Skip to content


Using a Test Database in Django

As I mentioned in my previous post, we’re using MySQL on our development machines. It has several advantages, but one of the drawbacks is unittests run slower when not using Sqlite (big ups to MockSoul for posting his benchmarks). The reason for this is when running unittests in Django with a Sqlite database, the database is run in memory (RAM) instead of being written to the disk.

Django only allows you to specify one database, and although a new database is created for unittests, it still uses most of the same settings (auto prepending “test_” to the database name), which means a Django install using MySQL also uses MySQL for unittests.

To get around this problem, I created a file in my project root called test_settings.py containing the following lines:

I then opened my settings.py, imported sys, and inserted the following lines at the end of the file:

If one of the command line arguments is “test”, that means a unittest is being run, in which case Django will attempt to import test_settings.py, which will override the database settings and use Sqlite instead. Migrations won’t be an issue, since Django South uses the old syncdb command for generating databases for unittests.

Hope this helps you save some time testing.

Posted in Web Design & Development.

Tagged with , , , , , .


Cross Database Incompatibility Using Django South

When our team (at Govnex) started using South Migrations we encountered a cross-database compatibility issue. I was using MySQL on my local machine for its performance and so I could browse the database using phpMyAdmin, while our other members were using Sqlite on their local machines. The problem we encountered was migrations that worked my machine running MySQL were failing on their machines running Sqlite. We discovered the cause was some NOT NULL fields in our models which didn’t have defaults defined; the NOT NULL fields with no defaults were working fine in Sqlite when created using syncdb, so apparently it’s only when updating a table in Sqlite that they require defaults (this a caveat of Sqlite, not Django South).

Our immediate solution was to add default values to the necessary fields. However, in the end we decided to switch to MySQL on our development machines in order to ensure no future issues arise that might prevent our development code from working on our production server, which also runs MySQL. Hope this helps anyone who might be having the same issue.

Posted in Web Design & Development.

Tagged with , , , , , , , .


Web Dev Bash Utils

I’ve just open sourced these bash scripts I wrote for web development. They’re available on GitHub.

Unfortunately they were written for use on a strict Unix environment with an outdated version of bash and without the benefit of GNU extensions (I was not the administrator), so they don’t currently work on Linux. My next step is to port them to Linux, and any help would be appreciated.

Posted in Web Dev Bash Utils.

Tagged with , , , , , , .


Does the Brain Like E-Books?

“Does the Brain Like E-Books?”, NY Times

Due to the distractions and time constraints on the Internet, I wonder if publishing is going to change in a way that it would be just as attention grabbing if it were on a computer. I don’t think it would constitute an appeasement to digital consumers, but simply attention to usability concerns. Usability is something that’s thought a lot about in web design in order to make sure the content is accessible to a wide audience, but I don’t think the same care has been put into books. With books it’s up to the reader to self-motivate and finish several hundred pages, and it’s expected that the people reading the book are people who like reading a lot and have the time to do so. On the web, content tends to be optimized to hold the reader’s attention, since statistics show they’ll only hang around for 3 minutes. If it does change, this could be yet another way new technology will make information more accessible to under-served audiences.

Posted in Web Design & Development.

Tagged with , , , .


Whitespace Management: Use Tabs, Spaces Considered Harmful

At one of my previous jobs I worked on dozens of websites that had been created by other people. I prefer to use tabs instead of spaces when indenting code, and I can get a little OCD sometimes, so every time I edited a file I would do a search and replace to change every 4 spaces to a tab character. I didn’t like the idea of having some files use spaces while others used tabs, so when I wrote a bash script for recursively searching and replacing inside text files throughout an entire directory structure, I added some code that would clean up the white space as well. The actions it performed were:

  • Converting from Windows (“\r\n”) or Mac (“\r” on older versions) end of line encodings to Unix style encodings (just “\n”)
  • Removing trailing whitespace from the end of lines
  • Condensing multiple blank lines to single blank lines
  • And most importantly, converting every 4 spaces to a tab character

I had anticipated that this would save some disk space, but I was surprised by how much; after running the bash script, the total size of each website would decrease by 10-50% (that’s not a typo, fifty), and that’s including binary files such as images and PDFs which were unchanged. Think about the impact that has. Every individual whitespace character takes up 1 byte, bytes which have to be stored on disk, loaded into memory, transferred over a network, loaded into the client’s memory, and iterated past when it gets processed by the browser. Whitespace management saves:

  • Disk Space
  • RAM
  • Processing Power
  • Bandwidth

