August Flanagan

software engineer; oss tinkerer; consumer of web services, burritos

Read this first

The first paying customer

Line by line your product begins to take shape. Bleary eyed and tired you push on, willing your brain to solve just one more piece of the puzzle before you call it a night.

You’re excited. You’re creating something. The thought that someone, somewhere is going to use it soon pushes you forward. You think “100 paying customers, that’s it, that’s all it would take for me to consider this a success.”

The building phase is full of excitement, full of optimism. You’ve been through it before. You know it’s silly to be so excited, to imagine the success of your product long before it has launched. The slog of building a user base is hard. You know it’s harder than what you’re doing as you spot your bug, bang out that last line of code and close your laptop.

It’s the big day. You launch. You know it’s not really a big day. Your product is niche. You created it for yourself and a couple of

Continue reading →


Log client-side assertion errors to server

I’ve been writing a lot of python lately, and the assert statement is my new best friend. You use it like this:

assert a == b, "a did not equal b!"

I’ve also been writing a lot of javascript lately, and the console object has a similar assert method that can be used like so:

console.assert(a === b, 'a did not equal b');

Console asserts are pretty useless though unless you are debugging in a dev environment. Today I wanted to add some assert statements that would log assertion failures (with a stack trace) to the server. Here’s what I came up with.

var logger = function () {
    return {
        assert: function (test, msg) {
            msg = msg || "(no error message)";
            if (!test) {
                try {
                    throw Error();
                } catch (e) {
                    if (e.stack) {
                        this.logError(msg + '\n' + e.stack);

Continue reading →


Load most recent database backup from S3 into MySQL

Like a lot people I back up a production database to S3 quite frequently. I run my development database locally, and need a simple way to keep it up to date with production data.

So, yesterday I threw together this quick bash script that always fetches my most recent backup and loads it into my local MySQL database.

echo -e "Getting latest MySQL backup...\n"

# Basic variables
bucket="s3://db_backups"

# Timestamp (sortable AND readable)
year=`TZ=America/Los_Angeles date +%Y`
month=`TZ=America/Los_Angeles date +%m`
day=`TZ=America/Los_Angeles date +%d`

most_recent_backup=`s3cmd ls $bucket/$year/$month/$day/* | tail -1 | awk '{print $4}'`

tmpfile="/tmp/db_backup.sql.gz"
s3cmd get "$most_recent_backup" "$tmpfile"
gunzip $tmpfile

echo "To load the backup database enter the mysql root user's password"
read -s -p Password: mysqlpass

echo -e "\nLoading DB...\n"
mysql -u root -p$mysqlpass

Continue reading →