Search using Geolocation data in MySQL

One of the many things brought to the forefront by HTML5 is Geolocation. It’s easy enough to get someones geolocation data using HTML5 but what do you do with it once you have it? Ideally you’d like to search through some sort of database be it store locations, real estate listings or what have your. This is where most people start to get tripped up.

There’s lots of different techniques for achieving this unfortunately they don’t seem to ever be explained very well as they relate to MySQL. Until now… dun dun dun dahhh.

The two most common technique are the Haversine formula and the Spherical Law of Cosines. The method I’ve chosen to use in my example is the Spherical Law of Cosines. The formula is a bit short and uses fewer mathematical functions.

The example is comprised of two parts. The first is the Spherical Law of Cosines. The second part is defining a search radius. Defining this search radius will significantly narrow the scope of our search. This is a good thing.

Alright enough chitchat. Here’s the sample MySQL query. It’s built in PHP below but can easily be converted to your language of preference.

Note: I’m Canadian so the example below is done using kilometers. If you want miles you’ll need to multiple $earths_radius and $surface_distance_coeffient by 0.6214 to convert them to miles.

If your interested in digging deeper into the theory and math behind the Spherical Law of Cosines or the Haversine formula checkout the Movable Type Scrips site they have tons of background information.

How to get Sencha Touch working on non-touch and touch Blackberry devices

When I needed to get Sencha Touch to work on non-touch Blackberry devices I tried the approach documented at
http://resilientcoder.blogspot.com/2011/03/getting-sencha-touch-to-work-on-non.html

At first this appeared to work correctly. But then I tried the app on a touch Blackberry and the touch elements didn’t work properly any more. So I ditched changes recommended by Resilient Coder and went digging into sencha-touch-debug.js myself.

To get Sencha Touch working on both touch and non-touch Blackberry devices you need to make the following changes.

You need to add || Ext.is.Blackberry to line 18098. This enables clicking on Sench Touch ui elements like buttons and tabs with the thumbpad or trackball. You also need to comment out line 18101 to enable scrolling via touch on Blackberry devices like the Torch. If you don’t comment this line out scrolling via touch doesn’t work properly.

The final piece of the puzzle is to enable scrolling using the thumbpad or trackball. This is really more of a work around. It’s based off the code I found at http://pastebin.com/Mih4Ps12. To use this work around you basically just extend your scrollable panels from Ext.NonTouchCompatibleScrollPanel instead of Ext.Panel.

Decode quoted-printable text with Sublime Text or Textmate command

If your like me you find yourself frequently need to take an HTML email that you received and alter it or clean it up and then send it out again. When you grab the message source what you discover is an ugly block of HTML-like text. It’s full or things like “=3D” or “=20″, don’t worry. This strange text your seeing is the result the HTML being encoded into the quoted-printable format. This encoding is how email keeps it’s lines at the appropriate length to be compatible with all the various email servers.

This command which can be used in either E-TextEditor or TextMate will decode the quote-printable encoding. It operated on either your current selection or the whole document. Internally the command itself uses Python to decode the quoted-printable text.

Download the quoted-printable decoder Sublime Text command
Download the quoted-printable decoder E-TextEditor / TextMate command

Automatically Format Any Javascript Code

Every javascript programmer at somepoint finds themself in a situation where they need to undo the effects of a packer or minifier on their code. Javascript Beautifier to the rescue.

Javascript Beautifier

It lets you cleanup the super scrunched up code into something more readable. This enables you to recover your source files if you lost your originals or dig through someone elses code and get a better idea of how other people in the real world are coding.