Python Unicode Gotcha

I was peer reviewing a bug fix for some code at work the other day and learned something about Python and encoded Unicode. It makes sense now, but when I first saw the fix my initial thought was that there's no way that's what is going wrong. It turns out that once you've encoded a Unicode string, perhaps to utf8, you can chop off just part of the bytes of a single Unicode character using string slices.

>>> u = u'A string with some random unicode \u0200 \u0202. There it is.'
>>> u
u'A string with some random …
→ read more

Djukebox Gets Handlebars and a REST API

I recently reworked the Djukebox UI. It's still ugly, but it uses way cooler things behind the scenes. The original incarnation had a main page which housed the player, a hidden iframe for uploading new tracks while letting the user continue browsing and listening, and another iframe for the current page content so that the player could keep playing while the user clicks around through lists of tracks and albums.

It worked pretty smoothly, but it's not cool and new. This is an old, hacky way of doing things. The point of Djukebox is to be a playground to do …

→ read more

Control Panel Development Is Underway

I have begun work on a new control panel app for the CMS used for I got to learn a little about how django.contrib.admin works since I dug into its code to see how the dynamic urlconf creation happens and how model registration is handled. For bscontrolpanel entire views are registered rather than single models. This can be a bit more work, but it allows for streamlined, user friendly control panel views to be built, housed with the app they belong to, but appear dynamically in the control panel and all live under a common base url path such …

→ read more

A New Look and Reworked Back End

The site has a new look. I completely scrapped the old html and css and started from scratch. I'm terrible with picking colors so I used a bootstrap them from BootSwatch and then went to work on the layout. I made changes to the back end to hopefully let me expand this more as time goes on. The blog section is now one app while the projects are their own app rather than being hacked into the blog stuff. I'm hoping to find time to take the projects section and tie into github and bitbucket APIs, add file attachments for …

→ read more

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