Skip to content

Instantly share code, notes, and snippets.

View hinnerk's full-sized avatar

Hinnerk Haardt hinnerk

View GitHub Profile
@hinnerk
hinnerk / aws_usage.py
Created February 9, 2011 11:08 — forked from rcoup/aws_usage.py
Fork of AWS usage report download script.
#!/usr/bin/env python
"""
A script to query the Amazon Web Services usage reports programmatically.
Ideally this wouldn't exist, and Amazon would provide an API we can use
instead, but hey - that's life.
Basically takes your AWS account username and password, logs into the
website as you, and grabs the data out. Always gets the 'All Usage Types'
@hinnerk
hinnerk / startme.py
Created February 10, 2011 22:37
A simple program consisting of a start-able setting file and a worker that contains all the code. The worker can access settings without blowing up if a setting doesn't exist.
#!/usr/bin/env python
# The exercise is to make a start-able config file
#
# This file contains some settings and minimal code to make it run.
name = "Anonymous"
weight = 80
size = 1.80
@hinnerk
hinnerk / IAM-EC2-GROUP-POLICY.json
Created February 18, 2011 20:38
AWS IAM group policy allowing only access to EC2
{
"Statement": [
{
"Effect": "Allow",
"Action": "ec2:*",
"Resource": "*"
}
]
}
@hinnerk
hinnerk / reiskoerner.py
Created May 22, 2011 11:12
Zähle alle Reiskoerner von Hand...
#!/usr/bin/env python
print "Fange an zu zaehlen..."
# wir starten mit einem Korn auf Feld 1
koerner_auf_feld = 1
# und haben am Anfang ein Korn im Sack
sack = 1
# fuer jedes Feld nach dem ersten (also Nummer 2 bis 64)
for x in range(2,65):
@hinnerk
hinnerk / renamepdfs.sh
Created October 21, 2011 12:16
Renames PDF files using the »InfoKey: Title« pdf attribute. Example: »817-1985.pdf« => »System Administration Guide Basic Administration (817-1985).pdf«
#!/bin/bash
# (BSD 3-Clause / "BSD New" / "BSD Simplified")
# Copyright (c) 2011, Hinnerk Haardt
# <haardt@information-control.de> All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
@hinnerk
hinnerk / monte_pi.py
Created February 3, 2012 13:10
π — calculated by chance
from random import random
import multiprocessing
from datetime import datetime
def run_simulation(throws=1000000):
hits = 0
count = 0
while count < throws:
count += 1
x = random()
import time
def test_time():
collisions = 0 # number of collisions
dist = {} # distinct values
microsecond = 0.000001
count = 0
while count < 1000000:
count += 1
t1 = time.time()
@hinnerk
hinnerk / observer.py
Created November 8, 2012 13:38
Observer-Pattern in Python
class Event(object):
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
setattr(self, k, v)
class Observable(object):
def __init__(self):
self.callbacks = set()
@hinnerk
hinnerk / link_AppSupport.sh
Created January 7, 2014 16:28
Soft-link all files/directories from current path into `~/Library/Application Support`. I used this some time ago to keep settings under revision management and, by extension, synched between multiple Mac OS X machines.
@hinnerk
hinnerk / timer_mul.py
Created January 7, 2014 16:48
Some strange benchmark written around 2007.
import random
value_list = [random.randint(0,0xff) for x in range(0,512)]
import operator
def mul_1(value_list):
"""
mixed
>>> mul_1((116, 101, 115, 116, 32, 116, 101, 115, 116, 32, 116, 101, 115, 116))