Status

Location
London, England
Subscribe to GeoRSS Subscribe to KML


Howto

Migrating a site from PHP to Rails

Published in Howto, Rails


I learn best by picking a project and learning a new technology by applying it to the project. This is how I originally learned PHP, MySQL, and various web technologies when developing the Detroit Curling Club site/portal. Looking back, it’s amazing I got done what I did with what I knew. I implemented a Wiki, CMS, user management, uploading, RSS, and so forth, from the ground up, with no frameworks .

However, the result also means the code is, shall we say, “spaghetti”. And is really no fun to maintain and add to. Since then, I’ve learned Ruby and Rails and really enjoy working in the language and framework and wanted to reimplement the site. With so many other projects going on, I was concerned about the time necessary to get the site migrated.

Actually, it was rather easy. by stroke of fortune. Here is how the work went.

On the catwalk…

By similar mindset, when I designed the original database schema, I used “rails-esque” naming: tables are plural, columns are simple singular names. Join tables are alphabetical of the two tables they are joining. I just had to migrate the names of a couple of tables and columns to mee the rails standard configuration. I could have overriden the table/column names, but didn’t want to deal with maintaining that. I really wanted the site to work like it was originally written with Rails in mind.

You’ve obviously created a Rails application by now, so I’ll skip that. Now, I have my database (with backups). Setup your config/database.yml to point to the database and then run rake db:schema:dump to create the schema.rb of the database. If you want, you can copy this to a migration file.

Next, install Dr. Nic’s Magic Models, which automagically give you your model files, associations, basic validations, and so forth with no coding. Magic just begins to describe it. You can verify this by bringing up script/console and toying with your models and associations.

Testing is good

A good idea at this point is to load Selenium, a web user-interface testing application, and walk over your original site to create user interface requirements based on current site design. This should stand as your base-line specification. In the end, your Rails app should act like your current application.

You can also check out the work of Josh Susser who has a ruby script that will validate all the records in your database using your model validations.

Define your application test specification using RSpec and BDD. Again, you already have an existing web application to help define your desired functionality.

The View, the View

Now you have a your base application done. You should start migrating your views. Fill in your layout/application.rhtml with the base layout from your original HTML files.

You’ll now need to start actually defining your controllers for various functionality: calendar, users, leagues, etc. Along the way, run your tests you defined with RSpec and verify operation. This is where the actual work comes in. Overall though, I find the design of Rails to make this very easy going. I just have to deal with various legacy functionality.

I’m also looking more at Unobtrusive Javascript for Rails (ujs4rails) at how to handle graceful degradation (or is it graceful upgrading) to browsers that may not support javascript.

Work in Progress

That all said, migrating the site has been very easy. So easy I’m looking at migrating other projects to Rails. Of course, deploying Rails applications to shared hosts is not nearly as easy as deploying PHP ones. Especially with applications that are meant for other users to easily install on their own hosts. But the ease of development and maintenance is not easily overlooked.

If only Apache supported a built-in Rails module. :)


TextMate Bundles

Published in Howto


I’m learning the power that is TextMate (like Emacs, but prettier). TextMate really is setting itself up to be a rather decent OS for editing. From within TextMate I can blog, keep a todo list, program in any number of languages, WYSIWYG webpage editing, and calendaring. Heck, mix TextMate and Quicksilver and who *needs* Finder. I picked up the new Pragmatic Programmer’s TextMate book to learn more of the underpinnings and how to stop repeating myself with simple tasks.

Like my thoughts on why plugins make, TextMate has excellent support via bundles (over 124 of them). However, the only way to get to these is via subversion. This is nice because it keeps me up to date, but is a little annoying having to get the subversion command right and path all the time.

So I wrote a small shell script to grab a bundle, get_tmbundle:

#!/bin/bash
svn --username anon --password anon co http://macromates.com\
/svn/Bundles/trunk/Bundles/$1.tmbundle ~/Library/Application Support/TextMate/Bundles/$1.tmbundle

I can then $ get_bundle AppleScript to get a new bundle installed.

