Brad's Blog

What's in my requirements.txt 2017-05-14

It's Sunday, and tomorrow is our scheduled monthly python meetup in Memphis, and it's one of those month's where I've been busy and I haven't done a good job of finding a speaker. So, that mean's I've got to pull something together at the last minute. While racking my brain for a quick-and-easy topic, I thought, "I wonder what python packages I'm using most?" So, I ran this nifty monstrosity of a ...

The Blue Collar Programmer 2017-02-12

There's a recent Wired article that's been floating around the web that asks if computer programming is the next big thing in blue collar work. I find this article interesting, because I've long though about computer programming a skilled trade. In one sense, it's not unlike being a plumber or and electician, both of which can provide very decent, middle-class salaries. In fact, thinking of tech jobs in this manner is nothing new! In the '90s ...

Webucator: zip, map, and lambda 2015-08-30

Recently, the folks from Webucator, who have a series of python tutorials got in touch with me about one of my blog posts: Python's zip, map, and lambda. They wanted to turn that article into a tutorial video. I thought that sounded like a pretty cool idea, so if you're into video tutorials, give this a view. And check out some of their other tutorials as well.

An Attribute by any other name... 2013-09-11

Let's explore some python attributes, shall we? (note: this is python 2.7.x) Attributes Let's consider a simple class, N, with a single attribute, numbers containing values 0 - 9. class N(object): numbers = range(10) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] We can create an instance of this class, then perform some operations on the attribute (like accessing or setting its values). >>> n = N() >>> n.numbers # get the value of the ...

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

Let's be a better vim user 2012-11-04

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

Customizing Django's password_change view 2012-10-30

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

Django Models & Mixins for cleaner code 2012-09-26

