Posted by & filed under OS X.

I’m trying to make use of the latest version of ApacheBench (2.4.3) to perform some benchmarking against my local server. Unfortunately, it seems to be broke as hell.

$ ab -n 100000 http://localhost:3000/analytics
This is ApacheBench, Version 2.3 <$Revision: 1373084 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
Licensed to The Apache Software Foundation,

Benchmarking localhost (be patient)
apr_socket_recv: Connection refused (61)

Interestingly, the output of the command tells me that I’m using ab 2.3, when the HomeBrew build version is 2.4.3:

brew info ab
ab: stable 2.4.3

I find that ApacheBench generally doesn’t work very well, especially under OS X. There’s all sorts of quirks (If benchmarking the root of a site, a slash must be added or ab will error out). The most annoying part is that OS X doesn’t have a good way to allow more open ports from a single process.

Does anyone know how to get this tool working again? Or, does anyone know of a better alternative?

Posted by & filed under Personal.

It would be illegal to tell the users of your web service that you have been subpoena’d by the NSA and forced to give access to private customer data.

However, would it be illegal to create a blog post every single day saying that the service has never received a subpoena, then stop creating new posts once it has happened?

Posted by & filed under Linux, OS X.

I use the following command to recursively download a bunch of files from a website to my local machine. It is great for working with open directories of files, e.g. those made available from the Apache web server.

The following can be added to your .bash_profile or .bashrc script, depending on which your OS/distro recommends:

