idisposable.net: a blog about web 2.0, search, collaboration, Ruby on Rails, Microsoft, Google, and other fun stuff

Mapping and Location Mashups in Rails: GeoKit and Geonames

If you are building geography based mashups in Rails, or just need some simple calculations for distance, be sure to check out GeoKit plugin and Geonames API Gem. They will save you hours of time.


What is GeoKit?

“Geokit is a Rails plugin for building location-based apps. It provides geocoding, location finders, and distance calculation in one cohesive package. If you have any tables with latitude/longitude columns in your database, or if you every wanted to easily query for “all the stores within a 50 mile radius,” then GeoKit is for you”

It is fantastic. Here is some sample code:

include GeoKit::Geocoders
   def get_location( location )
      loc = MultiGeocoder.geocode( location )   # ask GeoKit to find your city
      return loc
    end
 
    def calculate
     start_city = get_location("Hoboken NJ")
     end_city = get_location("Los Angeles CA")
     distance = start_city.distance_to( dest )
     #thats it!  really?? yes.
    end

What is Geonames

Geonames is a public location database / web service API that allows you to search and reverse lookup geography and location information, such as city names and towns, longitude/latitude, etc.

The excellent Geonames Gem for Ruby provides an easy to use interface into the geonames web service.

Why use geonames? I’ve found it extremely useful for finding “nearby” locations as well as cities/counties/subdivisions within another area. For example, look at the following call:

http://ws.geonames.org/search?q=NJ&maxRows=20

Viola! All the cities and location features in NJ. The real power in geonames (which you don’t necessarily get with geokit) is the ability to restrict searches based on FCL and FCODE designators.

For example, some locations from geonames might these elements attached to them:

<fcl>P</fcl><fcode>PPL</fcode>

What do these codes mean?

FCL and FCODE represent “feature codes.” A complete list of feature codes can be found here.

You can do neat things with feature codes. Witness:

“Geonames?”Yes, Ed

“New Jersey has over 127 miles of beachfront and another 83 miles of bayshore. Where are all of these beaches??

Ed, I am not a person, just an XML web service. You’ll have to ask me a different way.

“Ok, how about this: http://ws.geonames.org/search?q=NJ&featureClass=T&featureCode=BCH

Yumm.

More geonames; simple latitude / longitude lookup:
http://ws.geonames.org/postalCodeSearch?postalcode=10012&country=US

gives us the longitude and latitude for a zip code in Manhattan.

It is a great tool when you don’t want to have a local database with geography information. Put memcached in front of the calls, and you’ll have a zippy, small-footprint mashup in no time.

The Ruby on Rails Production Stack: Too many choices

Is it me or are there too many choices for Rails production stacks?

Depending on what kind of server you are deploying to, you can have any or all of the following in your mix:

Apache
Lighty (LightTPD)
Pound
Pen
Mongrel (or mongrel_cluster)
Ngnix
FastCGI

Whoa! That is way more confusing than even the most obsfucated Java stack.

I am a huge Rails fan, but I hope the community can come together with some simple production stacks that are easy and enjoyable to deploy for as Ruby is to develop in.

I’d like to know, what are you using? I am using Pound/mongrel_cluster right now, but I am looking into Ngnix.

Say what you want about Microsoft, but copy->paste into IIS directory is a whole lot easier to do.

"Facebook surfers may cost their bosses" - but look who is doing the survey

Today CNET published an article claiming that Facebook could cost employers as much as $4 billion (yes, thats BILLION) dollars per year.

Internet security company SurfControl looked at the phenomenon and found that Australian workers who keep a close watch on their Facebook profile page were cumulatively costing their employers up to 5 billion Australian dollars ($4 billion) a year.

Hmmm. SurfControl “looked at the phenomenon.” Ok, let’s see - who is SurfControl?

From their website:

SurfControl Web filtering solutions enable companies to cost-effectively monitor network use and abuse anywhere in the organization, no matter how or where users connect to the Internet, across the full spectrum of Web-based content: IM, P2P, streaming media, file downloads, and Web-based e-mail.

So, a company who sells products that allow employers to filter internet content, comes up with a report that companies are losing $4 billion a year to Facebook. Slight conflict of interest here eh?

