Note: some example scripts can be found in this repository.
Python is a flexible language, suitable for fast development and prototyping of web applications. We use the PyDev plugin in Eclipse for Xierpa development, a web environment built around a simple Twisted server.
A useful trick when initializing an object that inherits from a parent object, is to pass along some initial settings:
def __init__(self, path=None, fontpath=None, licensepath=None, xslpath=None):
super(MasterBook, self).__init__(path=path, fontpath=fontpath,
where the parent looks like this:
class Composer(ImagingConstants, Constants, NodeStack, Super):
def __init__(self, path=None, format=None, width=None, height=None, unitsperem=None,
zoom=None, toporigin=True, quality=None, backgroundcolor=None, user=None,
styles=None, autopage=True, style=None, fontpath=None, licensepath=None,
# do the rest of the initializing here.
All libraries are stored in the site-packages folder. Depending on OS and version, its location can differ. Here’s a one-liner to find it:
python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
On the shell, create a new virtual environment:
(`apt-get install python-virtualenv` first needed)
Then install in that virtual environment all the requirements:
pip -E . install -r requirements.txt
You can now work inside this virtual environment like so:
And exit with
There are several ways to find out more information about the installed libraries. See which one works best.
Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import defcon
['Anchor', 'Component', 'Contour', 'Features', 'Font', 'Glyph', 'Groups', 'Info',
'Kerning', 'Lib', 'Point', 'UnicodeData', '__builtins__', '__doc__', '__file__',
'__name__', '__package__', '__path__', 'addRepresentationFactory', 'objects',
'removeRepresentationFactory', 'tools', 'version']
>>> print defcon.version
>>> print defcon.__path__
The Processing environment was originally developed by Casey Reas and Ben Fry at MIT and is written in Java. It is ideally suited for generative audiovisual work and infographics. Processing provides an interface for inexperienced non-techical users. However, the main, non-GUI functionality consists of a set of libraries. In Java, a language designed as being strictly object-oriented, everything is a package or a subpackage. Therefore, it is relatively easy to import the Processing core and Processing-specific libraries into a regular Java IDE, such as Eclipse. By downloading my code into a separate workspace, I can easily switch between workspaces containing Python projects and the workspace containing my Processing-based generative and infographics work.
The code that I’m developing is stored at GitHub. There is an official page for running GitHub projects in Eclipse (you need to scroll down a bit).
Especially for Python, many libraries actually wrap deeper-lying C/C++ code. On Linux-based systems, which generally come with a package manager of some sort, this can be relatively pain-free. However, on a newish Mac, this can mean that you need to be able to compile all sorts of dependencies, which can cause conflicts because architecture register sizes (32 vs. 64 bit); you need to choose one or more of the following options:
- Power PC (
- Intel 32 bit (
-arch i386) or
- Intel 64 (
-arch x86_64) bit.
Larger libraries, such as the PIL Imaging library, can have many dependencies, including those for JPEG and PNG encoding and reading and writing of several font formats such as OpenType and TrueType.
otool -L site-packages/PIL/_imaging.so
sudo env ARCHFLAGS="-arch x86_64 -arch i386" python setup.py install
sudo port upgrade --enforce-variants libxml2 +universal
sudo port install libxml2 +universal
Command Line Tips & Tricks
Over the years, an experienced programmer will develop certain techniques to do his job faster and more painless. Once you get yourself comfortable with the command line or shell, it will give you all sorts of benefits. Shell scripts, for example, are small programs that can make use of all the file system commands that are available and can make use of conditional statements and loops. There are also some commonly used commands that can give you limited control. I’ve been documenting some tricks I’ve been using a lot for a long time as a reminder for myself. Previous incarnations of this site contained information on all sorts of audiovisual stuff, but since I’ve moved on to more professional applications thanks my current position at a design studio, I stripped down the list to the bare essentials. I decided to write a little bit more of a in depth explanation of why these commands are useful to me. The find command, for example, will return all files below a certain current position in the file system tree:
The dot isn’t needed on Linux-based systems, however on OSX you need to provide a path explicitely even for the current folder position. An extra delete option will simply delete all files that correspond to a certain name pattern. Removing Finder metadata using find delete can be done like this:
Another way is to pass on the results to the standard remove command, using so-called back ticks. So if you want to remove all subversion folders recursively from a branch:
rm -rf `find . -name .svn`
To remove the dot files on OSX, use
The disk usage command is perfect for finding out where the big files are located. I use this version to sort files in a human readable way:
If you need to know how much space is left on the device, use this command:
which will return something like this
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 7.9G 1.7G 6.2G 22% /
tmpfs 302M 0 302M 0% /dev/shm
Git is the version control system of choice nowadays. I’m collecting some useful shortcuts and one-line commands that are tricky to remember. For example, here’s how to set global ignores in Git:
git config --global core.excludesfile ignore-files.txt
Removing old Git branches is simple if you know how. If you have it checked out locally, do:
Then, delete the remote branch.
I’ll add some more tips and tricks on grep, cronjobs and bash scripts soon!
Compresssion & Conversion
For compression of and conversion between audiovisual sources, command line tools can often be of help. mplayer and it’s encoding/decoding counterpart mencoder are basically your Swiss army knife of compression and conversion. For example, the basic command for retrieving audio from a video fragment looks like this:
mplayer -vo null -ao pcm:file=.wav
They are available from the MacPorts repositories.
Ripping audio from your DVD’s usually gives you good quality samples. Here’s how you do it:
mplayer -ao pcm:file=powaquatsi.wav dvd://2 -chapter 14 -alang eng
where the value behind dvd:// should load the title of the main DVD feature. Often, some trial and error is needed to find the correct index for the feature. Leaving the chapter part away grabs the entire fragment.
To convert a folder containing a VIDEO_TS DVD structure to a burnable ISO file, OS X comes with a neat command line tool:
hdiutil makehybrid -udf-volume-name -o .iso <folder-containing-VIDEO_TS>
An SSH tunnel:
ssh email@example.com -N -f -L 3689:pulse.defekt.nl:3689
pg_dump waste -f waste.sql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.58 MySQL Community Server (GPL)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
mysql> create database cellar;
Importing backup file:
mysql cellar -uroot < cellar.sql
To a distant db server:
mysql -h host.address.for.rds.server -u rdsusername -p rdsdatabase < backupfile.sql
Dumping a database:
mysqldump -u root -p sukhatada > sukhatada.sql
java -Xms128m -Xmx512m -server -DGEOSERVER_DATA_DIR=/opt/geoserver/data_dir -Djava.awt.headless=true -jar start.jar
Adding a user as a superuser:
adding a user to a group:
Seeing if the user has been added:
Changing permissions so everyone that’s part of the group is allowed to edit files:
chgrp -R *
chmod -R 755 *