Mike Bailey

Rails Web API Versioning

| Comments

[2013-12-18 Why was so I attracted to the idea of versioning web APIs? I’ve never needed this.]

One way to make different versions of a web service available from the same webserver is to allow clients to prepend a version identifier to the URI path. There’s some discussion about the best way to use this but I like to default to no version identifier in URIs.

Passenger makes it easy to run different versions of your Rails web api alongside each other.

Update Your Webserver Config

Passenger allows you to direct traffic to different instances of your app. Here I’m serving brandish_v2 if no version identified is included in the URI.

<code># /etc/apache2/sites-available/brandish
<VirtualHost *:80>
  ServerName brandish.local
  CustomLog /var/log/apache2/brandish_access_log combined
  RackEnv development

  DocumentRoot /srv/brandish_v2/public
  RackBaseURI /v1
  RackBaseURI /v2
  <Directory /srv/brandish_v2/public/v1>   
    Options -MultiViews  
  </Directory>
  <Directory /srv/brandish_v2/public/v2>   
    Options -MultiViews  
  </Directory>
</VirtualHost>
</code>

Symlink public/ into your DocumentRoot

This is the only tricky bit. Passenger expects the RackBaseURI’s you used in the web config to point at symlinks to the public/ directories of the different versions of your apps.

<code>ln -s /srv/brandish_v1/public -> /srv/brandish_v2/public/v1
ln -s /srv/brandish_v2/public -> /srv/brandish_v2/public/v2
</code>

Note Passenger was failing for me because it expected application.rb to be in controllers directory. I fixed it by creating a symlink from application_controller.rb to application.rb. I’m a bit confused as I thought that had been fixed in recent versions of Passenger. Maybe the RailsBaseURI code is not up to date.

It’s lucky Qantas don’t design planes

| Comments

I’m glad Qantas don’t design planes because frankly I don’t think they would fly.

Web based flight bookings are money. They’ve changed the way we travel. Why would Australia’s national airline have such a poorly designed user interface for their booking website?

We don’t always read what’s on the buttons at the bottom of forms unless there are two together. I’d love to see click rates of a the dummy buttons below.

Harder to book

I’m guessing someone in marketing thought the best place to advertise their ‘points and pay’ offering was by linking to it from a submit button on the search form. This button is larger and brighter than the button that submits that takes you to your flight search results. It’s simply a link that opens up this page talking about their ‘points and pay’ scheme. Fail.

Which submit button should I press?

Just to be clear, clicking the bottom on the left does not submit the form!

Harder to pay

At the end of the booking process they provide a dangerous little button sitting on it’s own that discards your input. Fail. How many people in a hurry click this when meaning to submit the form?

How many people click ‘Start Again’ by mistake?

BlinkSale - How To Say Goodbye

| Comments

What do you do when you want to stop using a service but it’s going to be a lot of effort to extract your data? Write a script to do it of course!

I’ve been using BlinkSale for my invoices since 2007 and it’s served my needs well. Since being bought, BlinkSale has increased their monthly costs. In order to stop using them I needed to download 90 invoices as PDF’s. The following script automated the process for me.

If you have Ruby and the mechanize rubygem you can download and run it with:

1
$ curl -L http://bit.ly/mkQqan -o blinksave && ruby blinksave

Because it asks for your BlinkSale password you really should read through the code to make sure this is not a phishing trip! Look how easy Mechanize makes this kind of task.

How to find new music

| Comments

[2013-12-18 Shankly disappeared in Feb 2012. I currently use Spotify]

Have you stopped listening to new music? If you don’t have cool “music seeker” friends providing your aural fix then perhaps it’s time you become that person. If you’re into the shit I’m into then you’re in luck my friend. A fellow known only as “Shankly” has been putting monthly compilations on the net for a few years now. While much of it won’t take your fancy, some of it might and that can lead you to some great new music.

Sounds Great, What Do I Do

  1. Download this months edition of “Shanklys Mixtapes”
  2. Listen to the 80 tracks noting the ones you like
  3. Make a shortlist of albums to download. On a good month I find 5.
  4. After listening to the albums a few times, go buy the best ones.

Doesn’t That Make Me A Criminal?

Hey, how many albums did you buy last year? None? Because you don’t know what to get?

What’s criminal is that people don’t know this stuff is out there. Why does Radio and TV play absolute shit when there are true artists creating beautiful music.

What’s criminal is that no one told me how fucking amazing Mogwai is. Till I heard them on Shankly’s Mixtape for Jan 2011 that is.

April 2011

