Friday, 25 January 2013

Latitude and longitude in Rails activerecord

I needed to store latitude and longitude in my Postgres db in a way that maintained accuracy of data but also allowed fast efficient searching of this spatial data using BETWEEN queries. The PostGIS extension was not available to me.

The suitable data type for this is a decimal with precision of 9 and scale of 6 [decimal(9,6)]. The activerecord migration code for this turned out to be thus:
add_column :livetokens, :latitude, :decimal, :precision => 9, :scale => 6

Tuesday, 22 January 2013

Sniff iPhone HTTP traffic with mitmproxy

I always forget how to use mitmproxy, so here's a reminder for myself:
Download and install mitmproxy, if you haven't done so already.
Go to a terminal and run mitmproxy.
Get the network IP address of your mac by running ifconfig en1.
Set the proxy on your iPhone by going to wifi settings. Set HTTP Proxy to “Manual”, and enter the IP of your Mac and port 8080.
Start browsing on the iPhone, or run an app. Press ‘?’ to bring up the list of commands.

Wednesday, 16 January 2013

Text size bigger in iPhone Safari landscape

Is your text size being unpredictable when in landscape on an iPhone? Mine was. Here's the fix, just add this to your body class:

-webkit-text-size-adjust:none;

Wednesday, 9 January 2013

Twilio for rails - setting the StatusCallback URL

I've been using Twilio with Rails to send SMS, and needed Twilio to notify my Rails app if a send had been successful or not.

To acheive this I added a StatusCallback parameter when calling message.create. This contains a URL with a unique identifier of the message I sent.

 # send an sms
    @client.account.sms.messages.create(
        :from => '+44207XXXXXX',
        :to => phoneNumber,
        :body => body,
        :StatusCallback => ENV['app_url']+ENV['twilio_sms_postback']+'?smsId='+textmessageId.to_s
    )