I've been using Mixins lately to DRY-ly make certain behavior available to several different Django models. If you're not familiar with mixins, there's a great discussion over on StackOverflow. Here's a simple example to illustrate what I've been doing. In building Work for Pie, we've got a UserProfile model that looks something like this: class UserProfile(models.Model): user = models.OneToOneField(User) tagline = models.CharField(max_length=140) biography = models.TextField() avatar_url = models.URLField(max_length ...

Fixing Bugs. 2012-09-25

Convert Tables to Unordered Lists 2010-05-28

If you've ever had the pleasure of working with old HTML content, you've surely seen some <table>'s where they don't belong. Lately, that's the sort of thing I've been dealing with on a regular basis, and for some reason, I often see a list of information in a table.Wouldn't it be nice if there were an easy way to turn these tables into unordered lists? Thanks to BeautifulSoup, this is really not ...

Resize the iTunes Window 2010-01-14

My Macbook Pro is my main machine. At the office, I connect it to a 20" Cinema display. At home, I connect it to a 24" Samsung Monitory (Model 2494SW Glossy Black, which I really like, btw.)There's a down-side to all this, though. I mostly just notice it with iTunes. When I'm working on the laptop without an external monitor, my iTunes window is larger than my screen :( Unfortunately, clicking the Maximize button doesn't do what ...

Dynamically Displaying Fields in a ModelForm 2009-04-21

The Problem: I want to dynamically include some fields in a ModelForm based on some external criteria. Sometimes I want the fields displayed, sometimes I don't. I'm going to try to explain this scenario through a (albeit contrived) example. I have a Model that looks like the following:class Suff(models.Model): foo = models.CharField(max_length=255) bar = models.BooleanField(default=False, blank=True) def is_foo_bar(self): ''' is this model's foo attribute set to 'bar' ''' return ...

How to Set up a Foreign Key Constraint in MySQL 2009-04-01

The default storage engine in MySQL (MyISAM) does not support Foreign Key constraints. If you want to use Foreign Keys in Mysql, you need to use InnoDB.The following is a simple example that illustrates Foreign Key constraints, we'll create tables to store information about Authors and their Books. The Foreign key will link a book to an Author. Note, that in MySQL we need to use the InnoDB storage engine to support Foreign Key Constraints.First, we need ...

Add a Context Processor for your Django app using Sites 2009-01-05

I've recently refactored a significant number of my Django Apps so that they include the "sites" framework. Essentially, this allows me to use the same code (and database) for multiple sites. For Example, if I was was building a CMS (and I am!), I might have a model that defines a "page":from django.db import modelsfrom django.contrib.auth.models import Userfrom django.contrib.sites.models import Siteclass Page(models.Model): title = models.CharField('title', max_length=255) content ...

Morphology is Fun! 2009-01-04

Morphological operations are very common in image processing. The two most basic of these are Erosion and Dilations, and from these, additional morphological operations can be performed. While there is an abundance of literature on the topic of morphology, I often like to view concrete examples of the operations. So, I've published a few images that illustrate the output of 1-to-5 iterations of various morphological operations --erosion, dilation, opening, closing, gradient, top hat, and black hat--with various structuring elements--rectangle ...

That Looks about Right 2008-12-04

history | awk '{ print $2 }' | sort | uniq -c | sort -rn | head 152 cd 145 ll 73 vi 20 rm 18 svn 13 exit 9 ls 8 grep 7 php 5 wgetvia b-list.org

Soup's On! And it IS Beautiful! 2008-11-17

Here's the problem: There's a BAJILLIION static html pages sitting out on a server, and I need to migrate all that content to a new Database-driven CMS. Additionally, I need to get rid of a lot of non-essential hard-coded presentational markup (like align="center" or font="whatever") and any inline styles that may exist... (you know, because external CSS is the way to go).I could spend hours and hours just copy-/pasting stuff... but meh. Enter BeautifulSoup ...

Recursively Renaming files 2008-09-05

My hosting provider offers PHP4 and PHP5. Unfortunately, all files ending in .php get interpreted by PHP4, while all files ending in .php5 get interpreted by PHP5. So, how do I quickly change all of my files that end in .php to .php5?Do a google search for "recursively rename files", and you might run across this:http://seal-7.blogspot.com/2006/12/recursively-rename-files-with-regex-one.htmlSo, to accomplish my task, I use the following:find . -type f -print0 | xargs -0 rename ...

How to update an input value with the value from a selected option using Prototype 2008-08-12

Today, I needed to set the value of an HTML input element based on the value of a option in a select element. This is fairly easy to do with Prototype's writeAttribute. Here's an example:A simple javascript function to do the work:function populate_input(){ var field = $('tf_select').getValue(); $('tf').writeAttribute('value', field);}A simple HTML snippet to see it in action:<div><p><select id="tf_select" name="tf_select" onchange="populate_input();"><option value="">- choose one -</option><option value="v1">value ...

The Structure of a Django App 2008-07-15

Previously, I'd lamented the difficultly present in choosing an web development framework. I'd worked through several symfony tutorials, and though I could see the benefits down the road, it just didn't feel right to me (yes... "feel" is a technical drawback).So, I checked out a copy of Django, and I haven't looked back. If you're the least bit proficient with python, and you need to build a database-driven web site, USE DJANGO! They have ...

Lions, Tigers, and Web Development Frameworks, oh my! 2008-06-17

Apparently I've stumbled upon a problem that has recently faced many web developers. That is, I would like to adopt an open-source web development framework for mid-sized project. Well... searching that phrase only yields 200,000+ results. So how does one choose?I guess Ruby on Rails sparked the whole "Web Development Framework" movement (among other things). I've typically used PHP for my web-based projects in the past, but over the last 2 years, I've also become ...

The Never-ending "To-Learn" List 2007-09-10

I'm officially a student! August marked the beginning of a new semester for me, and this time I'm a full-time student. After being on the faculty side of things for a while, I'm actually having a great time being a student again. One of the major benefits of being a student is that I'm actually getting to dive into that never-ending list of technology tools that I've been wanting to learn how to use!Just ...

Hello Torque, again. 2007-05-16

Well, I've just begun to dig into the Torque Game Engine again, but this time, I'm building it on a Linux box. Once I downloaded the Linux source, it took me a while to figure out how to get it compiled. TGE's configuration is a little different than the typical "./configure and make" process.First of all, I tried to make sure I had all of the development tools necessary to build TGE, including nasm, libogg, libvorbis ...

Javascript: What is the standard? 2007-02-27

I've recently been writing a little javascript, and I needed to chage the value of some text inside an html/xhtml element. It seems there are several ways to do this, but evey browser may or may not support the same method for doing it (big surprise, here) I'm not sure what is considered the "standard" way. Here's a little script that I use to help me decide which browsers support which methods for altering text within ...

magic SysRq 2007-02-09

Occasionally I goof up. Yes, as much as I hate to admit it, it's true. However, thanks to this handy tutorial on liquidweather.net, I've learned about some nifty ways to kill things in linux.In addition to the traditional ways to kill a process, this tutorial lists some magic SysRq key combinations that--if enabled in your kernel--can provide a nice option to just pulling the plug...Alt+SysRq+K - Kills all processes (SIGKILL / kill -9)Alt+SysRq ...

Migrating PHP scripts to MySQL from PostgreSQL 2007-01-05

I've recently had to work on a project where I needed toconvert some very basic PHP code thataccessed a postgresqldatabase so that it would work with mysql. For the most part, this has beenfairly simple thanks to rpl. Many of PHP'sdatabase functions have very similar names, so I simply use rpl toconvert the existing code. Here's a simple bashscript that I put together to convert some of my postgresqlfunctions to mysql: #!/bin/bash if [ ! -n "$1" ] then ...

Spammers never die! 2006-12-17

I've recently received a lot of spam through my contact form, and it's starting to get on my nerves. Apparently the spammers have noticed that many developers are trying to thwart their attempts to sneak extra header information into PHP's mail function, so they've resorted to spamming websites directly! (or am I the only one?)The messages I've been getting actually include a long list of URLs of the form: [URL=http:www.whatever.com ...

Voice Observation 2006-11-09

Apparently, I haven't quite beat the flu... or whatever it is that's making me cough. So head over to my local Medical Practitioner and get a nice pharmaceutical conglomeration injected into my hip. Apparently, I could also use some antibiotics, too... so I head over to walgreens and drop off the magical note that lets them know it's OK to give me drugs. I wait several hours, and then I discover that my insurance has rejected a ...

Torque 2006-10-15

Well, I finally bought an Indie Game License for the Torque Game Engine. Like many young men over the past decade or so, I got into Computer Science thinking I'd like to create video games. Maybe I'll finally get that chance!My initial impressions with Torque are a little mixed though. I can immediately see huge potention in the sort of things you can do without even touching the Engine itself... thanks to the built-in scripting language and ...

Data Structures 2006-09-28

Well, since I'm teaching a course in Data Structures this semester, I thought that I'd post some of the basic examples that I've given in class. For now, you can find some source code under my Data Structurs Projects Page. All of the code is written in C++ and illustrates some simple data structures using the STL.

OpenCV on Mac OS X 2006-09-06

I finally got arount to compiling OpenCV on my G4 Mac mini. While there is a lot of good information online as to how to do this, there were a few final steps that took me a while to either figure out or find. Apparently using OpenCV on OS X is still a new thing...First of all, follow the directions here at the Mac OS X OpenCV Port Wiki. (Note the two different configure options for Fink and MacPorts ...

OpenCV 2006-08-18

Those who know me know that I'm a huge proponent of Open Source Software. I use it daily, and the sheer number of quality open source projects just astounds me. The latest to do so is OpenCV, a Computer Vision library originally from Intel.In a few weeks I will take my first steps into the world of computer vision, and like so many times before, an open source project will guide me. Awesome.

YouOS 2006-07-24

Occasionally, I run across some project that's implementing an idea that I've had ... That's the case with YouOS. I think I even wrote a paper about it in 1998, but that's what happens when your lazy (read: too many other things you have to do!)I created an account, and though it was a little slow for my wife's laptop, YouOS is really a very impressive project. Now, all the world needs is a very ...

Roll your own! 2006-07-14

With all the good FOSS CMS software out there (like Drupal and WordPress), I sometimes wonder why I take the time to "roll my own"...For all of you that subscribe to the feed (what, like 0), you might have noticed that it hasn't been updated lately. That's because I wrote some stuff to put by blogs in a database (PostgreSQL! - overkill is good!), but I'm just now finishing it so that the feed gets updated.So ...

Scripting! 2006-06-12

I imagine that anybody who actually likes programming is familiar with the many popular scripting languages in use today. Of course, a lot of web devs and sysadmins have been using languages like php, perl, and python for ages, but if you read any tech news (like /.), you'll know that the newest craze is ruby. I've played with it a little, and I can actually see what the hype is all about... It's a neat language, and ...

Google Knows Me!! 2006-06-07

Yesterday I discovered that Google knows who I am! This is surprising to me since, for several years, this site has never been displayed when searching for Brad Montgomery! I have a Page Rank of 2! Apparently, I'm currently the 3rd most popular Brad Montgomery, right after Brad Montgomery - The motivational Speaker and his blog (Both have a Page Rank of 4), and Brad Montgomery - The Actor. Surprisingly enough, Brad Montgomery - The Actor, only has a Page Rank of ...

OpenLaszlo 2006-05-10

Wow... the Net never ceases to amaze me. I've been a fan of Pandora.com for a while, but I never realized they were using OpenLaszlo! So, after a skimming over the OpenLaszlo site, I ran across a link to Gliffy.com which bascially allows you to draw diagrams in your browser. Sweet!