All posts for the month August, 2012

Notes for myself so I can do this again someday… (UPDATE: I had to refresh the links at the bottom of this article to the latest version of Django. Good luck.)

Let’s say we are working on a Django project called applesauce, for lack of a better name. We start by creating a directory for this project:
cd ~
mkdir applesauce
cd applesauce

We use pip to install python packages, so we must install it first:
sudo apt-get install python-pip python-setuptools

We use virtualenv to manage our python environment to make sure we don’t go too crazy. We can use pip to install it:
sudo pip install virtualenv

virtualenv has this idea of using a directory to store its settings, so let’s make one for it, and use it as a new virtual environment:
mkdir applesauce-virtualenv
virtualenv applesauce-virtualenv

The –no-site-packages is the default now, so we don’t include it here (you could, but it’s deprecated). This helps keep things sane.

virtualenv creates a shell script for you to source that sets up the necessary environment variables. You will need to source this file every time you want to work on this project:

source applesauce-virtualenv/bin/activate

You should see that your shell prompt has changed, and now has “(applesauce-virtualenv)” at the front of the prompt. This lets you know that you have already “logged in” to your virtualenv.

Now, let’s install some of the packages required to work with Django. We start with the non-python system-wide packages and libraries:
sudo apt-get install libxml2-dev libxslt1-dev python2.7-dev libpng12-dev libfreetype6-dev build-essential python-dev

Then, make sure that you are in your virtual environment and install these python things using pip. Since we’re installing these packages into the virtualenv we don’t need to use sudo.

pip install django django-debug-toolbar south httplib2 lxml

If you have any modules/packages that you want to be able to use in your Django project, you can copy them into applesauce-virtualenv/lib/python2.7/site-packages/

To verify that Django can be seen by Python, type python from your shell. Then at the Python prompt, try to import Django:

>>> import django
>>> print django.get_version()

Now, you can start working with Django. You might want to start with the official tutorial, Writing your first Django app.

(Some information taken from the Django Quick install guide.)

I work at a desk all day and enjoy listening to music while I work. I also occasionally play video games where it’s nice to have a microphone for the team chat. I don’t really like ear buds since they make my ears hurt, and the “on-ear” headphones that just press on your ears also hurt after a while. I never thought of myself as the “big headphones” guy, but on the suggestion of a friend I bought a pair of Koss SB49 headphones (not an affiliate link).

Koss SB49 headphones

They are the first pair of headphones I’ve tried that are actually comfortable enough to wear all day long. The cups are large enough to fit around my entire ear, so they only rest against my head, not pressing on my ears. The sound quality is most excellent (especially good bass response which is normally reduced on most headphones) and the microphone quality is top-notch too. Comes with a small volume adjust slider, and the cable has two plugs, one for the microphone and one for the speakers. It would be really nice to find an adapter cable to let me use this headphone+mic with a cellphone. Update! I’ve since found a great adapter cable to adapt these (and similar) computer headphones to use the TRRS plug needed by a cell phone’s external headset jack. This adapter is $16 on and has Prime shipping, and has worked very well for me on my MyTouch 4G Slide phone.

When reviewing and editing papers, my advisor likes to use his copy of Adobe Acrobat to mark-up the insertions, deletions, and add comments to the original PDF. This works nicely, but when overlapping comments are present, such as a block comment over an entire paragraph with sentence-specific edits “underneath” the block comment, none of the “standard” PDF viewers on Linux (including the official Adobe Reader for Linux) are able to access the buried mark-up. Fortunately, I have discovered that a freeware program called PDF XChange Viewer can be easily run using WINE, and allows you to view, edit, and create PDF annotations. I haven’t tried creating or editing annotations, but I certainly do use it to delete block annotations covering up the more specific edits.

via Finally, real PDF annotating under Linux! (with help from Wine)

set backupcopy=yes
set softtabstop=4
set autoindent
syn on
set cindent
set shiftwidth=4
set shiftround
set expandtab
set formatoptions=t
set textwidth=0
set mouse=a
set bg=dark
map <f5> :set hls!<bar>set hls?<CR>
map <f6> :set paste!<bar>set paste?<CR>

Auto indent and auto syntax highlighting. I use a black background terminal, so the “set bg=dark” optimizes the colors for a dark background. I like 4 spaces for my indenting, no tabs. I use the F5 key to toggle search result highlighting, and F6 to toggle between paste mode (no auto-indent) and no-paste mode.

If you’ve ever uploaded a folder full of images to your web server, seeing the directory listing of all the filenames is less than ideal, as you can’t preview any of the images without clicking through on them. Here is a quick one-liner to generate an index HTML page for all the images:

for i in *.jpg; do echo "<img src=\"$i\" width=\"640\" /><br />" >> index.html; done

Unfortunately, that will cause your browser to load up the full-size version of every image into RAM. If you’ve got a lot of photos, especially if they are very large files straight from your DSLR, you’ll probably start swapping. To fix this, we first use the mogrify command from the ImageMagick suite to generate thumbnails from all your images. Here, we assume that your source images are all in JPEG format, so we can easily use identically-named PNG files for our thumbnails:

mogrify -format png -thumbnail 640 *.jpg

Then, we can use a slightly-modified version of the loop above to generate the HTML:

for i in *.jpg; do BASE="`basename "$i" .jpg`"; echo "<a href=\"$i\"><img src=\"$BASE.png\" /></a><br /><br />" >> index.html; done

Adjust the size of the images by changing the “640” above to whatever image width you like.