Skip to content

{ Category Archives } Uncategorized

Anagrams and python

Over at stealthcopter.com, the author has a very succinct anagram finder.
Some of the anagrams found are rather humorous:
salesmen lameness nameless maleness
lameness – A salesman is lame if they miss their quota?
nameless – A sales manager doesn’t care what the salesman’s name is, as long as they make their quota (and thus hers/his)
maleness – less [...]

Extracting the boundary of a 2D graph

Given a 2D finite element mesh, we wish to determine the boundary nodes and edges using simple graph operations.
Using networkx, the following code builds the graph and then extracts the boundary edges:

import networkx as nx
#Use a MultiGraph to allow parallel edges
G = nx.MultiGraph()
#Each element is a cycle
G.add_edges_from([(1,2),(2,6),(6,5),(5,1)])
G.add_edges_from([(2,3),(3,7),(7,6),(6,2)])
G.add_edges_from([(3,4),(4,8),(8,7),(7,3)])
G.add_edges_from([(5,6),(6,10),(10,9),(9,5)])
G.add_edges_from([(6,7),(7,11),(11,10),(10,6)])
G.add_edges_from([(7,8),(8,12),(12,11),(11,7)])
# Create a boundary graph
G_boundary = nx.Graph()
for v1,v2 [...]

Encrypting your dropbox folder

If you are a dropbox user, you may have some concern about uploading and backing up your data in the cloud. This post describes in sufficient detail how to encrypt your dropbox folder using encfs on (at least) ubuntu.

Regular expressions

How “Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby, …)”

A simple script to rename jpg files based on date

As anyone with a digital camera knows, you can generate a lot of files in a very short time from all of your photos. Since almost everyone in my household has a digital camera, that represents a lot of files, haphazardly scattered over many directories.
I’ve looked around quite a bit and found many utilities that [...]

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 [...]

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>

Consultingware

Joel Spolsky has a good description of what happens when expectations do not match delivery:

Custom development is that murky world where a customer tells you what to build, and you say, “are you sure?” and they say yes, and you make an absolutely beautiful spec, and say, “is this what you want?” and they say [...]

Building scipy for SUSE 9.3 x86_64

I was surprised to find that neither numpy nor scipy was available for SUSE 9.3 x86_64 via YAST (yes, 9.3 is way old but when everything is working just fine, I’m not screwing things up by upgrading). So I attempt (and eventually succeed) to build these two packages.
Pre-requisites:

Scipy
Numpy
BLAS/LAPACK (I used the ATLAS library)
Fortran compiler (I [...]