January 2012
2 posts
5 tags
Book Review: HTML5 Cookbook by Christopher...
Summary
HTML5 Cookbook provides an overview and examples of new HTML 5 features and related JavaScript APIs. The cookbook series aims to provide short, targeted chapters that solve real world problems, and for simple use-cases, this book provides that.
Most of the material in the book could be found in online tutorials, but it provides a good overview of the available technologies in a...
November 2011
2 posts
3 tags
Book Review: A Bug Hunter's Diary by Tobias Klein;...
Summary
A Bug Hunter’s Diary describes the technical details of how the author identified and analyzed software security bugs. It doesn’t get into exploiting the bugs because, as the author points out at the end of every chapter, it’s illegal to publish exploits in Germany.
I expected a light treatment based on the cute title and cover, but it was mostly C code,...
5 tags
Book Review: Test-Driven Infrastructure with Chef...
Summary
Test-Driven Infrastructure with Chef describes a rationale and an approach to developing automated tests for system infrastructure. It includes an explanation of behavior-driven development, and detailed instructions for setting up a testing system using cucumber-chef on EC2.
Audience
Surprisingly little time was spent talking about cucumber-chef and how to use it. The majority of...
August 2011
1 post
The Mother of All Interview Questions -... →
“Does your process involve invention? … ” This is a great interview question. It’s a conversation starter, and it’s both relevant to evaluating a candidate and, hopefully, an interesting question for the interviewee to consider.
July 2011
2 posts
Making applications scalable with Load Balancing →
Old but useful article about load balancing issues by the author of HAProxy
Jay Fields' Thoughts: The High-Level Test... →
Two key takeaways from this post:
Sometimes it’s better to clobber an unmaintainable test suite and start over with something simple and focused on maximizing value.
Maintenance of high-level tests might be a sensible place to break from the shared code-ownership principle.
March 2011
3 posts
Temporarily Change the Rails Environment
A helper method to change the Rails environment within a block. I use this for testing isolated, environment-specific methods. Obviously, I wouldn’t suggest using this outside of test code. You could easily do something very stupid.
def with_rails_env(environment, &block)
begin
original_env = Rails.env
Rails.instance_variable_set(:@_env, environment)
yield if...
Shady Characters - The secret life of punctuation →
Proving once again the breadth of my geekdom, I’m really enjoying this blog about the history of punctuation.
ActiveRecord Join Table Gotcha
Whenever I create join tables, I’m always tempted to add an ID column, in case I want to upgrade it to a :through association at some point. I’m also tempted to timestamp columns, so that I can know when the association was created.
Sadly, it just doesn’t work with has_and_belongs_to_many.
- If you add an ID column, Rails will choke as soon as you try to access it. IDs are...
February 2011
1 post
MySQL Mass Destruction with xargs
Yesterday, I needed to clobber a bunch of similarly-named database schemas on my development machine. I could have selected and deleted 40 times in Navicat, but I thought I’d try to write a one-liner instead:
mysql -u root -e "show databases;" | grep _3_6 | xargs -IDB_NAME mysql -u root -e "drop database DB_NAME;"
The first part pulls the database names all the database names. The...
September 2010
2 posts
ShareableRouteSet - Gist →
This is a class to allow the creation of Rails route helpers for external applications without interfering with the application routes.
This is useful when you have a Rails application that needs to have some knowledge about the routes in another application. The routes could be published by the source application in a plugin/gem to avoid duplication of routing information.
Find and Concatenate Files with Spaces
Normally, xargs will interpret the spaces in the filenames as separate files. The -print0 argument to find paired with the -0 argument to xargs will use some other magical delimiter so that the spacey filenames remain intact as you pipe them around.
find ./spacey_files -name *Report* -type f -print0 | xargs -0 cat > all_reports.csv
April 2010
1 post
Bulk Update Github Hooks
The Github API doesn’t support updating hooks, but I’ve got way too many projects going to do it by hand. I wrote up this script to update all of my hooks at once. I used the mechanize gem to drive the web admin interface for the hooks that I needed.
The gist with the code is here: http://gist.github.com/375621
November 2009
2 posts
2 tags
Remove an Environment Variable in Bash
export -n RAILS_ENV
Setting an environment variable to nothing is not the same as removing it entirely. If really need it to go away completely, use the -n flag on export.
Behold:
jason@idaho:~/Code/subakva$ env | grep RAILS_ENV
jason@idaho:~/Code/subakva$ export RAILS_ENV=development
jason@idaho:~/Code/subakva$ env | grep RAILS_ENV
RAILS_ENV=development
jason@idaho:~/Code/subakva$ export...
RunCodeRun
For a personal project, I’m trying out RunCodeRun, a service for doing automated builds for projects on github.
I think the idea is a good one. For gems or simple web apps without complicated integration tests, getting an automated build up and running is dead simple. It’s just a matter of adding a post-commit hook to your github project to notify runcoderun that the code has been...
May 2009
4 posts
Git Cannot Merge? Try committing first.
I ran into this git error again today:
Entry 'blah/blah.rb' would be overwritten by merge. Cannot merge.
After messing around with it for a while, I remembered the last time this happened. The solution is to commit your current conflicting changes, then merge afterwards.
Sunlight Labs: Blog - Apps for America 2: The... →
2 tags
URI.join v. File.join
URI.join does not work quite the same way as File.join in Ruby. The aim of URI.join is more to calculate a relative path (as a browser would) than to simply concatenate path elements cleanly. The irb output below demonstrates this:
irb> require 'uri' #=> true
irb> host = 'http://www.example.com' #=> "http://www.example.com"
irb> prefix = 'prefix' #=> "prefix"
irb> file =...
2 tags
Sinatra Hacking at RailsConf
I played around with Sinatra a bit at RailsConf and there’s a tiny spec of open source code to show for it:
Bourbon - An extension to Sinatra that adds support for Liquid templates.
ColorURL - A simple Sinatra application that displays a page in the color of the URL path. It uses the color gem and is deployed on Heroku. [http://colorurl.heroku.com/mauve]
April 2009
3 posts
Character Encodings in Ruby
I’ve been dealing with some issues related to character encodings in MySQL, and I ran across this series of articles. It covers the fundamentals of character sets and encodings as well as an overview of how they work with Ruby 1.8 and 1.9:
Shades of Gray: Understanding M17n
Ruby Network Error List
I’m writing some code that needs to handle a failed network connection. Here’s an almost certainly incomplete list of the exceptions I need rescue:
SocketError, Timeout::Error, ActiveResource::TimeoutError, Errno::ECONNREFUSED, Errno::EHOSTDOWN, Errno::EHOSTUNREACH
How about an IOError or something?
s3cmd with MacPorts
I ran into a string of errors while trying to run s3cmd with MacPorts python.
/opt/local/bin/s3cmd uses ParameterError before importing it. I moved the imports out of the try/except block to get this working:
if __name__ == '__main__':
from S3 import PkgInfo
from S3.S3 import *
from S3.Config import Config
from S3.S3Uri import *
from S3 import Utils
from S3.Exceptions import *
from...
September 2008
1 post
1 tag
Only in Python...
I just imported code from the future. That famous XKCD comic is a lot closer to reality than you might have thought.
from __future__ import with_statement
February 2008
1 post
1 tag
Clone My Fields, Please
The Introduction
I recently started using the SearchManager from the Mercury Tide white paper on using MySQL full-text search with Django. It’s been helpful, but I ran into a bug recently while trying to add a default filter to a SearchManager subclass.
The Boring Context
Rather than deleting objects from the database, my application sets a boolean flag to indicate that the content is...