Rails Database Connection with Block

Posted on December 4th, 2008

I found myself needing to very quickly connect to an alternate database that was defined in my database.yml like so:

alternate_data:
    adapter: mysql
    database: alternate_database
    username: user
    password: pass
    host: localhost

I was accessing it with something similar to the following:

ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations["#{state}_data"])
results = connection.execute description_params[:extraction_sql];
#This wasn't actually hard coded, but this is just an example
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations["development"])

The problems with this was that I had to repeat this ugly code everywhere, and if there was an exception thrown while accessing the alternate database it would not revert back to the original before exiting.  So the next request to the server thought the default database was the alternate database.  What I decided would be useful would be to have an “establish_connection” method that accepted a block and handle these issues.

(more…)

Rails Caching: Dynamic Fragments

Posted on December 3rd, 2008

I am finally getting around to implementing caching on my Rails application that I’ve been working on adamantly for the past couple of months.  For the time being, I am using a memcached server with simple action and page caching.  I ran into a few problems with my first few attempts at fragment caching and decided it wasn’t really necessary for the time being.  I needed a simple method of including small sections of dynamic code in an otherwise static page.  I then wanted to use action caching on the resulting view.  I’ll outline a simple method I used to achieve this.

(more…)

My Google Interview or: How I Learned to Stop Worrying and Drink the Kool-Aid

Posted on September 27th, 2008

Around November 2007 I managed to get into Google’s Boston office for an interview.  I had always wanted to interview at Google and this was the opportunity I had been waiting for.  I had applied many times in the past, but never got anything except a generated rejection letter.  Before I got my interview and while I was studying I searched endlessly online for any tips that might help me succeed and to know what to expect.  There are plenty of resources, and I’ll highlight a couple of them.  I’m not going to reproduce what’s already been said.  I’m just going to tell the story of my visit to the Google Boston office starting with my early attempts to get an interview and ending with the actual interview and my reactions to it.

(more…)

Necklace Simulation

Posted on September 7th, 2008

I had some ideas that required some sort of necklace simulator through a web interface.  I didn’t have much experience programming anything complex in ActionScript, but I was sure that would be the way to go.  I have seen some amazing work done with Flash applications over the past few years and I had no doubt that Flash could handle such an application.  So I set out on one weekend to put together a quick prototype for my idea.

(more…)

« Previous Page
© Chasing • Powered by Wordpress • Using the Swiss Cool theme.