I could only imagine the economic boom we’d see if people stopped surfing Facebook! Just imagine all of the new products, inventions, cures for disease, and subsequent world peace that would occur if this menace was stopped! I am going to go out and buy SurfControl right now to get ahead of this as fast as I can.

In reality, social networks, websites, distractions, are always part of what workers have to contend with - information workers and otherwise. If employers think that Facebook (or SurfControl) is going to reap them many man-hours of productivity gains, they are likely the same employers whose employees waste time by surfing the web all day instead of contributing to the bottom line.

Tutorial: How to virtualize your PC and run it in Mac OS X (Intel editions only)

I recently converted from an IBM ThinkPad T43 to a MacBook Pro. I was able to keep all of my PC-specific software, including MS Office, Visual Studio 2005, SQL Server, QuickBooks, etc. This method allowed me to preserve my PC as it was - perfectly frozen in time with all my preferences - and take advantage of the powerful Darwin/OS X operating system for better productivity and as a platform for Ruby on Rails development.

  1. Clean your PC up to make sure you have eliminated anything you don’t need. This will ensure that you don’t have a larger virtual disk (the big file that your PC will be stored as) than you need. Here is how I did that:
    • I installed FolderSizes, from Key Metric Software: http://www.foldersizes.com/download-folder-sizes/index.htm This allowed me to see where all the “hidden” large items were on my disk. I was able to remove over 10GB of old files and garbage this way. Be sure to eliminate “Temporary Internet Files”, “Temp” directories, etc.
    • I ran “Add Remove Programs” and eliminated everything I didn’t need, or what would be easily replicated natively in OS X. For example, I removed iTunes, Picasa, a bunch of utilities, etc.
    • I copied all of my music, photos, projects, personal files to an external hard drive. If you have an external hard drive (USB 2.0 preferrably as it will work great between both your PC and your Mac), do the following:
      • Plug it in to your PC
      • Create a folder called “archive” on it
      • Copy your music, photos, personal files, etc. to it
      • That’s it - you are done.*
      • (* if your external drive is formatted with NTFS it might be a bit tricky to get it to be recognized by your Mac, so try to use a FAT32 drive if you can - I’ll post NTFS instructions later as I had to go through this)

OK, now that your system is nice and clean, you are ready to convert it into a virtual machine.

2. Convert your PC into a virtual machine using VMWare Converter.

    • Download VMWare Converter from here: http://www.vmware.com/download/fusion/eval.html
    • Install and run it.
    • Click “Import Machine” on the button bar.
    • Start the wizard, choose “Physical Computer” from the source screen. (click next)
    • Choose “This Local Machine” (click next)
    • Converter will evaluate your machine. You should choose at least your “main volume” (the larger one).
    • At this point, to save space on my Mac, I chose to enter a custom size (40GB) to hold my current system (28GB) and have some breathing room. If your PC has 80GB+ of storage, you probably don’t need to have a virtual disk that big. YMMV.
    • Click next (twice) and choose “VMware standalone virtual machine” (this is important). Click next again.
    • Give your machine a name “MYLAPTOP” or something like that, then choose a location (a USB 2.0 disk is a perfect choice) to save it to. Click next a few more times (no more advance setup required), and start your machine import.
    • Wait a few hours.

Whew! That was some experience, metaphorically similar to a religious conversion - you are at the altar but not quite there yet. Now you are ready to import your virtual PC into your Mac and join the dark/light side of the force (depending on your POV).

3. Install VMWare Fusion on your Intel-powered Mac OS X (Tiger) and “enjoy” your PC , exactly the way it was, on your Mac.

  • Download VMWare fusion onto your Mac: http://www.vmware.com/download/fusion/eval.html
  • You may want to review the release notes.
  • Install it.
  • Copy your virtual machine file from your USB 2.0 drive (see step 2 above), to your Mac. ~/Virtual Machines is a good directory for it (in other words Home -> Virtual Machines — create the directory first)
  • Run VMWare fusion.
  • Open the machine from your filesystem.
  • Off you go!

