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
wget http://redis.googlecode.com/files/redis-2.6.13.tar.gz
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 https://gist.github.com/peterc/408762/raw -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/redis.pid
logfile /var/log/redis.log
port 6379
# bind 127.0.0.1
# 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
> INFO

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.

Posted by & filed under OS X.

Boy does my Homebrew installation like to get messed up. Pretty much every time I do a big `brew update` I have to repair everything. This is what I typically have to do:

cd /usr/local
sudo chown -R USERNAME /usr/local/.git
sudo chown -R USERNAME /usr/local
sudo chown -RL mysql:mysql /usr/local/mysql/data
git pull
git reset --hard origin/master
brew update

My permissions often end up completely out of whack, and I also get a bunch of garbage in the /usr/local directory. This fixes the permissions and pulls the latest from homebrew and runs the update. Your mileage may vary.

Posted by & filed under Linux.

If you’re using my previous method for logging a networks ever-changing public IP to a webserver you control, you can use this simple command to grab the last known IP and SSH into the box that way.

ssh USERNAME@`curl -s http://www.example.com/pong.php`

The `backticks`, when run in a shell, will execute that command and return the results. In this case, it grabs the pong script, reading the IP address it provides, and the SSH’s into it.

Posted by & filed under PHP.

<?php
$raw_header = "http://location/\r\nBadHeader";

# PHP 5.4:
$clean_header = explode("\n", explode("\r", $raw_header)[0])[0]);

# PHP 5.3:
$no_cr = explode("\r", $raw_header);
$no_nl = explode("\n", $no_cr[0]);
$clean_header = $no_nl[0];
unset($no_cr, $no_nl);

echo $clean_header;