Entries Tagged 'Programming' ↓

Reading Advantage Database Server Files (.ADT) in Ruby

I recently received some data in the Advantage Database Server file format (.adt). In the past I have worked with DBF, Access, and .xls. I was able to find some way to retrieve data from these formats using open source software. The open source solutions were much easier to work with, usually not requiring any sort of driver installation, etc.

I searched thoroughly for an easy way to retrieve information from this set of .ADT files I was dealing with. Sybase provides tools to work with the data, but all of them require using their software or drivers developed by them. I would have settled for this if it wasn’t such a hassle to figure out how to use them. I asked the question on Stackoverflow.com and got an answer from one of the employee’s of Sybase. While helpful, the suggested Perl driver was one of the things I was avoiding. I did attempt it and after a little hassle, moved on to creating a simpler solution.

Continue reading →

Converting Multiple Microsoft Access Databases into a Single MySQL Database – Rails, Ruby, MDBTools

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 →

Treat Google Referred Users Special

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 →

Rails Database Connection with Block

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.

Continue reading →

Rails Caching: Dynamic Fragments

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.

Continue reading →