Brad's Blog

web dev, django, running, food, or whatever

String Theory 2013-05-09

I'm not a physicist, but I've got some views on string theory that I'd like to share. Here goes: Brad's String Theory: Axiom I While in motion, strings will become untied, regardless of advanced techniques employed to fasten them. Brad's String Theory: Axiom II When at rest (i.e. upon completion of aforementioned motion), strings will be resistant to any attempt at unfastening. These statements are, to best of my knowledge, universally true, based on ...

Django Manager Testing Woes 2013-04-07

I've recently run into some strange behavior while testing some custom Django managers. While, I can't list all of the exact code (it's not open source), I'll try to list some simple examples that illustrate the problem so (hopefully), this post will be helpful for others. To get started, assume I have the following Model and Manager: class DefaultThingManager(models.Manager): def things(): # A custom method that retrieves some set of DefaultThing # objects. This doesn't ...

Python's zip, map, and lambda 2013-04-01

Many novice programmers (and even experienced programmers who are new to python) often get confused when they first see zip, map, and lambda. This post will provide a simple scenario that (hopefully) clarifies how these tools can be used. To start, assume that you've got two collections of values and you need to keep the largest (or smallest) from each. These could be metrics from two different systems, stock quotes from two different services, or just about anything. For ...

How in the world do you Mock a name attribute? 2013-03-14

Or... My adventures with Mock. Part 1. I've been working a lot with Mock lately (and by lately, I meand for the last three months). Though it takes a while to wrap your head around it, it's an amazing and powerful testing tool. To get started, let's look at some of the neat things you can do with Mock. Take this class, for example: class Thing(object): shape = 'square' color = 'blue' def calculate(self): # ... do some stuff ...

Why I deleted Mailbox after only an hour. 2013-03-13

I'll be honest; I was really excited about Mailbox. When I first heard about it, I'd become increasingly Sucky at Email. My inbox was a mess. I had five different kinds of flags/stars, multiple kinds of todo flags, and I was one of those read-an-email-and-mark-it-as-unread people. So, when Mailbox showed up, I really did have high hopes that it'd help me learn A New Way of managing email. I wanted to be productive. But then, I ...

Calculate a Week Range for a Date 2013-03-07

Math with dates and date ranges is often fun & enlightening! As a testament to the fun of calculating dates (particularly ranges of dates), I present the following: Given a date, how would you find the range of dates that describe the week during which your original date lies? In other words, assume today is March 7, 2013 (and it is... for now anyway). Can you answer these two questions: What was last Sunday's date? What will be the ...

How to use a turning lane 2013-02-23

Stop in the middle of the road Slowly turn half-way into the turning lane Wait forever

The Minimum Working Thing 2013-02-08

This was originally a guest post that appeared on Nibletz. The original link is here: http://nibletz.com/2013/02/08/minimum-working-guest-post/ I've been pondering this post for a long time. Any student of startups is probably familiar with the phrase Minimum Viable Product. It's really a simple idea, and I think it embodies an important philosophy for anyone starting a company. The idea is that your product (whatever it is; e.g. a service, a physical thing ...

Division By Zero 2012-11-23

In a former life (while a GA in graduate school), I was forced to had the pleasure to teach elementary and intermediate algebra. These courses are essentially the algebra curriculum you should learn during High School in the United States. Unfortunately, many college-bound students don't master the material, and find themselves in a remedial class during their college career. That's the class I was teaching. There are many concepts that are difficult for students to understand, but one ...

Vim: Jumping around! 2012-11-12

So what happens when you open a file in vim, and you're presented with lots of content? Say, 5000 lines of something. Well, I typically start searching for things: /keyword. That works great when you know what you're looking for. But it breaks down quickly when you don't. So, today's vim post is about moving faster through pages of text. Jumping to a line number I have line numbers turned on by default (:set nu, if ...