Mix 1

  1. Vaccines – If You Wanna (Live)
  2. REM – Alligator Aviator Autopilot Antimatter
  3. Foo Fighters ΓΓé¼ΓÇ£ Rope
  4. Arctic Monkeys – Don’t Sit Down Cause I’ve Moved Your Chair
  5. Debbie Harry & Franz Ferdinand – Live Alone
  6. Wombats – I’m A Robot Like You
  7. Glasvegas – The World Is Yours
  8. Elbow – Lippy Kids
  9. Wolf Gang – Dancing With The Devil
  10. White Lies – Is Love (Stereolab Remix)
  11. Lykke Li – Rich Kids Blues
  12. Yeasayer – Swallowing the Decibels
  13. Uffie – Wordy Rappinghood (Evian Mix)
  14. Cold War Kids – Mine Is Yours (Passion Pit Remix)
  15. Kassidy – I Dont Know
  16. Deftones – Drive (Cars)
  17. Gruff Rhys – Take A Sentence
  18. Sara Lov – Hold Me Now (Thompson Twins)
  19. Aretha Franklin – God Bless The Child
  20. Radiohead – Supercollider

Mix 2

  1. Decemberists – Down By The Water (Live)
  2. Okkervil River – Rider
  3. My Morning Jacket – Holdin On To Black Metal
  4. New Pornographers – A Drug Deal Of The Heart
  5. Laura Stevenson & The Cans – Master of Art
  6. Felice Brothers – Fire at the Pageant
  7. Zoey Van Goey – You Told The Drunks I Knew Karate
  8. Iron & Wine – Godless Brother In Love
  9. National – Exile Vilify
  10. Antlers – Every Night My Teeth Are Falling Out
  11. Boxer Rebellion – Step Out of the Car
  12. Cascadeur – Walker
  13. Watson Twins – Angelene
  14. Low – Especially Me
  15. Caroline – Sleep
  16. William Fitzsimmons – The Tide Pulls From The Moon
  17. King Creosote & Jon Hopkins – Bubble
  18. Roddy Woomble – Work Like You Can
  19. Matt Sweeny & Bonnie Prince Billy – Must Be Blind
  20. Shearwater – Missing Islands

Mix 3

  1. Akron Family – Island
  2. Dengue Fever – Cannibal Courtship
  3. Dirtbombs – Good Life (Inner City)
  4. Grinderman – Evil
  5. PJ Harvey ΓΓé¼ΓÇ£ England
  6. Bill Callahan – America!
  7. Parenthetical Girls – Handsome Devil (Smiths)
  8. British Sea Power – Stunde Null
  9. Art Brut – Clever Clever Jazz
  10. My Dad Vs. Yours – Wildcat Strike
  11. Buffalo Tom – Down
  12. Flaming Lips – Drug Chart
  13. Airborne Toxic Event – All at Once
  14. Parts And Labour – Fake Names
  15. Help Stamp Out Loneliness – Record Shop
  16. Thomas Tantrum – Its Like Drums
  17. Snowmen ΓΓé¼ΓÇ£ Hyena
  18. Young Knives – Love My Name
  19. Black Feather – Paperhouse (Can)
  20. Ema – California

Mix 4

  1. Dananananayckroyd ΓΓé¼ΓÇ£ Reboot
  2. And So I Watch You From Afar – BEAUTIFULUNIVERSEMASTERCHAMPION
  3. Standard Fare ΓΓé¼ΓÇ£ Suitcase
  4. Pains Of Being Pure At Heart – Girl of 1,000 Dreams
  5. Boogie Monster – Castle In The Clouds
  6. Los Campesinos! – Light Leaves, Dark Sees
  7. Woebot – Blues
  8. Mogwai – Hasenheide (B)
  9. Sorry Kisses – Drifting In the Dark
  10. Four Tet ΓΓé¼ΓÇ£ Pinnacles
  11. Johnny Foreigner – What Drummers Get
  12. Tinklers – Don’t Put Your Finger In The Fan
  13. Grails – All The Colors Of The Dark
  14. Mazes – Most Days
  15. Battles ΓΓé¼ΓÇ£ Futura
  16. Bearsuit – Princess, You’re a Test
  17. She’s Hit – RE_PEATER
  18. Moonbell – Nostalgia For The Future
  19. Lovely Eggs – Muhammad Ali and All His Friends
  20. Kontakte – The Ocean Between You And Me

Slicehost RIP

| Comments

2013-12-19 Linode offers a great service with 1GB RAM VPS for $20/month

slicehost – Built for Developers

