Blug Opdate

This is the obiligatory “I’ve update my blog, and I’m serious about adding regular content, guys. From here on, things will be different,” post.

This site now sports the Minimal Mistakes jekyll theme and with it, better responsive support.

Additionally, the site has a new vanity domain, a real and appropriate moniker (“Fail Fast”), more room for large images, and a marginally less grumpy author avatar.

I still need to add a nice banner image and favicon, but it’s not pressing.

I’m looking forward to the content I’ve been meaning to write. Fingers crossed.


Ran into an issue this weekend with httparty, and an API (mapquest) that was sensitive to query parameter order. Specifically, when batch geocoding locations, mapquest expects a query string like: ?location=foo&location=bar&location=baz, and will return geocode results in the order received.

I noticed the issue when an api call for a US city returned a result in Ireland.

Httparty has two methods of encoding query parameters. The default, rails-friendly, way converts

:param => ['bar','baz']

into

?param[]=foo&param[]=bar

This can be disabled by calling disable_rails_query_string_format, which replaces the default query string normalizer with this proc

NON_RAILS_QUERY_STRING_NORMALIZER = Proc.new do |query|
  Array(query).map do |key, value|
    if value.nil?
      key.to_s
    elsif value.is_a?(Array)
      value.map {|v| "#{key}=#{URI.encode(v.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"}
    else
      HashConversions.to_params(key => value)
    end
  end.flatten.sort.join('&')
end

Different version of ruby (even different 1.8.7 versions) will sort the result of

Array({:key => :value})

differently. A sort was added at the end of the normalizer proc to ensure that the query string is consistent across versions, likely for testing. This works, but has the side effect of also shuffling the order of array value elements.

Solutions

  • Presort query parameters to avoid surprises,
  • use an alternate proc for query normalization (I just removed the sort entirely in my app),
  • submit request as json (or other format)
  • or wait until it’s fixed upstream.

Httparty pull request can be found here: https://github.com/jnunemaker/httparty/pull/245


Raspberry Pi Paper Cases

Received 3 Raspberry Pi cases as gifts recently, and my wife was kind enough to supply me with these excellent boxes.

Three paper raspberry pi cases

Box template can be found here


Copy Last Git Hash

Show the most recent git commit hash, and copy it to the clipboard:

Linux

git rev-parse HEAD | tee xclip -selection c

Windows (mingw/cygwin)

git rev-parse HEAD | tee /dev/clipboard

Mac

git rev-parse HEAD | tee pbcopy

Recently discovered Chocolatey, which I’ll be using for basic software installation on new machines.

Chocolatey both suffers and benefits from its community-driven packages. While there are a large number of packages available, especially compared to similar windows tools, several packages I tried are were not functioning and seem abandoned.

My current install script and package lists can be found here.