I was working with the official Ruby gem for the Zendesk API. It’s a quirky little thing but on the whole quite nice to work with. I did run into one little gotcha: in order to retrieve all the items in a paginated collection, you have to use the #all! or #all methods (the bang version raises an error), and you must pass it a block.
I’m fiddling with a bit of Ruby code for my silly Ioughta gem. In this module, the each_resolved_pair method takes a structure of “pairs” (of symbols and lambdas) and mutates them (by calling the lambda with an incrementing value), returning the resolved pairs.
I thought I’d write about how fanriff.com serves its Ember.js index from its Sinatra.rb API, and how web clients interacts with the back-end once the application is loaded. It started to run a little long so I’ve broken it up into parts. This first chapter will cover some background information on Ember, the fanriff.com web architecture, and how we deploy our Ember index to our stack.
If your Rack application (and probably other types of applications) lives behind a reverse proxy, always set an X-Forwarded-Proto request header. I recently ran into an issue where Rack::Session (which I’m using for an OAuth1.0a server-side login flow) wouldn’t let me set a secure cookie because it didn’t think I was serving a secure web site.
I have forwardfor disabled in my HAproxy config because I’m using PROXY protocol to talk to Varnish. Manually adding the X-Forwarded-Proto header to the request fixed the issue, and now I want those three hours of my life back! Hopefully this comes up in someone else’s frantic googling at some point in the future and saves them a similar headache.
There are a tremendous number of things you can do today to make your site more secure, while preserving compatibility with all but the oldest web clients (I’m looking at you, Java 6 and Internet Explorer 6). If you haven’t been keeping up with the state of the art, this includes things like (cue Benny Hill music):
The slides for my recent Torii for Ember.js Lightning Talk (it ran a little long, so it was more of a “thunder” talk) are now available to download. They closely follow my post about Ember.js and Torii from September, and indeed the slides link to that post for the code walkthrough. Please let me know in the comments if you have any questions, and of course I’m available to chat in the EmberJS Community Slack team as @mwpmaybe (invite yourself here if you’re not already signed up).
I think there’s a video of my talk, but I understand the quality is not that great. I’ll post it here as soon as possible, assuming it’s not too bad.
Every now and then, rpi-update will crash halfway through and completely hose up the boot partition on my Raspberry Pi’s sdcard. To fix it, I have to mount the sdcard on my Mac, repair the volume, and download the firmware bits from rpi-firmware. Here’s that process in a nutshell.
Unfortunately, this doesn’t work in Sinatra, or at least not on Sinatra 1.4.6, Rack 1.6.4, and Ruby 2.2.3. Why? Well, body is (for some reason) an array, so its length is probably zero (nil body) or one. It also occurs to me that we care more about the byte size of the body than its string length; if you think a 513-byte response is worth compressing, 512 characters encoded in UTF-32 (2,048 bytes) certainly is!
Here’s a modified (and code-golfed) version of the above snippet for Sinatra: