Skip to content

Instantly share code, notes, and snippets.

View HeinrichHartmann's full-sized avatar

Heinrich Hartmann HeinrichHartmann

View GitHub Profile
@HeinrichHartmann
HeinrichHartmann / banzhaf.py
Created August 18, 2014 19:56
Banzhaf power index calculation
# -------
# ------- banzhaf - version 1.1
# -------
# ------- A simple self-contained function to compute the Banzhaf Power Index given:
# ------- * a list of integer weights for all voters in the system, sorted in ascending order
# ------- * the quota for the voting system
# -------
# ------- This is a slight modification (mainly vectorization) of the code by
# ------- Ruben R. Puentedura (http://www.hippasus.com/resources/socialsoftware/index.html)
# ------- which was published under CC-License in 2004
@HeinrichHartmann
HeinrichHartmann / hartmann.pub
Created November 16, 2014 17:15
GPG Public Key
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: SKS 1.1.4
Comment: Hostname: pgp.mit.edu
mQENBFLOhGwBCADLreJzn4F8bKodTjg/QY4AyvQQWxnM0h56xsUmqTZqvRCp9kgtrcR5Bnvp
kMMRoIx9rOM7Hnp/LrxogZ8ZHbp+r3eQt3tp8p7ZwymQCT8cZoreTQplDp4eqZmnPh4BMk3a
+gqvgPv5SShwQjNGtf8r31MWe+xTCx6Db1XYpHav0pSs06Gmf/Kh/WVMtTvh841R0OU9mWhk
OxnOYWDErPSzUolA9u4A20B3LVpowjoA5Oaq3kIzC+mgL7muXhiEA4hzL9WXqcDHPXyRS3ut
Djmz1oqXFIZFgwhUUDW6g1hyuVuulNZRMkFtqASi13x+qMF8PwbU6KvoVCXG9++yQF13ABEB
AAG0K0hlaW5yaWNoIEhhcnRtYW5uIDxoYXJ0bWFubkB1bmkta29ibGVuei5kZT6JAT4EEwEC
@HeinrichHartmann
HeinrichHartmann / blink.py
Last active August 29, 2015 14:10
Raspberry PI GPIO Tester
@HeinrichHartmann
HeinrichHartmann / TimeSeriesTools.py
Last active August 29, 2015 14:11
TimeSeries convenience functions
import numpy as np
import matplotlib.pylab as plt
from scipy import stats
from collections import *
from itertools import *
#
# Convenience Class for Time Series
#
# Series Objects can be added and subtracted using infix operators.
@HeinrichHartmann
HeinrichHartmann / RPi_ADC8032.py
Created December 14, 2014 21:04
Raspbery Pi Analog Input with ADC0832
#!/usr/bin/env python
#
# Analog Input with ADC0832 chip
#
# Datasheet: http://www.ti.com/lit/ds/symlink/adc0838-n.pdf
# Part of SunFounder LCD StarterKit
# http://www.sunfounder.com/index.php?c=show&id=21&model=LCD%20Starter%20Kit
#
import time
@HeinrichHartmann
HeinrichHartmann / sensor-server.py
Last active August 29, 2015 14:11
RaspberryPi Serving Sensor Data over HTTP
#!/usr/bin/env python
# Import the ADC driver:
# https://gist.github.com/HeinrichHartmann/27f33798d12317575c6c
import ADC0832 as ADC
import sys
import BaseHTTPServer
import json
from BaseHTTPServer import BaseHTTPRequestHandler
@HeinrichHartmann
HeinrichHartmann / _G.lua
Last active August 29, 2015 14:15
Lua Global Environment
{
_G = nil --[[ref]],
_VERSION = "Lua 5.1",
arg = {
[-1] = "/usr/bin/lua",
[0] = "main.lua"
} --[[table: 0xbcbef0]],
assert = assert --[[function: 0xbc5310]],
collectgarbage = collectgarbage --[[function: 0xbc5370]],
coroutine = {
@HeinrichHartmann
HeinrichHartmann / GoogleSheetsExample.py
Last active December 5, 2016 20:34
Convenient Access to Google Spreadsheets
# Copyright (c) 2015 Heinrich Hartmann
# MIT License http://choosealicense.com/licenses/mit/
import gdata.spreadsheet.service
class GoogleDriveConnection(object):
def __init__(self, email, password):
self.client = gdata.spreadsheet.service.SpreadsheetsService()
self.client.ClientLogin(email, password)
@HeinrichHartmann
HeinrichHartmann / histogram.py
Created January 15, 2016 13:56
Simple (inefficient) example of how to create a histogram with python
from matplotlib import pyplot as plt
import numpy as np
X = np.genfromtxt("DataSets/RequestRates.csv", delimiter=",")[:,1]
bins = [500, 700, 800, 900, 1000, 1500, 1800, 2000, 2200]
bin_count = len(bins) - 1
sample_counts = [0] * bin_count
for x in X:
for i in range(bin_count):
if (bins[i] <= x) and (x < bins[i + 1]):
sample_counts[i] += 1
@HeinrichHartmann
HeinrichHartmann / pinbuffer.el
Created June 15, 2016 16:06
Pin an buffer to a window in #emacs
;; Similar to: http://stackoverflow.com/questions/43765/pin-emacs-buffers-to-windows-for-cscope/65992#65992
(defun pin-buffer ()
"Pin buffer to current window."
(interactive)
(message
(if (let (window (get-buffer-window (current-buffer)))
(set-window-dedicated-p window (not (window-dedicated-p window))))
"pinned buffer" "un-pinned buffer")
))