You could also use the getBundle Bundle, but that seems like cheating. Of course, getBundle also has an AutoUpdater and is baked into TextMate as a bundle itself (how deep does the Rabbit Hole go?)

Technorati Tags: , , , , ,


Daily del.icio.us blog posting

Published in Howto, Web


By popular demand (ok, one request), I am putting up instructions on how to have your del.icio.us links posted daily to your blog.

I like this, as feed readers then have a succinct list of interesting sites to show (rather than a sidebar, who goes to a blog anymore?). A list of links is often more interesting than some half-written paragraph of diatribe just to get to the point. (case in point).

How to setup del.icio.us to post daily links

  1. Log into del.icio.us
  2. On the right-side, under “experimental”, choose “daily blog posting”
  3. Click “add new thingy” (yes, it really says “thingy”, those crazy del.icio.users
  4. Fill in the form as appropriate, here is an example:
    • job_name: DailyLinks
    • out_name: (blog user - e.g. delicious)
    • out_pass: (blog password for that user)
    • out_url: http://highearthorbit.com/xmlrpc.php
    • out_time: 3 (approx time to post, in GMT)
    • out_blog_id: (leave this blank)
    • out_cat_id: (category id, look at the id in your blogging software)
  5. Click “Submit Query”
  6. Sometime within the appointed hour (they’re spaced out so neither del.icio.us’s servers, or ping services, are flooded ‘on the hour’) your new links will be posted.

    For this blog, I created a new user, gave that user Author privileges, and created a specific category, bookmarks


No LaTeX, never fret

Published in Engineering, Howto, Microsoft


So you’re writing a paper with citations and you’re wishing you had LaTeX’s beautiful self-referencing ability to your list of references. However, for whatever reason, you’re stuck using Microsoft Word. And clicking through Insert->Reference->Cross-reference…, then scroll to find your article, and set to paragraph number, etc. has got you really down.

Bet you didn’t know about field codes. Instead, just put your cursor in your citation brackets (or whatever you use), press <ctrl>-F9, and then REF NameYear \n.

... demonstrated in on an airship [{REF Turner02 \n}].

The \n specifies that you want the paragraph number of the reference, which equates to the ordered-list number. Later, in your references section, you will Insert->Bookmark and properly name your citations (again, I use NameYear). You then need to hit Alt-F9 turn ‘hide’ all the field codes in your doc and update and they’ll all be linked.

It’s not pretty, it’s not LaTeX (not that LaTeX is pretty either), but it works.


GeoNames supports reverse geocoding

Published in Geolocation, Howto, Programming, Technology


GeoNames is YAG (yet another geocoder), but behind the curtains lie many cool features. The most unique of which is a reverse geocoder.

Reverse geocoding is converting Latitude & Longitude to a place name. This is the other side of the mirror from traditional geocoding, which converts a place name into latitude & longitude. Why would someone want to reverse geocode you ask? With reverse geocoding you can convert your GPS tracklogs into meaningful locations easily, or allow users to click on a map and get back actual location of where they’re clicking.

The GeoNames API provides an interface for getting nearby postal codes, country, or most specific: place names.

Example

HighEarthOrbit offices: http://ws.geonames.org/findNearbyPlaceName?lat=42.4266&lng=-83.4931&style=full

returns:

<geonames>
  <geoname>
    <name>Northville</name>
    <lat>42.43111</lat>
    <lng>-83.48333</lng>
    <geonameid>5003956</geonameid>
    <countrycode>US</countrycode>
    <countryname>United States</countryname>
    <fcl>P</fcl>
    <fcode>PPL</fcode>
    <fclname>city, village,...</fclname>
    <fcodename>populated place</fcodename>
    <population>6360</population>
    <elevation>252</elevation>
    <admincode1>MI</admincode1>
    <adminname1>Michigan</adminname1>
    <admincode2 />
    <adminname2 />
  </geoname>
</geonames>

The whole geo-enchilada

Lastly, to make you really feel warm and good inside, the GeoNames database is provided for direct download under a Creative Commons Attribution license. Yum, free data.

See the GeoNames Blog post about it.