Skip to content

{ Monthly Archives } January 2008

Alphanumeric sorting

Ned Batchelder (the author of the coverage.py module) has a succinct alphanumeric sort:
import re

def tryint(s):
try:
return int(s)
except:
return s

def alphanum_key(s):
“”" Turn a string into a list of string and [...]

Create a Debian package from your Python application

This post describes in enough detail how to package your Python application in a Debian package.

Creating Scientific/Engineering Graphs

Asymptote is a powerful command driven graph generator. It produces elegant graphs such as that shown below:

The code required to generate this graph is:
import graph;
size(4inches,0);

real f1(real x) {return (1+x^2);}
real f2(real x) {return (4-x);}

xaxis(“$x$”,LeftTicks,Arrow);
yaxis(“$y$”,RightTicks,Arrow);

draw(“$y=1+x^2$”,graph(f1,-2,1));
dot((1,f1(1)),UnFill);

draw(“$y=4-x$”,graph(f2,1,5),LeftSide,red,Arrow);
dot((1,f2(1)),red);

Typesetting equations in a WordPress blog

The MimeTex plugin enables the typesetting of complex mathematical formulas using the TeX syntax. The quadratic equation:

is inserted in the post as:
<tex>x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}</tex>