Some of the data I’ve been dealing with lately is in Microsoft Access databases (.mdb files). I’ve been surprised with the lack of support for manipulating these files outside of Access. There are a couple solutions, but nothing satisfied me needs. The worst data set came to me in a few hundred different .mdb files. It looked like the person that exported the database exported a copy of the database for each unique facility. So each facility had a file, but the schema for each file was exactly the same. It was apparent that in order to do any sort of complex queries on the data, the files would have to be combined. I was recommended a tool called mdbtools by somebody at a local Ruby meetup. I ended up using this along with Ruby inside of a Rake task to convert all my .mdb files into a single MySQL database. Continue reading →
Converting Multiple Microsoft Access Databases into a Single MySQL Database – Rails, Ruby, MDBTools
June 13th, 2009 — Programming, Projects, Work
Treat Google Referred Users Special
June 7th, 2009 — Programming, Work
The content of my main web application, Myhealthcaresource, will contain more than 15000 detailed financial reports for nursing facilities at its future peak. Each of these reports contains textual information as well as monetary values. It might list administrator names, employee names/salaries, owners, products or services purchased. I wanted to have all of this information searchable on Google, without Google caching the page. I also wanted to let users who came from Google as a result of searching for this information see it without having to log in, but only the page that they found through Google search. Continue reading →
Uniq for Array or Hash with a Deeply Nested Structure
January 4th, 2009 — Projects
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). Continue reading →
Rails Database Connection with Block
December 4th, 2008 — Programming
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: localhostI 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.
Rails Caching: Dynamic Fragments
December 3rd, 2008 — Programming
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.