Simulating the Golden Balls game show
In this eposide of Golden Balls, an inspired event takes place: I retold the event at DIKU APL lunch (nice to have a job where game theory is a valid conversation topic), and we had a conversation about it. At…
Difficulty level 2 of 5: Easy
In this eposide of Golden Balls, an inspired event takes place: I retold the event at DIKU APL lunch (nice to have a job where game theory is a valid conversation topic), and we had a conversation about it. At…
If you run ‘ll -l’ sometimes a file has ‘@’ permission. This means that the file has extended attributes. TextMate may extended attributes to a file. Consider a fictional Python file called xxx.py edited with TextMate: View extended attributes: $…
given a (2D) array a, and a smaller (2D) array b, how can you add the smaller array to the bigger array at some offset in numpy? >>> a = zeros((4,4), dtype=int) >>> a array([[0, 0, 0, 0], [0, 0,…
How long does [insert code snippet] take in Python? Find out with the timeit module, in Python since 2.3. Below I time how long it takes to make a list with a 1000 zeros, [0,0,0,…], using different Python code snippets.…
The recommended practice is to have different passwords on different websites. But how do you remember all those passwords without storing them somewhere? The tricks is, you don’t. You remember a single strong password, and use a mechanism to generate…
Note: Since writing this post, I’ve learned about the fileinput module, which turns most of the following into a oneliner: import fileinput for line in fileinput.input(): process(line)
Here is a map application that illustrates very well the different tile schemes used (TMS, QuadTree, Google Maps):
Simple CSV file import You have a CSV file called “data.csv”. It has a header line, and is delimited using “;”. You want to import it into Postgres and a table called “your_table”: Create the database table. Set column-types so…
Assuming a shapefile called myshapefile.shp, a table mytable in schema xyz, in a PostGIS enabled database called mydb on localhost. The table is owned by user dbuser who has password “secret”. Using shp2pgsql shp2pgsql myshapefile -I xyz.mytable > statements.sql psql…
These instructions show how to install pip and virtualevn on a Mac running Snow Leopard 10.6.8 and using Python 2.7. I used this to install Django 1.3.1 (installation instructions included). Installing pip (skip if you have pip installed) First make…