Category: Programming

  • PyBrain quickstart and beyond

    After pip install bybrain, the PyBrain the quick start essentially goes as follows: from pybrain.tools.shortcuts import buildNetwork from pybrain.structure import TanhLayer from pybrain.datasets import SupervisedDataSet from pybrain.supervised.trainers import BackpropTrainer # Create a neural network with two inputs, three hidden, and one output net = buildNetwork(2, 3, 1, bias=True, hiddenclass=TanhLayer) # Create a dataset that matches […]

  • How to merge two disjoint random samples?

    The problem: Given two random samples, s1 and s2, of size k over two disjoint populations, p1 and p2, how to combine the two k-sized random samples into one k-sized random sample over p1 ∪ p2? The solution: k times, draw an element s1 ∪ s2; with probability d1 = |p1| / |p1 ∪ p2|, […]

  • Get Weather using JSON web service and Python

    Get the current weather for Copenhagen: import urllib2 import json # hent vejret for Koebenhavn url = ‘http://api.openweathermap.org/data/2.5/weather?q=Copenhagen,dk’ response = urllib2.urlopen(url) # parse JSON resultatet data = json.load(response) print ‘Weather in Copenhagen:’, data[‘weather’][0][‘description’]

  • Writing a parser in Python

    This is my base pattern for writing a parser in Python by using the pyparsing library. It is slightly more complicated than a hello world in pyparsing, but I think it is more useful as a small example of writing a parser for a real grammar. A base class PNode is used to provide utility […]

  • Tired of encoding problems in Python?

    A tip: Decode early, Unicode everywhere, encode late

  • Geocoding Python function for PostgreSQL

    Gratefully making use of what others have provided, i.e. geopy, Google and plpythonu. Type to hold result of geocoding: CREATE TYPE geocoding AS ( place text, latitude double precision, longitude double precision ); Function that does the actual geocoding (to be extended with more vendors. Hint: look at geopy wiki). Takes an (arbitrary) input string […]

  • Things related to Docker

    Docker is a cool idea and open-source product, that seems to be taking the tech community by storm. Wired will tell you why it is cool in a story titled The Man Who Built a Computer the Size of the Internet. The short version goes: Docker is a way to deploy and move applications with […]

  • Hello GNU profiling

    The profiling tool in GNU is called gprof. Here is a short, boring example of how to use it. 1) Write hello world in C (hello.c) #include int foo() { int b = 54324; int j; for (j=0; j < 1000000; j++) { b = b^j; } return b; } int main() { int a […]

  • Some good slides for using PostgreSQL with Python

    Peter Eisentraut has written some good slides on coding PostgreSQL clients in Python and on using Python as a stored procedures language in PostgreSQL. First half deals with using Python as a Postgres client. Second half deals with coding stored procedures in Python.

  • Go, go, go

    I’ve decided to learn Go. Not the board game, but the programming language. Why? I’ve been wanting to learn a systems programming language for a while, but have so far avoided picking up my brick of a C++ manual.