Keyboards

I've tried out a number of keyboards in the past year in an attempt to move away from my beloved, but aging, Microsoft Natural Ergonomic Keyboard 4000 and wanted to put my reviews of them up for anyone looking for an overview of the ones I tried. A few years back, I developed a small case of carpal tunnel and knew I had to change some of my habits before it got worse - these kind of problems don't go away on their own! At the time, I was using a second generation Apple wireless keyboard with those chiclet-style keys. I loved it and used it for a few years before the pain started up, and then I had to give it up as it wasn't the most ergonomic keyboard out there. A friend of mine recommended to try the Microsoft Natural Ergonomic Keyboard 4000 and after reading a quick review online, I purchased one. It took a few hours of getting used to it, but I quickly fell in love with it. The keyboard itself is not eye candy by any means, but it got the job done and best yet, it helped ease the pain in my wrists with the more "natural" positioning of the hands. With its split keyboard layout, cushioned wrist rests built right into it, and a nominal price tag, this easily become my main keyboard. Here's my quick breakdown of the MS Natural 4000:

Microsoft Natural Ergonomic Keyboard 4000 (*stock photo)

Microsoft Natural Ergonomic Keyboard 4000

The next keyboard I tried out was a Das Ultimate S and it was my first experience with a keyboard that had real switches. I got mine with MX Blue switches and they lived up to the hype - man, were they loud! You got a really satisfying feeling when hitting each key and the tactile feel really made for a good combo. In the end, I ended up parting ways with it as it was a bit too loud for my wife since we lived in a one bedroom apartment together in NYC and the clickity-clack would interrupt her shows.

Das Ultimate S (*stock photo)

Das Ultimate S

The next keyboard on my list was the Kinesis Maxim. I've heard good things about Kinesis from other developers and decided to give them a try. I opted for the Maxim as it was one that was closest to the Microsoft 4000 I was used to using, with a split keyboard layout. I ended up not liking it for one particular reason - the alt key on the left side was smaller than a normal keyboard's, which made hitting it (Command key for you Mac guys) a bit difficult. As an Emacs user, I found this even more annoying as this led to lots of simple errors.

Kinesis Maxim (*stock photo)

Kinesis Maxim

Microsoft came out with a new ergonomic keyboard recently I was pretty excited to give it a try, being how much I liked their previous ergonomic keyboard. The Microsoft Sculpt Ergonomic came out with a bit higher price tag than the MS 4000, a little more than 2x the cost to be accurate, but I still gave it a shot. It felt pretty natural to me for the split layout and they added a few other things to make it more "up-to-date".

Microsoft Sculpt Ergonomic

Microsoft Sculpt Ergonomic

I used the Sculpt for quite a few months, until I started to miss real switches, thus prompted my keyboard switch yet again. This time I went back to a familiar brand, Kinesis, but tried the Advantage series at recommendation from one of my friends, Wraithan. It was definitely a unique keyboard with a hefty price tag. Unfortunately, it didn't last more than a week in my possession as I found the learning curve a bit too much to overcome. I'm not a super fast typer, but my speeds range in the 70-80 WPM range with a regular layout keyboard. Using the Advantage, I was down to 30-40 WPM with about 1-2 errors.

Kinesis Advantage

Kinesis Advantage Full
Kinesis Advantage Left Side
Kinesis Advantage Right Side

Finally, this brought me to try out the Happy Hacking Professional 2. What I liked most about this was that the control key was already mapped to the caps lock, which is something I always re-map on a keyboard I use anyway.

Happy Hacking Professional 2

Happy Hacking Professional 2

In the end, it's a great keyboard all around, but the delete key placement didn't jive with me and is the only reason I am not using this keyboard as my main. Overall, I think I will use this when I travel because of it's small, compact size, but not as my main keyboard. This inevitably brought me to the Realforce 104U keyboard. This is the current one I'm using today and I am loving it. The lack of a split keyboard layout is not something I'm looking for anymore as I learned to help my wrist pains over the years (stretches before day begins, once at lunchtime, and small breaks on the hour to shake out hands.)

Realforce 104U

Realforce 104U

After trying all these keyboards, and consequently going through the return process for most of them, I can happily recommend the Realforce 104U to anyone looking for a professional keyboard with good switches. The variable weighted keys helps me not fatigue as much since the weaker fingers have 35g, stronger fingers have 45g. It's the closest keyboard to a traditional look-and-feel of an old-school IBM keyboard, with no learning curve, but a higher price tag for what you would expect a high-end keyboard. If you don't have the space for a full-sized keyboard, I would recommend a Happy Hacking Professional 2.


Django 1.5 Custom User Example

With Django 1.5, one of the biggest changes introduced was the ability to configure the user model. Anyone who has coded a Django app with a business requirement of adding a birthday field, an arbitrary checkbox to the user registration fields, or even making the signup process email-only with no usernames, knows the awkward feeling of implementing their own custom user and feeling a little less Django-esque when all is said and done. This configurable user model change alone was enough for me to 1) upgrade all my Django sites to 1.5 and to 2) swap out my customer user code for the way it should be done now with the configurable user model.