When Rackspace bought Slicehost in 2008 I suspected it would only be a matter of time before they ruined it. In May 2011 Rackspace announced that they will be shutting down Slicehost. It’s sad news for a lot of people who have been a part of the “slicehost community” for this was a company that customers felt a part of. Co-founder Matt Tanase says in this video interview the news “tears him up inside”.

When I first signed up for a slicehost VPS in 2006 I was dubious about how $20/month could buy me a server with 256MB memory and 100GB of traffic throughput. There was no signup fee, no minimum contract period and the management software was so simple and clear. My concerns that it would be oversubscribed and poorly supported were proved wrong. I was soon won over!

The guys who ran the company, Matt and Jason, also ran the servers. They chatted with customers on IRC and answered emails. Somehow they even found time to produce a podcast where they spoke candidly about their experiences and plans. Through the podcast the guys really made us feel like we were there with them.

One of the hot topics in the early days was the waitlist. Slicehost was an overnight success and the guys had to deal with its popularity. The waiting list for new VPS’s was stretching out to weeks when they came up with a novel solution. If you were willing to prepay for future months service you could move further up the queue. I can recall when paying for 6 months in advance would give you a server same day. It solved their cash flow problem and allowed them to buy more hardware.

The following year they explained the downside to this approach. The tax office saw all the prepayments as income and wanted them to pay tax on them but saw their expenditure on servers as capital expenses which could only be depreciated over several years. They were faced with a big tax bill.

I’m sad to see slicehost being dismantled. This comes on the tail of Cisco announcing their plans to kill the Flip. What is it with companies buying great products and killing them?

I’ll leave you with episode 4 of the slicehost podcast. I don’t think you’re ever going to get something this raw from Rackspace.

3 Way Handshake – Episode 4

Cisco bought Flip camcorder for $580 million and is closing it down

host@home: Choose A Virtualization Platform

| Comments

Use Virtualization

If I could offer you only one tip for the future, virtualization would be it. The long-term benefits of virtualization have been proved by scientists, whereas the rest of my advice has no basis more reliable than my own meandering experience.

OK, so which server OS virtualization platform are we going to use in our home data center? We’ve got a few choices:

VMware vSphere Hypervisor

VMware shows little regard for non Windows folk, requiring us to run the vSphere Client under a virtual machine. running windows. VMware can fuck right off.

Xen

I love Xen and am pleased to see debian is again supporting it. Amazon use Xen for their EC2 service and the last time I looked the majority of big virtual hosting providers were using it. A couple of years back I wrote a web interface for Xen called Xenium.

After all that gushing you’re probably going to think I’m recommending you use Xen right? Nope!

Oracle VirtualBox

I think my love for Xen caused me to ignore this option until recently.

VirtualBox is cross platform open source (GPL2) virtualization software for Linux, OSX, Windows and Solaris. It’s easy to install and  someone has created a web frontend (phpvirtualbox) for it that looks just like the native GUI.

I’ve only just started exploring VirtualBox but for ease of installation, freedom and functionality it looks like a winner for hosting @ home.

Things I like about VirtualBox

  • sound from Windows guest is playing on my Linux host
  • mouse moves smoothly with no need to use keys to release
  • easy to share a directory from host to guest (well…windows needed reboot)
  • VRDP gives you RDP even when your OS doesn’t

host@home: Setting Up Your Network

| Comments

[2013-12-19 I’m not currently hosting @ home but Snowden leaks have made me rethink]

My Billion 7300 modem/router does a simple task well.

My first step on the path to hosting @ home was to get a good Net connection. I selected a Naked ADSL plan from Australian provider Internode. Australians pay crazy high prices for Internet but $60 a month for 150GB (combined download/upload) doesn’t seem too steep. In order to host @ home I needed to disable the Internode network firewall to enable incoming traffic.

Internode gives me a dynamic IP (which I actually prefer). Most DSL routers come with support for dynamic DNS built in and mine does a great job of updating my DNS entry within seconds of my IP changing. All other domains hosted here will have CNAMEs pointing this host only a single hostname needs to be updated when my IP changes.

When my modem light glowed steady on Friday I knew I could get started configuring the router. I’m fond of Billion modem/routers which sell for around $60.

Configuring the router

ADSL Routers tend to be pretty easy to configure via their web interface providing you remember the admin password or have something to poke in the hole to reset it to factory defaults. The other thing you have to work out is the IP address the modem is  running on. For some reason 192.168.0.1 is not the universal standard – my modem was on 192.168.1.254.  Go figure. Here’s what I do when setting up a new host@home network.

  • Change root password from the factory default
  • Configure DHCP to handout my ISP’s nameservers and my own domain
  • Configure DHCP to IPs from 100 – 200 (I reserve others for manual addressing)
  • Forward incoming connections to a gateway IP (which forwards traffic using HAProxy)
  • Configure dynamic dns

