Category Programming

How to use non-default profile in boto3

Given an AWS credentials file that looks like this: [default] aws_access_key_id = DEFAULT aws_secret_access_key = SECRET1 [dev] aws_access_key_id = DEV aws_secret_access_key = SECRET2 [prod] aws_access_key_id = PROD aws_secret_access_key = SECRET3 You can use any profile, say dev, like this in…

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…

Get Weather using JSON web service and Python

Get the current weather for Copenhagen: import urllib2 import json # hent vejret for Koebenhavn url = ‘,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…

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 <…