Code

Things Storm bookmarked this week / 26-10-11

This week…

Dave pointed me to the fact that Google have given their App Store a bit of a facelift. As he points out – “to say that it had a ‘hint of iTunes app store’ is possibly an understatement” – but he’s also right, it’s pretty well put together and always worth spending a bit of time poking around..

From Adam – a neat little Gem which implements scheduled background tasks in Ruby. “It provides a simple way to specify any number of jobs on easily customisable schedules. It can call into other Ruby functions in your code, perform rake tasks or execute arbitrary command line commands.”

Liam “Apple” Gladdy gave me this: a sexy little iOS-app-screen-like web GUI in coffeescript - Now I find I need to go and look up what “coffeescript” is…

And from me – this utterly awesome video/sound piece: “Entire Musical Compositions Made from Just One Line of Code“. Totally tremendous on sooo many levels :-)

Generating code coverage metrics for a Ruby on Rails project with simplecov

As part of my dive into unit testing Rails applications I was keen to set up a tool to give me code coverage stats.  Code coverage represents the % of your source code that your unit tests exercise.  100% code coverage is a good goal to have and the earlier you hit it, the more likely you’ll find testing a worthwhile endeavour.  Whilst 100% coverage doesn’t guarantee that you’ve tested every permutation in your app, not having 100% coverage guarantees there are bits where daemons may be lurking.


Continue reading

Stop autotest continuously re-running your Rails tests

I’ve been getting up to speed with writing unit tests for Rails applications today.  My setup currently consists of RSpec tests being automatically run by autotest when I save a file.  This is a really nice workflow as you get instant feedback on failing tests.  Couple that with the autotest-growl gem to receive Growl notifications on failure and you’ve got a pretty funky setup.

However, autotest decided it wanted to re-run my tests over and over again, even if I hand’t saved a file in my project.  This had me very confused for quite a while until some Googling led me to ‘autotest -v’ which shows you which files had changed.  The culprit: test.log.


Continue reading

Using curly braces in a C# String.Format format pattern

This is a gotcha which caught me out and after banging my head against my desk to 10 minutes was easily solved by reading the documentation.  I was trying to use StringBuilder.AppendFormat to build up a JavaScript function and kept getting hit with a FormatException when trying to do this:

sb.AppendFormat("function {0}(args) { return false; }", someVariable);


Continue reading

URL Re-Writing in ASP.NET Requires Form Action to be Re-written

On a project I was working on recently we ran into a problem where the combination of URL re-writing and  postbacks caused the page to post back to the wrong URL.  When you create an ASP.NET page with a <form runat=”server”> tag, ASP.NET will automatically output the action attribute to be the URL of the current page.  However, the URL that is used is not the original URL of the request, but instead the real URL of the page.  For example, when you are on the page “/services/web-design” the real request might be to “/services.aspx?service=web-design”.  When you do a postback, you will be returned to the ugly URL.


Continue reading

The Haversine Formula in C# and SQL: Distance between two points

Storm was recently asked to create a local office finder for a client.  We used the Google Maps API to geo-locate the offices, storing their lat/lng co-ordinates in a database.  Each time a customer performs a search for their town or post code we use the same process to their lat/lng co-ordinates as well.  Now we have the information we need, but how you find out which offices is closest to the customer?  We use the Haversine Formula.


Continue reading

Using the Google Maps API to get long/lat co-ordinates from a postcode or address

Storm were recently asked to create a local office finder for franchised business VoIP provider, Datasharp. The client requested that the user should be able to enter their postcode or town/city and be informed where their nearest branch was.  To make this possible we would need the latitude and longitude co-ordinates for each office and the customer, but how do you get the co-ordinates from the address?


Continue reading

Convert an angle in Degrees to Radians in C#

I was recently using Google Maps API geo-location lookups to get the longitude and latitude of an address entered by the user.  I wanted to find the distance between a two co-ordinates using the Haversine Formula.  To do this I needed to convert my lat/lng co-ordinates into radians.  This seemed like an excellent opportunity to create a new extension method to add to Storm‘s library of re-usable code.


Continue reading