The Django docs are fantastic. It is one of the most comprehensive and, most important, user-friendly documentations out there for programmers of all skill levels. I highly encourage you to read through the docs first on customizing the user model, but isn't required to understand this walk-through.

If you're anything like me, you sometimes like to skim or even skip the docs altogether, and turn to Google to try and find a solid example online. I found a few, but none of them really seemed to show me a full example of configuring the user model. As a result, I decided to write my own and put it all together in an example Django project to show how I handled the custom user model. Here is the link to the repo on Github.

This is going to be a brief walk-through in running this example codebase. It is opinionated, but (hopefully!) easily understood - so this would enable you to modify this example codebase slightly to fit your business requirements.

Also, this custom user example is inspired from Dr. Russell Keith-Magee's great talk at DjangoCon US 2013 titled "Red User, Blue User, MyUser, auth.User" and should serve as a good example for how you can change the core fields of auth.User.

Please note - this walk-through will assume you have pip and virtualenv installed locally, as we'll be using that to create the environment for the example Django project.

View the source on Github

First, clone the example custom user project and change directory into it:

$ git clone https://github.com/jonathanchu/django-custom-user-example.git
$ cd django-custom-user-example

Then, create your virtual environment. We'll only be installing Django (v1.5.4):

$ mkvirtualenv customuser
(customuser) $ pip install django

After Django is installed, let's run syncdb to create our test DB and first superuser. This is configured out-of-the-box to use SQLite3 for simplicity, but feel free to change to whatever database backend you feel more comfortable with. Create your superuser now and follow the prompts:

(customuser) $ python manage.py syncdb
...
::Follow prompts to create a superuser::

Then we can run runserver to checkout how the custom users in the admin looks:

(customuser) $ python manage.py runserver

And open up your browser to http://127.0.0.1:8000/admin and log in with the superuser you just created. Under "Accounts", you will see our custom "Users" there. Try it out, take it for a spin, create additional users from the admin, change passwords, etc. This all works nicely with our custom user model!

Django Custom User Screenshot

Hopefully this is helpful to some out there looking for a solid example on customizing the User model. Any issues with the codebase, please use the repo's issues tracker on Github. Happy hacking!


Setting Up Deft Mode in Emacs with Org-Mode

I've been a big fan of Notational Velocity for quite a few years now - and more recently, nValt which is a popular fork of Notational Velocity, but with a bit more features. Everyone has their own process when it comes to taking notes, and to each his own, but the one thing that really turned me on to Notational Velocity/nValt is the simplicity and unstructured process of taking and searching for notes. Coupled with Dropbox for seamless syncing, you have yourself a great note taking process that was easy to use and even easier to search. As for mobile, I used Simplenote to view my notes via Dropbox, and it made taking notes during programming meetups or business meetings even easier. Life is good!

However, over the past year, as I found myself coding more and more in my text editor of choice, Emacs - the more I found myself wanting something that didn't seem so disconnected from where I do most of my prose and coding. After a quick search, I found Jason Blevins' great little creation called Deft. To sum it up, Deft is an open source mode for Emacs to view, record, and search for notes in plain text, very much like Notational Velocity/nValt. I highly encourage you to check out Jason's project page for Deft. After trying out Deft, it made me want to switch 100% over to org-mode notes as I really only used org-mode for sporadic notes. Now, I have the power of org-mode with Emacs in a Notational Velocity-like buffer with Deft. The rest of the article will be outlining how I set it up in my Emacs config.

Setting up Deft

First, go grab deft.el and make sure it is available in your Emacs config (i.e. - ~/.emacs/vendor/deft.el path). You can grab it here or get it directly from my Emacs config, which is the original unmodified file.

Once deft.el is on your Emacs load path, you'll need to tell Emacs to use Deft. Put the following anywhere in your config (I like to keep modes separated in it's own modes.el file that gets loaded on initialization):

