Rescuing Exceptions… err… I mean StandardError in Ruby
7 10 2008I’ve heard from people how or how not to rescue things that might break in ruby. And I was confused.
Your basic rescue frame of mind is something like this:
This won’t give you a very good description of what you rescued so you can rescue specific errors and exceptions like this:
But! I want to catch EVERY POSSIBLE ERROR I MIGHT RUN INTO! So why not just rescue the whole Exception class? Yeah that sounds like a great idea.
Ok so that catches anything we might run into BUT NO!!! Its not a great idea. Let’s illustrate:
Now let’s say we have a script that is taking FOREVER to do anything like the one above. Let’s send it a kill signal via ctl+c or you could call kill with the process id from the command line. So ready set… kill! Die die die!
Um wait nothing happend…
What did the logger say?
Uh wait what!?!?!
Ah so rescuing Exception rescues Interrupt (ctl+c) and SignalException (kill). In this case I had to call kill -9 to get the damn thing to die. The kill -9 command is kind of a silver bullet but you can end up with a mess so don’t use it when you don’t have to, like my associate who crashed a whole cluster of servers that ran a large rental video chain’s backend because kill -9 on that weird flavor of linux did a lot more than just kill the one process, it killed everything that didn’t belong to his user (i.e. goodbye oracle db processes)!
What we should do is rescue StandardError unless you really want to rescue things like ScriptErrors (when you’re eval-ing ruby code) or rescue SignalExceptions (like do something before the thing dies).
This should help:
Comments : 1 Comment »
Tags: rescue, rescue Exception, rescue Exception ruby, rescue standard erorr, rescue StandardError, rescuing exceptions, rescuing exceptions ruby, Ruby, ruby exceptions, standard error
Categories : Linux, Ruby
Rentmappr.com now has RESTful search!
15 07 2008Rentmappr.com now has RESTful search. Here’s how it works:
You can now just fill in the url to search for properties. Every option available in the search form has been put into a RESTful url that are built in the following format:
www.rentmappr.com/search/minimum_price/maximum_price/bedrooms/
You can add “none” for min_price, max_price, or bedrooms, to say you don’t have a preference.
You can search for pets by adding /cats or /dogs, or /cats/dogs for both.
Some examples
/search/1850/none/3br/dogs will search for properties with a monthly rent of at least $1850, with no maximum price, that has three bedrooms and allows dogs.
/search/none/2650/none will search for properties with no minimum price but a monthly rent capped at $2650 and with no preference on bedrooms.
/search/1850/2650/4br/dogs/cats will search for properties between $1850 to $2650 per month that is four bedrooms and allows cats and/or dogs.
Currently you will have to pick a city to search in before these url’s will work.
I am working on a RESTful url search that will let you target specific markets. Using the same schema from above I would only have to add the city’s name to the url.
/search/boulder/1850/none/3br would search for houses in Boulder with at least a monthly rent of $1850 that has three bedrooms.
This feature will shortly be extended into a “link to these results” generator, making sharing of results much easier, ala “link to this map” in google maps.
Comments : Leave a Comment »
Categories : Rails, Ruby
Rentmappr.com: more things coming soon…
9 07 2008So I did some analysis on my rentmappr.com results. Looks like I get on average about 84% of postings to successfully geocode and get posted to rentmappr from craigslist. I do have an address correction algorithm in place but I haven’t analyzed its results for success. From watching the geocoder do its work though, I estimate I get about 20% of the postings that have a “bad” or non-geocodeable address to successfully geocode.
I will shortly be adding bedroom search to further narrow results. I did push dog and cat search options to production last week.
I’m also pleased to announce that my roommate successfully found, and rented, an apartment using rentmappr! Her glowing testimonial to follow.
Comments : Leave a Comment »
Tags: craigslist, craigslist mashup, find a place to rent, google map hack, google map mashup, rental housing
Categories : Linux, Rails, Ruby
Memcache Sessions in Rails
26 06 2008Does rails scale? No! But memcached does!
Ok ok, you aren’t probably going to need memcache for caching huge queries yet. But it is useful for storing your user’s session data server side and not having to worry about filling up cookies or clearing out files in your tmp directory or your database.
So I’ve been designing a single sign on system for the interanl applications at CI. And I need apps on all kinds of different servers to talk to the same memcache instance(s) for their sessions. I did follow this article on err.the_blog to get started but I only got so far and ran into some issues that got hard to debug.
The default memcached session store hits localhost:11211 which is generally fine for most applications but I needed a clustered approach and could not for the life of me figure it out. Turns out like most things with rails it was really easy.
Pre-req’s:
1. Memcached installed on your machine or whatever machine you want to use for sessions
1a. Top Funky has a really simple shell script that will work on os x and another that works on ubuntu
2. You will need the memcache-client gem, you know what to do.
In environment.rb in my rails app I needed to do a few things:
1. Setup the connection to the memcache server
2. Tell rails to use memcache for sessions
3. Setup rails to drop all its sessions stuff into the memcache server we setup
Alright so 1:
require 'memcache'
CACHE = MemCache.new(:namespace => "your_app")
CACHE.servers = 'some_ip_address:some_port', 'another_ip_address_if_you_need_it:some_port'
and then 2(pretty easy)
config.action_controller.session_store = :mem_cache_store
and then 3 (this is where you can set the session timeout and then pass in the memcached object CACHE)
config.action_controller.session = {
:session_key => '_your_app_session',
:secret => 'someotherkindofsecretthatnooneknows',
:cache => CACHE,
:expires=>900 }
I think if memcache doesn’t find the session on one server it’ll look on the others you put in the CACHE.servers list. However if your memcache instance goes down your rails app is hosed and starts throwing up 500 errors all over itself.
You can actually throw alot of this config into a gem if you are going to have several apps that are all going to use the same config (setup the CACHE stuff in your gem and then just do step 3 in your apps) That way if you need to switch or add servers to your memcache setup you don’t have to make changes in 20 places.
Comments : 4 Comments »
Tags: memcache, memcache session store, memcached, mem_cache_store, Rails, sessions, single signon
Categories : Linux, Rails, Ruby
Protected: BR BP Questions.
10 12 2007Comments : Enter your password to view comments
Categories : Linux, Rails, Ruby, Windows
Gmail with Rails…just so I don’t forget how to do it.
6 12 2007Smtp settings in config/environment.rb:
ActionMailer::Base.smtp_settings = {
:address => “smtp.gmail.com”,
:port => 587,
:domain => “christm.us”,
:authentication => :plain,
:user_name => “admin@christm.us”,
:password => “*******”
}
Get code from this very helpful post. Make the folders and files
- action_mailer_tls
- lib
- smtp_tls.rb
- init.rb
- lib
and copy/paste his code into the correct files you just created
Comments : Leave a Comment »
Tags: , gmail, gmail with ruby on rails, Rails, Ruby, use gmail with ror
Categories : Rails, Ruby
LightMate Gedit Theme and now for TextMate too!
5 12 2007Ok kids, finally got the themes available up on my website: http://ubermajestix.com/uber/themes.
Check the screenshot below for the gedit theme or hit up my website for screenshots of Textmate.
I really hate working in dark environments…well lights off yes, but a bright computing environment is a must. Thus when customizing gedit to work like TextMate for rails work I really hated the DarkMate theme – and the default lightish theme I didn’t like either.
So I made my own based on some colors from DarkMate. Take a look:
-
rhtml:

