Brad's Blog

web dev, django, running, food, or whatever

Published: 2013-04-01

Python's zip, map, and lambda

lambda map python zip

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 ...

Published: 2013-03-15

How in the world do you Mock a name attribute?

mock python testing

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 ...

Published: 2013-03-13

Why I deleted Mailbox after only an hour.

email gmail inboxzero ios mailbox

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 ...

Published: 2013-03-07

Calculate a Week Range for a Date

date isocalendar python range

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 ...

Published: 2013-02-23

How to use a turning lane

comic driving

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

Published: 2013-02-08

The Minimum Working Thing

entrepreneurship programming startups web

This was originally a guest post that appeared on Nibletz. The original link is here: 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 ...

Published: 2012-11-23

Division By Zero

division math zero

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 ...

Published: 2012-11-12

Vim: Jumping around!

editor unix vi vim

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 ...

Published: 2012-11-04

Let's be a better vim user

editor programming unix vim

It's November. For many, that means a month of writing (NaNoWriMo). For others, that's a month of cultivating a fine moustache (Movember). I, however, am making an effort to become a better vim user. Call it NoVIMber or VIMmember or whatever. I'll try to periodically blog about what I'm doing, but I'm not making any promises (other than to force myself to be more productive). I've been using vim for a long time (since ...

Published: 2012-10-30

Customizing Django's password_change view

django programming python web

If you have a site where users have the traditional username/password combination, you've got to provide some way to let users change their password. Luckily, this is fairly easy to do with Django. The auth app comes with a password_change view that does what you'd probably expect. It's also fairly easy to set up. You add a line similar to the following to your root URLConf: url(r'^accounts/', include('django.contrib.auth.urls')), You also ...