This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################################################################### | |
# 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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.