Uniq for Array or Hash with a Deeply Nested Structure

Posted on January 4th, 2009

Most people have had some experience with ruby’s built in #uniq method for Arrays. Internally, this method finds the unique items in the array by creating a hash internally, and this internal comparison is done with the #eql? method. If an item in the array is a Hash, then #eql? simply uses the object_id, generated by the #hash method, to determine whether it is equal to another object in the array. There are many solutions online each with s light variations and goals. I found myself in need of a uniq method for an array containing items in an arbitrarily deep nested structure (ie many sub-hashes and arrays). (more…)

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…)

URL Archive System or: URL Hacking Made Easy

Posted on November 3rd, 2008

Have you ever found yourself slightly modifying a URL to try to find something you know used to exist or should exist but you keep getting that dreaded 404 page?  Perhaps you were trying to find something that shouldn’t be online anymore but it was simply unlinked to, benevolent purposes or otherwise? Another example might be that a site’s main homepage is down and so many users are unable to access the site.  If they had a list of URLs they could see which are still valid very quickly with the URL Archive and go to the site through those URLs.  Google cache and Wayback Machine get you pretty close to what you’re after but sometimes they just fall a little too short.  Some things are beyond even Google’s giant umbrella of web applications (at least for now).

I’m sure an application focusing more on URLs is somebody’s 10% project somewhere sitting on the backburner until they have time to finish it.  It seems like almost anything you’d want to do has a corresponding web application.  When I come across a need that doesn’t I just feel like that void should soon be filled.  I’m going to outline the application that I believe would fill this void.  Maybe in future posts I’ll also walkthrough my attempts to do it as my personal .5% project. (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…)

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