ADSL router updates dynamic dns entry when IP changes.

I installed apache2 on my gateway host to test external access. You should be able to access it here: home.failmode.com

In the next installment…

The next post will cover setting up HAProxy on the gateway host to so that incoming requests can be routed to the correct internal servers.

SSH compression can slow you down

| Comments

[Repost from my old blog]

When copying some large files between hosts at our rack I noticed some pretty poor transfer speeds. Having recently forked out $70 for a rackmount gigabit switch I wondered what was slowing things.

It seems ssh was trying to help out by compressing everything however compressing the data took more than twice as long as transferring the uncompressed data. I proved this by disabling compression at the commandline and seeing the transfer speed more than triple.

1
2
3
4
5
mbailey@modu1:~/vm$ scp -r r03 modu4:vm/
Ubuntu 64-bit-f001.vmdk          7%  147MB   8.1MB/s   03:54 ETA

mbailey@modu1:~/vm$ scp -r -o 'Compression no'  r03 modu4:vm/
Ubuntu 64-bit-f001.vmdk        100% 2048MB  28.1MB/s   01:13 ETA

So how can we put this into practice everywhere?

Setting ‘Compression no’ in /etc/ssh/ssh_config will do the trick for me. There’s no need for my vmware hosts to be compressing files I copy between them. I do want compression when copying files over shared/slower links but I can achieve that by initiating connections that benefit from compression on boxes that are configured to use it.

If I want to enable compression I can always use the ‘-C’ switch to enable compression.

Wired to Care - Will Neuroscience Prove Jesus Right?

| Comments

Humans, like the apes we evolved from, are social creatures. Cooperation has given survival advantages to our species. One interesting aspect of our wiring is empathy. It’s been argued that this involves mirror neurons, which fire both when an animal acts and when the animal observes the same action performed by another. Whatever the cause, we feel other peoples feelings and therefore share in the benefits when we make someone feel better. Conversely, causing someone distress should give us unpleasant feelings. This seems like a simple yet effective system for social regulation that doesn’t require modern (human) innovations like verbal language, law or religion.

So how can people still be cruel to other people if they’re going to feel their emotions? Did we evolve a way to selectively shutdown this mechanism? If your tribe was under attack, surely it would be advantageous if your warriors could suppress empathic responses just long enough to beat your enemies to a pulp. You would want them to be re-enabled once the threat has gone though!

I think we have built in empathy circuit breakers that get activated when we see people we dislike. There may be other ways to suppress empathy such as “just following orders” but it’s the identification of people as bad or an enemy that has me curious. Is this a major contributor to cruelty and callousness from otherwise kind individuals? Do we become ‘selectively psychopathic’ by shutting down an important part our ‘humanity’?

Some advice I always had trouble comprehending was “love your enemies”. It may turn out to be another way of saying, “don’t disable your empathic mechanisms”. While this may not be helpful advice for a soldier on a battlefield, it’s probably good advice for us in our schools, workplaces and social gatherings.

I suspect a way to achieve this is not view anyone you deal with as ‘bad guys’ which reminds me of another quote attributed to Jesus, “Do not judge others”.

There seems to be a fair bit of research going into modulation of empathic responses. I suspect there’s a significant difference between the response of males and females to seeing a person being punished for wrongdoing.  In the TV show The Shield, it’s made very clear to you who the bad guy is in each episode and he usually gets a pounding by the end of it. My dad used to enjoy shows like The Professionals when I was a kid but my mum found the violence distressing. I wonder whether males, being the ones who probably had to defend the camp, developed the ability to ‘reverse the polarity’ on their empathic circuits and actually gain pleasure from seeing ‘bad guys’ suffer?

Perhaps avoiding the human tendency to judge others unfavourably can help us avoid triggering a survival mechanism which doesn’t have a place in modern society and in doing so, allow us to act better toward one another.

Jesus must have given this a lot of thought.

How To Loose Your Customer Base

| Comments

Yes, the misspelling in the title is deliberate. See image below.

If you’re building expensive tools for managing server infrastructure, please don’t assume your users are idiots. Warning me about the possible consequences of my action is fine. Preventing me from doing what I want to do won’t endear me to your product and poor spelling won’t increase my confidence. I’m LOOSING confidence in you VMware.

You can’t go there. Sorry, it’s the rules.

Rob Postill had a little rant about VMware last night.