phil wade dot org
I'm Phil Wade, I write code, homebrew beer and live with two cats, a dog, a wife and a daughter in Buffalo, NY.

Email phil (at) philwade (dot) org

My wife and I write about dinner: Us Versus Dinner

Twitter Github

Subscribe to RSS

Tweets by @phil_wade
Coffee and Tea
by phil | Mar 24, 2017 - 08 a.m.

In my life I've experimented with my caffeine intake. Sleep has always been tricky for me and caffeine is a big part of that. When I was still in college, I went through a phase of constant coffee drinking that resulted in a year of non-stop stomach problems. About a year ago, I was drinking no caffeine at all. I don't know what my ideal is, but caffeine has positive affects on productivity in general, so completely cutting it isn't great, and stomach problems are for sure not good.

I don't have the answer and I'm not the best optimizer, but currently, I drink a single cup of green tea a day. Today, I'm drinking a cup of coffee. I had to be up early and didn't go to bed soon enough last night. The coffee has more caffeine and feels like a treat. I've got to be careful though, since coffee and it's higher caffeine (and subsequent sleepless nights) is a very seductive thing. Funny how the stuff that is a treat can so quickly become the norm.
Trying to write more
by phil | Jun 4, 2015 - 09 p.m.

So it's been about three years since the last post here. That seems hard to believe, since the post before this recounts a tale from the job that I started right before moving to Buffalo, and it doesn't feel like I've lived here for three years at all. Time, as per usual, has passed more quickly than I'd like.

I don't feel bad about it, since writing hasn't been a priority for various reasons, but lately I've been feeling the itch. A majority of the posts here were the result of challenging myself to write a post a week, and it was surprising how easy it was to come up with at least something every week. I recall them being ok, but I haven't scrolled back and read through any of them in a while. Mostly, I just like the idea of having written.

And that's sort of what this post is about. Since the beginning of this year, I've been making a genuine effort to reprioritize some things that I've been neglecting. The crux of those efforts has been scheduling things and seeing how I do following through. Using Google Inbox reminders I've set myself things that I should be doing. Tonight I had a reminder pop up to "write", so here I am.

Other habits I've been trying to form: yoga, running, meditation, calling friends and making time to finish the book I've been reading for who knows how long. I've had varying success with all of these, and I've been happier, so I'm continuing to try.

Writing feels nice at the moment, so after editing this post I'll set a reminder for next week, and I can write something about the other things I've been trying.
In which python is great
by phil | Apr 22, 2012 - 10 a.m.

To me, python's greatest strength is that the syntax is almost identical to the form that programs take when they appear in your mind. This makes the time from the initial thought to final code shorter, and makes it easy for others reading your code to understand your thinking. This makes it ideal for interview problems, but mostly just makes it a joy to work with.

To profile some code that I had written, I was calculating the average of many page loads. My inital approach was to write down the numbers and then plug them into a calculator. Simple enough, but like most pure programming problems, very boring for numbers greater than three or four. Sounds like a good time for some python.

To start, I formatted my numbers as simply as possible. The file looked like this:

Wall 130 45 300 312 60 77
CPU 100 50 330 300 60 78
Mem 2000 2121 400 3100 1945 1224

I wanted it to print out the name of the run (Baseline in this case), and then print an average of each measurement. The code I wrote was this:

f = open('runs', 'r')

for line in f:
    parts = line.split(' ')
    sum = 0
    count = 0
    for part in parts:
            n = int(part)
            sum += n
            count += 1
        except ValueError:
            print part

        print sum / count
    except ZeroDivisionError:

Short, and gets the job done. The best part is that it only took about five minutes from inception to working code. I needed to run it twice to get the names of the exceptions correct, but beyond that, it took me almost no time compared to the amount of time it saved, and that's a beautiful thing.

Could I have done it with awk? or excel? Certainly. However, one requires opening up excel (if you even have it. Also, yuck), and the other would require a bit of reading to figure out. Neither is really ideal. Although the awk one might be sort of fun. Perhaps we'll see about that in a future post.
A short development tale
by phil | Apr 4, 2012 - 07 p.m.

I missed posting last week, and this week I'm also feeling pretty overwhelmed. I'm working on finding a place to live and starting a job in a new city. So instead of trying to come up with something completely new to write about and missing a second week, I'm going to just relate a tale of code deployment gone wrong.

Roughly three years ago, I was working, and at the time, the company was in a bit of flux. The development team was understaffed, so with a ow level of experience, I inherited the job of deploying the website to production.

This meant taking machines in and out of service by logging into the load balancer, rsyncing new code to every machine, and then logging directly into the production servers to clear cache before making them live again. Clearing the cache was done by going into the cache directory and typing "/bin/rm -rf ." - it was necessary to do this because rm had been aliased to "rm -i", which prompted for every file removed, mainly for safety reasons.

This process was careful work, but at the same time, it was quite tedious. So while various tasks were running, I did what any good programmer does during downtime. I dorked around on the internet.

So one day, while doing a deployment, I was looking at reddit. When I looked up, my boss was standing over my shoulder - not just any boss, but the big boss. I'm not sure how many management layers existed between us at the time, but it was several. Needless to say, I felt a bit put off that I had been caught screwing around. He had a question. I answered quickly, spun in my chair, and executed the next command in my routine. "/bin/rm -rf ." Then I got up to get some coffee.

When I came back, the command was still running, which was unusual. I didn't think much of it until I saw a string of permission denied errors appear. That was very unusual. It had never happened before. That's when I realized I had never changed directories to where the cache was. I had just removed everything in the home directory. Which was also the web root.


And that's why you automate your deployments.
(I eventually did)
On the importance of backups
by phil | Mar 24, 2012 - 11 a.m.

I like to keep my stuff backed up. I've got a huge external drive next to my laptop that I use as a mac time machine. For stuff like tax backups, I also throw a copy in my dropbox. And another on my web server. I used to put a copy on a thumb drive. I wish I could find the source of a piece of advice I once read, but my google skill is lacking today. Basically, the jist was: "If you have n copies of something, you really only have n - 1 copies for all practical purposes." If you only have one copy of anything, you could find yourself without that thing any moment.

Making bunches of copies may also appeal to my inner hoarder sensibilities without taking up extra space in my house, but I'm going with the "just being safe" argument. At least publicly.

Either way, I realized just the other day that, to my horror, the only copy I have of my blog is the single database at my web host. I know for a fact that they do regular backups, but for my own piece of mind, I'd like to have copies myself.

So I wrote a little script that hooks into my django models, converts my posts to markdown formatting, and saves them to flat files. It also saves some meta data about each post in a related json file. At the moment it's nothing to write home about really, and it messes up the markup that I use for code blocks, but it's a good enough backup for most purposes. I plan on extending it a bit so that I can write posts as flat files and have them converted to html and synced back out to the live site, automatically push the copies to github, etc.

That's the other advantage. Now that my blog posts exist outside of a database, I can push the markdown files out to github. That way, if my grammar sucks or something, anyone can correct it and submit a pull request. That's assuming anyone cares to correct my grammar, but let's not get all academic here.

You can check out my backup script here, and the repository with copies of all my blog posts here.