-
ruby:

UPDATE: Theme is for GTKsourceview-2.0 and later (this is installed with Gutsy Gibbon). This theme will not work with Feisty or earlier releases.
Comments : 4 Comments »
Tags: darkmate, darkmate theme, gedit styles, gedit themes, gtksourceview-2.0, Rails, styles, themes
Categories : Design, Linux, Rails, Ruby
Upgraded to Ubuntu Gutsy Gibbon
4 12 2007I went through with it on my dev machine at work b/c I heard there were lots of great new things in gedit and openoffice might stop crashing (gotta love the java apps).
I updated all the components update manager told me to BEFORE I ran the upgrade. I heard there were problems if all Feisty updates were not applied, so I updated. That took about 45 minutes.
Then I ran the upgrade package – I had to delete some custom software repositories in System=>Admin=>SoftwareSources because they were no longer live and the upgrade was trying to load the Gutsy source from them…I just switched the Download From: to Main Server and unchecked the repositories giving me issues under Third Party.
After that the upgrade went smooth…I was still trying to work while doing the upgrade so it took about 2 hours to complete. I lost one text document I tried to save when the installer was doing its thang (it locked the local filesystem) but thats the only other trouble i ran into.
Rebooted and it all looked fine except for gedit. This needed to be re-customized for rails since they change a whole bunch of crap in gedit. I followed the instructions here: http://crepuscular-homunculus.blogspot.com/2007/10/gedit-for-ruby-and-everything-else-on.html
And whala everything in gedit is working…i did sudo apt-get install gedit-plugins
to get some extra fun stuff like a color picker, bracket matcher…I think I like Gemini better b/c I can select text and then wrap it with quotes and brackets…but it does completion of “<” those guys which I hate because I use “<<” all the time to add an element to an array so Gemini makes it into “<><”…anyway, the default color scheme is a little different…actually I don’t like it but I also don’t like Darkmate style which everyone raves about…so I have to find one that works.
I also installed IE6 under Wine…I followed the instructions here: http://www.tatanka.com.br/ies4linux/page/Installation:Ubuntu
And this dude has some interesting/useful plugins for gedit also:
http://my.opera.com/area42/blog/gedit-browser-preview-plugin
http://my.opera.com/area42/blog/gedit-language-reference-plugin
http://my.opera.com/area42/blog/gedit-template-plugin
Comments : Leave a Comment »
Categories : Linux, Rails, Ruby