(require 'deft)

Since I use Org-Mode, I want *.org files to be recognized by the Deft buffer, so let's set the deft-extension to "org". I believe the default file type that Deft will look for is "txt", so omit this part or add in "txt" if you want to use plain text files.

(setq deft-extension "org")

And again, since I'm using org-mode with Deft, let's set the deft-text-mode appropriately to use org-mode:

(setq deft-text-mode 'org-mode)

Next, we need to tell Deft where to find all of my current org-mode files. In my case, I like to keep all my org-mode files in Dropbox, so that path would be ~/Dropbox/org for me. You should change this path to wherever you keep your files.

(setq deft-directory "~/Dropbox/org")

Finally, the last bit of customization is to tell Deft to use the filename as a title. By default, Deft will use the first line of the file as the filename. In my note taking preference, I normally don't lead off a note with the title of the file (it's usually a date like "2013-08-15" if it's a meeting), so I switched on the trigger for this:

(setq deft-use-filename-as-title t)

Putting it all together, and you have this in its entirety:

;; deft
(require 'deft)
(setq deft-extension "org")
(setq deft-directory "~/Dropbox/org")
(setq deft-text-mode 'org-mode)
(setq deft-use-filename-as-title t)

Using Deft

To enter the Deft buffer, simply do:

m-x deft ENTER

And you should see the Deft buffer like so, with all of your org-files (yes, I know - nothing is blurred out...I got nothing to hide :P ):

Deft buffer screenshot

Start typing and you'll see the list of notes filter out the results that do not match, just like Notational Velocity. Hit ENTER to open the note in a new buffer.

Deft filter screenshot

And there you have it! Much appreciation and thanks goes to Jason Blevins for this awesome mode that has effectively streamlined my coding and note-taking all in Emacs!


Org-Mode and MobileOrg Installation and Config

MobileOrg

Intro

Throughout the years, I've flipped back and forth between Org-Mode and applications such as Drafts (iOS), Evernote, Simplenote, and even plain ol' text files (with the Notational Velocity and nValt) for my most basic note-taking needs; however, I've always found myself coming back to Org-Mode in the end for another spin around the block. The one positive thing that kept me coming back to Org-Mode, and perhaps the same thing that Emacs is often criticized for, is the fact that it has a lot of functionality under the hood - almost too much. Org-Mode is a very feature-rich application. For my basic needs, I use Org-Mode primiarly for three things:

Here Comes MobileOrg

When I first learned about MobileOrg, I was really stoked that I would be able to record notes, update TODO statuses, and even just view my org files on the go. Unfortunatley, I found that the basic setup instructions on their website left a few minor things out for someone new to MobileOrg, and this is my attempt to supplement that to help others with the same issues I faced with setup.

Org-Mode Configuration

First off, it should be noted that I'm using Emacs 24 with Org-Mode already baked in. If you're using an earlier version of Emacs that doesn't have Org-Mode by default, please install it according to your own preference (which we won't get into here since there are a few different ways to install Org-Mode).

My root directory for all of my org files is kept in Dropbox in a directory called org:

~/Dropbox/org

I've found that this setup fits my workflow best since I also work off a second laptop at times and would like all my org files to be synced across all machines with as little effort as possible.

MobileOrg Setup

Next, install MobileOrg from the App Store. I chose the path of least resistance and decided to use Dropbox as the source for server config, so when you first open the application, click on the Dropbox option, click to link account, and allow authentication with Dropbox to proceed. It should have created a new directory for you under:

~/Dropbox/Apps/MobileOrg

Emacs Configuration for MobileOrg

You will need a few more lines of code to get this all working with your local org files and MobileOrg. This is my basic config based on the two main directories above that will need to go in your Emacs config:

;; mobileorg settings
(setq org-directory "~/Dropbox/org")
(setq org-mobile-inbox-for-pull "~/Dropbox/org/inbox.org")
(setq org-mobile-directory "~/Dropbox/Apps/MobileOrg")
(setq org-mobile-files '("~/Dropbox/org"))

Finally, from within Emacs - edit any org file located in ~/Dropbox/org/ and save those changes. Then send these changes to MobileOrg to sync up:

M-x org-mobile-push

With any luck, you should be able to go back to MobileOrg on your mobile device and click the refresh button to see your org file(s) all there.

Happy hacking!


Upgrading PostgreSQL 9.0 to 9.1 with pg_upgrade

Recently, I updated all of the packages I have installed via Homebrew and ran into some issues with the PostgreSQL package. I was getting this error:

The data directory was initialized by PostgreSQL version 9.0, which is not compatible with this version 9.1.4

A quick search took me to this page, however the docs left a lot to be desired to say the least. Here's a step-by-step to how I eventually fixed it using pg_upgrade.

First, change directories to your Postgres data directory.

$ cd /usr/local/var

Next, create a new directory for the new data directory.

$ mkdir postgres9

Use initdb to initialize the new Postgres cluster in the new data directory you created above.

$ initdb /usr/local/var/postgres9

Run pg_upgrade with the following arguments:

$ pg_upgrade -d /usr/local/var/postgres/ -D /usr/local/var/postgres9 -b /usr/local/Cellar/postgresql/9.0.4/bin/ -B /usr/local/Cellar/postgresql/9.1.4/bin/ -v

If all goes without error, you can switch the data directories so Postgres will point to the right source.

$ mv postgres postgres9.0.1
$ mv postgres9 postgres

You can delete the script left behind by pg_upgrade:

$ rm delete_old_cluster.sh

I actually had my old Postgres instance running, so I had to stop it before restarting the new one:

$ pg_ctl -D /usr/local/var/postgres9.0.1 stop -m fast

Then I restarted the new Postgres instance:

$ launchctl unload -w homebrew.mxcl.postgresql.plist
$ launchctl load -w homebrew.mxcl.postgresql.plist

And you're done - this should fix the PostgreSQL incompatible data directory issue.