Skip to content

Instantly share code, notes, and snippets.

View michaelkrisper's full-sized avatar

Michael Krisper michaelkrisper

View GitHub Profile
public static class ExtensionOperations
{
public static T[] ForEach<T>(this T[] items, Action<T, int> action)
{
for (var i = 0; i < items.Length; i++)
action(items[i], i);
return items;
}
public static T[] ForEach<T>(this T[] items, Action<T> action)
@michaelkrisper
michaelkrisper / ak_is_hypothesis_test.ipynb
Last active August 29, 2015 14:09
ak_is_hypothesis_test
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
####################################################################
# Monkey Patch urllib2.urlopen for caching #########################
import shelve
import urllib2
__default_urlopen = urllib2.urlopen
def __urlopen(url):
db = shelve.open("tmp.db")
if url not in db:
db[url] = __default_urlopen(url).read()
result = db[url]
@michaelkrisper
michaelkrisper / powerset.py
Created May 16, 2013 23:25
Python: Powerset (Potenzmenge)
# Compute the Powerset of a list
# items = [1, 2]
# powerset = [[], [1], [2], [1, 2]]
import itertools
items = [1, 2, 3, 4]
powerset = [x for length in range(len(items)+1) for x in itertools.combinations(items, length)]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.