which in turn helps save:

  • Money
  • Electricity
  • the Environment

It also helps you provide a better user experience. When browsing the Internet, I’d much rather download a 5KB HTML file than a 10KB one, since it’ll download faster and render faster.
(On a side note, generally these are all also benefits of writing standards compliant, semantic XHTML with external CSS and JS.)

Another reason I prefer tabs to spaces is, when browsing code it’s easier to tell if the proper levels of indentation are being used. If there’s one space missing or one additional space it can sometimes be hard to tell, but if a tab character is missing it’s very obvious. Also, most text editors allow you to specify how wide a tab character should be displayed, so if one developer likes 8 space indentation width, another likes 4 spaces, and another likes 2 spaces, they can all use the same code containing tabs and configure their respective editors to display the tab character at their preferred width. If you were to use 4 space characters for each indentation level, the developers who like 8 and 2 spaces are forced to use it as well.

Posted in Web Design & Development.

Tagged with , , , , .


Survey of Best Programming Practices

I was having a talk today with some colleagues about the scarcity of web developers, and even software engineers, who use best practices such as:

  • using version control
  • using a bug tracker
  • writing unit tests
  • using a programming framework

In all honesty, I didn’t do any of these before my current job at Govnex (aside from a little dabbling with CakePHP), nobody at my first 2 web development jobs did any of these, and we didn’t learn about any of this stuff in college. As far as I know, nobody I knew at RIT followed these practices except for maybe using a framework. Of all the job descriptions I’ve read in the past few years, only a handful mentioned using a framework, and only a couple mentioned anything about unit tests or version control; none of them mentioned the use of bug tracking software. One of my colleagues said that these practices are common among all developers, while my other colleague agreed with me that they’re hard to find.

What do you think? I’ve created a 6 question Google Apps form for collecting survey data and made the results public, it would be a big help if you could fill it out. Afterwards, please share your comments below.

Posted in Web Design & Development.

Tagged with , , , , , , .


Just Moved to RackSpace Cloud Servers

Sorry for the down time, I just moved to RackSpace and got everything up and running.

I had some problems migrating WordPress and getting it working, which stemmed from the fact that it was using too much memory. I ended up doing a fresh install of WordPress with a fresh installation of each plugin I wanted to keep, but on some pages I still occasionally got an error saying too much memory was being allocated. After some searching I discovered that the “measly” 32MB max. memory allocation in my php.ini wasn’t enough for the latest version of WP, and I had to up it to 48MB. I honestly don’t think I’ve ever encountered this error before.

Over time I’ve noticed as WordPress has become heavier and more resource intensive, and I have a feeling that the plugin mechanism is slower than built-in functionality would be. I think WordPress is a great tool and it’s fantastic that it can (usually) be set up in 5 minutes, even by novice users. However, I’d like something more customized and with better performance, so once I have some spare time I think I’ll redevelop my blog using Django.

Anyways, in the next few days I’ll start to rebrand my site and add more community features, including project repositories and bug tracking. This should make it easier for users to report bugs for the Color Management Firefox Add-on, contribute code and add translations.

Posted in Site Updates, Web Design & Development.


Color Management 0.5.1 Add-on Released

This release just fixes a few bugs.

Download Color Management 0.5.1.

Posted in Color Management.

Tagged with , , , .


Color Management 0.5 Add-on Released

Sorry for the long delay everyone, I’ve been really busy at my new job. In about a month I plan on changing my website from a personal blog to an open source community, so hopefully I’ll get some volunteers to help out with development.

I’ve been having some problems with the Firefox Add-ons Site, so for now this will only be available here. Some new features are:

  • Changed target application to XUL 1.9.1, so it should work with any XUL 1.9.1 based app, including:
    • Firefox 3.5
    • Thunderbird 3
    • SeaMonkey 2.0
  • Updated for new options in XUL 1.9.1
  • Choose profile dialog now defaults to OS specific color profile folder on Windows, Mac, and Linux.

Color Management 0.5 Add-on

Posted in Color Management.

Tagged with , , , .


DreamHost Account Upgrade

So, DreamHost is upgrading their infrastructure, to go green and save money. During this process there could be technical difficulties, so as a reward to customers who take a risk and volunteer to be migrated first they’re offering unlimited disk space and bandwidth for free, forever! I volunteered, and not only do I now have unlimited storage and bandwidth, but it turns out my account was already moved over, so I essentially got it for doing nothing. If you have a DreamHost account, it might be worth volunteering.

Posted in Site Updates.

Tagged with , , , .