tenderlovemaking.com Archives - 15 June 2013, Saturday

I posted a benchmark on twitter about comparing a DateTime with a string. This is a short blurrrggghhh post about the benchmark and why there is such a performance discrepancy. Here is the benchmark: require 'benchmark/ips' require 'active_support/all' if ENV['AS'] require 'date' now ...

Right now people who publish native gems targeting the windows platform have a problem. Our problem is supporting ruby 1.8 and 1.9 at the same time. Right now, we can’t build one gem targeting 1.8 and one gem targeting 1.9, and have rubygems differentiate the two. I have a solution: f...

Our attacker knows that this class is defined in the system. Using YAML, along with Psych’s object deserialization, they can inject any object in to the system they choose. So how can they use this object? Let’s take a look at the YAML payload for exploiting this code, then talk about...

TL;DR This is your periodic reminder to specify dependency versions in your Gemfile I started updating one of our larger projects at work to use edge Rails. This project uses devise, and the Gemfile declares the dependency like this: gem "devise" The latest version of devise correctly...

Ruby 1.9 will return true for public and protected methods, but false for private methods. If we compare this to actually calling the method, we’ll see an inconsistent behavior. Let’s interleave respond_to? checks along with calling the method to see what happens:

Our basic requirements for dealing with a database connection are essentially the same as when dealing with files. We need to open our database connection, do some work with the connection (send and receive queries), and close the connection. We have these similarities, yet the API fo...

Messages a delimited by two newlines. The data field is the event’s payload. In this example, I’ve just embedded some JSON data in the payload. The event field is the name of the event to fire in JavaScript. The id field should be a unique id of the message. SSE does automatic reconne...

Related:

Besides enabling multi-threading by default, one of the things I really wanted for Rails 4.0 is the ability to stream data to the client. I want the ability to treat the response object as an I/O object, and have the data I write immediately available to the client. Essentially, the a...

Related:

Sometimes buffering a response is less than ideal. It would be nice if we could send the head tag along with any css or script includes to the browser as quickly as possible. Then the browser can download external resources while we're still processing data on the server. If this were...

Related:

2012-07-09 @ 16:51 Crouching Tiger, Hidden Salami I’ve been learning how to cure meat, and I thought I should share my setup. I’m currently on my third batch of meat (second time curing salami). Curing meat requires control of the environment, external and internal to the meat. This p...

So where do we start? Typically, we begin at the beginning. Today we'll start profiling the rake environment command. This task simply requires all of the files for your application, readying everything for execution against a Rails context. Many things can impact the startup time of ...

A while back a ticket was filed on the Rails tracker to turn on config.threadsafe! mode by default in production . Unfortunately, this change was met with some resistance. Rather than make resistance to change a negative thing, I would like to make it a positive thing by talking about...

Yay! I got vim and autotest integration working. When I run autotest, if there is an error, I can have Vim read the errors from autotest and jump me to the right place. Here is a video of me using it: Please note that I’m not copying and pasting anything. In vim, I hit a command and V...

It’s been forever since I’ve written a blog entry, so LETS DO THIS . I want to talk about reading RFID tags with Ruby. I am a nerd, so even though I can’t think of a good application, I am compelled to be able to read RFID tags. I love programming Ruby, so of course, I have to do this...

I love making beef jerky. I started making jerky by using Alton Brown’s recipe , but I found his jerky making apparatus to be lacking in a few key areas, so I put together my own jerky making setup. I use a modified food dehydrator for making my jerky. I prefer using a food dehydrator...