4. (Optional) Your new VM might behave erratically at first or force you to “Activate Windows”

  • If your VM bluescreens, just reboot it. Its normal behavior because you just essentially ripped the soul of your PC out and put it in another shell. It freaks out a bit. You shouldn’t need to reboot more than a few times.
  • If Windows asks for Activation, go through the steps. Your product key should be somewhere on your computer. If that doesn’t work, go through the “I’m not connected to the internet, activate by phone” menu and call them and get a new activation code.

If you have problems, leave comments here and I’ll try to answer them. Also you should check out the VMware support forums.

Good luck and happy computing.

Public Airwaves for the Public Good

http://civic.moveon.org/airwaves/

Please check this out people. This is huge; if Google or someone else opens up the new wireless spectrum, we will see another technology revolution.

Here is part of the letter I sent when signing the petition.

Thank you for your time and kind consideration. I am the CTO of a information services firm (getthejob.com) based in New Jersey, with offices in Cleveland and Naples, Florida. We employ over 40 full time employees and contribute much to our local economy, including well-paid high-skilled jobs.

A large part of our business was inspired by the Google model. Companies like ours to thrive on the ability to openly provide web tools for consumers; a concept ingrained into to the open Internet.

The wireless spectrum has been part of a closed system for too long. In the past, the engineering know-how required to master safe wireless operation made it wise to leave the protections in the hands of large, well-known and skilled firms like AT&T.

Today, technology (especially software) has become so advanced that spectrum owners like Google, or other like-minded companies, can safely allow access to the spectrum to inventors, innovators, small and medium sized businesses, and other economy driving enterprises.

The wireless spectrum is a treasure; a part of the public trust, as important to our nation as so many monuments and natural wonders that mark our land. A new economy and technology boom will occur if open access is provided to the innovators that have fueled this great nation since its inception.

Please consider adopting open access measures for all aspects of the new spectrum auction.

Ok, got the MacBook , now I want to learn Ruby. What first?

I am going to try Locomotive. In the spirit of WAMP/MAMP, it is a full Ruby on Rails stack for OS X. Since I am not terribly interested in doing everything manually (yet), I figure this is my easiest way in.

Took the plunge… in the form of a MacBook Pro

So far, I love it.
I did a whole “unboxing” ceremony. I’ll upload pics for that soon.

I have already been able to install a PHP/MySql Stack (MAMP) and Drupal.

Soon, I’ll be on to Ruby.

Running Ruby "natively" in IIS! Cool

10 steps to get Ruby on Rails running on Windows with IIS FastCGI

Very cool. I haven’t tried it yet, but would like to. We have a production application in ASP.NET that we want to be a RESTful API to, and there is no framework for REST in ASP.NET. I was thinking if we could have it run side-by-side with ASP.NET/IIS, Ruby would be the perfect language to try this out in.

Technorati Tags:

Solution to an IE gotcha when developing Facebook App in an IFRAME

This was a very frustrating problem for us in our app Jobs (http://apps.facebook.com/getthejob).

The problem was that in IE, if a parent frame has a different domain than the child page, the session data (stored in the Session object) is not preserved. This is a so-called “security feature.”

Anyway, if you have this problem, the answer is here: http://support.microsoft.com/kb/323752

Simply put, in your ASP.NET page codebehind, add the following code: [code]

   protected override void OnPreRender(EventArgs e)  {      Response.AppendHeader("P3P", "CP=\"CAO PSA OUR\"");      base.OnPreRender(e);  }

[/code]

This will add the right headers to every page.

Also cross-posted to the facebook developers wiki

Pick a Firefox plugin that you can’t live without: FoxMarks

http://www.foxmarks.com/

FoxMarks has been saving me time, headache, and energy ever since I first stumbled upon it last year.

The nickel tour:

  • Install FoxMarks for Firefox on all PC’s (Win/Mac/Linux/Amiga/TRS-80) that you use.
  • Create a FoxMarks account from the plugin setup in Firefox.
  • Sync your bookmarks.
  • Forever have bookmarks in sync.

You know I wanted to use social bookmark sites like delicious, but Foxmarks obviated that for me. The biggest draw for the bookmark websites for me was the ability to have a simple place to always find my bookmarks, no matter where I was.

FoxMarks, you solved that for me without having to remember where to put the “.” in delici.ous

Tell me, what plug-in can’t you live without?

ss_blog_claim=77c0780e64c123f107896646c0ee8870