function download-web() {
    wget -r -nH --no-parent --reject='index.html*' "$@" ;

To invoke the command, you run it like so:


It will then download everything linked from the first page, checking each child path, to the current directory. It will not download anything above that directory, and will not keep a local copy of those index.html files (or index.html?blah=blah which get pretty annoying).

This isn’t a simple alias, but is a bash function, so that you can add a URL after the command. It should work fine in both OS X and Linux. If you are using OS X, you can follow my guide for Installing WGET on OS X.

Posted by & filed under Personal.

So, yeah, I wrote this book:

Instant Backbone.js Application Development

The process took a couple months, despite the relatively short length of the book. You wouldn’t believe how many times the book has to go back and forth between the publisher and the writer! I’ll have to write about my experiences in more depth in the future, for those of you interested in publishing works yourself.

The book is currently only available as a digital download, I think it’ll take a few weeks for the copies to get printed before we’ll see physical copies for sale.

The book itself is intended for people who know some JavaScript, and who don’t really know Backbone.js, and are looking to build Single Page Applications. If you like my writing style, and are interested in learning Backbone.js, by all means grab yourself a copy!

Posted by & filed under Reviews.

I just put down my copy of Hands-on Testing with PHPUnit How-to by Michael Lively, published through Packt Publishing.

Overall, this is a pretty good book, and covers all of the topics one would expect from a Unit Testing book. Such topics include getting PHPUnit installed via PEAR, writing and running some basic tests, doing some configuration of PHPUnit, how to incorporate PHPUnit into your project, how to generate PHPUnit tests semi-automatically using an existing codebase, fixtures and providers and mock objects, how to setup test dependencies, testing abstract classes and traits, how to expect good exceptions and errors, using output buffering for the purpose of testing CLI scripts, how one tests private and protected members, testing database connections, and making sense of the automatically generated code coverage HTML.

The book flows from subject to subject smoothly, with each new topic building on the knowledge of previous topics, without ever introducing the reader to an overly-complex topic. The reader is guided along with concise code examples and explanations of why everything is happening. The author also covers alternative libraries for making Unit Testing easier whenever possible, most notably when covering different mocking frameworks such as Mockery or the authors very-own Phake. Another appreciated set of alternatives include using SQLite for keeping track of data and how the same thing can be done with XML or YAML.

One thing I did wish the book covered more is the why behind Unit Testing, and how to get the reader into the Test Driven Development (TDD) mindset, however this is undoubtedly outside of the scope of a book in the Packt Instant series. Personally, I find myself lacking in the Unit Testing department. The last two large PHP projects I’ve worked on both had PHPUnit integrated into the codebase and I always find myself writing my Unit Tests at the last minute, well after the code had been finalized.

Several sections of the book did open my eyes to the true potential of PHPUnit, most notably the ability to automatically create unit test skeletons based on existing codebases. This will make for a great way to introduce Unit Testing to existing projects which otherwise lack testing. I was also surprised to see that PHPUnit had a solution for testing Traits, a new feature of PHP 5.4. I did find it interesting that there are standardized methods for testing database connectivity; I had always been under the impression that doing so was taboo.

If you are new to the concept of Unit Testing, and would like to apply it to PHP in particular, I highly recommend picking up a copy of Hands-on Testing with PHPUnit How-to by Michael Lively. It’s a small book, quickly digested, and will make a nice desk-side companion (heck, I’ve already got friends who want to borrow my copy). While the code is thoroughly explained, the content is terse enough to serve as a reference.

Posted by & filed under Personal.

Here’s a video I took of an alley that I have to walk through every day to work. It’s pretty obvious that someone is being very sloppy with their grease dumping habits. I’m not positive which company is dumping it. The doorway seen in the video connects to Tomukun, a local restaurant.

This same situation happens weekly. If you look closely at the stained cement, you can see that this has been happening for a long time. The smell is disgusting, and sticks around for days at a time. The grease flows from the Tomukun part of the alley, and runs through a neighboring property (used to be owned by Grand Traverse Pie Company) in their seating area. I’m pretty sure it will require some major pressure washing to fix, and is probably diminishing the property value.

I’m assuming this has gone unchecked for so long because the building in front with the seating area being ruined is currently closed. Obviously, once a business moves in, they will make sure this issue goes away pretty quickly (otherwise their customers would never want to eat outside). I’m posting this on my blog for visibility, in the hopes that I can get whoever owns the grease trap to stop dumping.

Dumped in Alley next to Tomukun

Dumped in Alley next to Tomukun

Very Old Grease Stains

Very Old Grease Stains

Viscous Grease Runoff

Viscous Grease Runoff

Viscous Grease Runoff

Viscous Grease Runoff

Stained Cement

Stained Cement


Posted by & filed under Linux, Redis.

If you’d like to have the most recent version of Redis installed on your Debian machine, follow along with this guide. Unfortunately, the process of installing it is not as easy as `sudo apt-get install redis`, which you probably already knew since you’re reading this. The current version of Redis, at the time of me writing this, is 2.6.13. Go to the website and copy the download link and be sure to change the version in the URL below:

# Install the required tools to build the source
sudo apt-get install build-essential
# Download and extract the files
tar -xzf redis-2.6.13.tar.gz
cd redis-2.6.13
# Compile
make install

Now that you’ve got it “installed”, you’re going to want to make it a Debian service (so that it can run on startup, and you can use commands like `sudo service redis start`):

# Create a user account for Redis
sudo adduser --system --no-create-home --disabled-login --disabled-password --group redis
# Make a writable log file
sudo touch /var/log/redis.log
sudo chown redis:redis /var/log/redis.log
sudo chmod u+w /var/log/redis.log
# Make an init script
cd /etc/init.d/
wget -O redis
sudo chmod u+x redis
sudo update-rc.d -f redis defaults
# Make a place to store your database
sudo mkdir /var/redis
sudo chown redis:redis /var/redis
sudo chmod u+xw /var/redis

Next, you’ll want to edit the configuration script. Do the following:

sudo mkdir /etc/redis
sudo touch /etc/redis/redis.conf
sudo chown redis:redis -R /etc/redis/
sudo vim /etc/redis/redis.conf

Here is what I use for my redis.conf file:

daemonize yes
pidfile /var/run/
logfile /var/log/redis.log
port 6379
# bind
# unixsocket /tmp/redis.sock
timeout 300
loglevel verbose
databases 16
save 900 1
save 300 10
save 60 10000
rdbcompression yes
dbfilename dump.rdb
dir /var/redis/
# requirepass foobared

Once that’s all done, run the following to make sure everything was installed properly:

$ sudo service redis start
$ redis-cli

If you see an error when the server is starting, or an error after running the CLI script that it cannot connect, something went awry. Leave a comment and I’ll be sure to lend a hand.