Programming Pearls: Phone Directory

I recently started reading the book Programming Pearls. It walks through several situations in software development which had interesting solutions. The solutions generally required a bit more thought about a problem than a person might initially give it, but were far simpler to write and/or more efficient than the first solution most people would think of as well.

This also includes exercises after each section which reinforce some of the concepts and ways of thinking used to solve the initial problem. I intend to do some of these and occasionally post my answers. The book used C++ and I may …

→ read more

Django / Nginx / uWSGI / Supervisor On Debian

So I've moved my stuff over to Rackspace and have pulled Apache out of the mix. I'm now running Django behind Nginx and uWSGI in a virtualenv with Supervisor. It was more work than I expected and most of the instructions out there I didn't find to be very helpful because they expect you to be setting things up exactly how the author of those instructions does it, so here's my own little bit of info on how to do this. I run Debian, so the specifics I provide here will be for Debian (and Ubuntu and I'd guess Mint). …

→ read more

The Redesign Continues

Today I decided to do a little bit more to make this site look just a touch nicer. Rather than relying on doing everything myself, I decided to pull in bootstrap which the people at Twitter have been nice enough to provide. It allowed me to strip out some of my own css, add the little older and newer buttons down at the bottom of the main page, and provides a whole lot of functionality that I haven't used yet... fancy drop down menus, a menu bar, pop-up alerts, progress bars, and more.

I did find getting started a little …

→ read more

Partial Indexes With Django

My previous post about extending Django's model validation led to a new requirement, partial unique indexes. The extended validation works, but there's still a race condition between validation and saving, so you can validate that the current values don't violate the unique constraint and then another object can come in and get saved before your current object. To keep this from causing a problem, the uniqueness needs to also be enforced at the database level.

Fortunately, Postgresql has partial indexes and partial unique indexes, specifically, which solve this problem if you're using postgres. Unfortunately, Django does not support these directly. …

→ read more

Extending Django's Model Validation

Today I found myself in need of extending the way Django does model validation. What I needed was a partial unique index. Unfortunately Django doesn't have support for that built in. What I ended up doing was overriding my model's validate_unique() method. This wasn't terribly difficult, but did have some complications due to a bug in django.core.exceptions.ValidationError or unclear documentation. The examples in the documentation only show ValidationError being raised with a string passed into it.

The problem that with this is that part of the code for ValidationError assumes that you did not pass in a string but …

→ read more

Comparison Of mod_wsgi And mod_fastcgi

I've recently been trying to improve my Django setup to make it more stable and easier to maintain. Part of this has been experimenting with protocols and modules for Django to interface with Apache.

For awhile I've been running Django using FastCGI with Apache's mod_fastcgi. There are several good things about using mod_fastcgi and one annoying disadvantage. What I really like is how easy it is to go this route while using virtualenv. You just activate your virtualenv and then start up the Django FastCGI server with runfcgi port=<yourport> and away you go (after proper configuration of Apache, …

→ read more

From MySQL to PostgreSQL

I've finally made the switch from MySQL to PostgreSQL. This is something that I've been meaning to do for awhile, but MySQL did what I needed, I was using it at work and so knowing more about it was useful, and I was just used to it and comfortable with it. I've recently changed jobs and the new place uses postgres. Since I've also been working with Django and the Django guys also recommend postgres, now seemed like a good time to switch.

One thing that always comes up when discussing mysql and postgres is a bunch of people claiming …

→ read more

A Realization

While trying to come up with my next project it just really hit me that I really enjoy doing more back end, library type work. My two most recent projects, both of which I really enjoyed working on, were an OAuth library and an app for Django which has no UI elements.

Most of my applications that do have a UI get a minimal one. My Android XMPP chat client just has white text on a black background and ListViews, this website's layout and colors are simple and pretty terrible, and my other Android apps have really simple, unimpressive UIs. …

→ read more

Things Learned During The Redesign

While I've been working on changing the site around I've gotten to learn a few more things about Django. The biggest change is behind the scenes in the form of a taxonomy app. The first page to use this is the projects page and it can easily be used for any other similar pages, tagging, or any other categorization I might need.

I got to work with Django's contenttypes framework, which provides some really useful features. With the contenttypes framework you can create generic relations, which behave like a foreign key (sort of... it's more difficult to work …

→ read more

Redesign Progress

As you can see, if you've visited before, the redesign has made progress. The nav is now on the upper right and the list of projects are on their own page (which needs some work to look nicer). It's very subtle, but the nav links do a cool little color change deal when you hover over them now (It's not much, but my UI skills are sorely lacking). I may make that stand out a bit more. I also fixed some font-family nonsense that caused some really dumb looking fonts to be used with Internet Explorer.

Next up will be …

→ read more

Site Redesign and Other Stuff

I'm thinking about a minor redesign of the site. Rather than having the menu on the left, I'm thinking about just having links to "Home" (or "blog"?), "Projects", "RSS", a new "About", and possibly a new "Tutorials" section somewhere around the top of the page. The projects page would then have a page with a list of projects, the rest would behave basically as is. This would create a somewhat cleaner layout and give me more room to work with to add other interesting or useful stuff like links to tweet, etc.

The other big news is I got a …

→ read more

Scala OAuth Works!

My Scala OAuth client more or less works now. I have sent HMAC-SHA1 and Plaintext signed token and access requests to both Twitter and Yahoo APIs using both GET and POST. I have also sent tweets to twitter, received my timeline, etc.

My primary goal was for a very simple to use library rather than one that does everything. I think I've more or less accomplished that. Only two objects are needed, one for the initial token request and access request and then the second for making signed requests. Currently only POST and GET are supported and only text/string responses. …

→ read more

Django Syndication Framework

I've been looking for more to do with Django. I took a look at some of the common additional addons for Django and decided to use the syndication framework to add an RSS feed of the latest posts.

This basic usage was pretty simple to get up and running. It required adding one simple class which inherits from django.contrib.syndication.views.Feed, which I put in a new file, and of course adding a line to

from django.contrib.syndication.views import Feed
from cms.models import *

class BlogFeedRss(Feed):
    """RSS feed of latest posts"""
    title = "Bash-Shell.Net Posts"
    link = …
→ read more

Implementing OAuth In Scala

So I really liked Scala when I worked with it in the Seven Languages book. I've also been meaning to write an OAuth library for some time. I decided that this would be an interesting first project in Scala. It's not overly complex, but not so simple that I won't learn anything either.

So far I've written just enough to make the first request for a request_token from an OAuth provider. I used traits, treating them more or less like a Java abstract class, to create classes to sign the messages using HMAC-SHA1 or plaintext methods and will be adding …

→ read more

Seven Languages in Seven Weeks Wrap-Up

So I'm done with Seven Languages aside from maybe going back to do some of the exercises that gave me trouble at some point. I really enjoyed working my way through this book, even when it occasionally got frustrating. I've always been a firm believer that being familiar with more languages, styles, and paradigms will make you a stronger programmer, even if you don't use most of them often (or ever) after getting the base knowledge. I believe it gives you more ideas for how to solve problems and a better understanding of how things work. I highly recommend this …

→ read more