Skip to content

Instantly share code, notes, and snippets.

View benjamingeiger's full-sized avatar

Benjamin Geiger benjamingeiger

View GitHub Profile
@benjamingeiger
benjamingeiger / gist:3627064
Created September 4, 2012 21:52
Cartesian product of lists in Python.
def cartesian (lists):
if lists == []: return [()]
return [x + (y,) for x in cartesian(lists[:-1]) for y in lists[-1]]
print cartesian([[1, 2, 3], [2, 4, 6], [3, 6, 9]])
@benjamingeiger
benjamingeiger / gist:3835506
Created October 4, 2012 18:34
XOR method with type error.
private static byte[] xor(byte[] left, byte[] right, int len)
{
byte[] output = new byte[len];
for (int i = 0; i < len; i++) {
output[i] = (byte) ((byte) left[i]) ^ ((byte) right[i]);
}
return output;
}
@benjamingeiger
benjamingeiger / kernels.cl
Created November 25, 2012 17:40
Failing syntax/matching.
__kernel void
aes128_expand_encryption_key ( __global uint4 *key ,
__global uint4 *expandedkeys )
{
uint rd;
uint global_id = get_global_id(0);
__global uint4 * ex = (expandedkeys + (global_id * 11));
@benjamingeiger
benjamingeiger / gist:4145298
Created November 25, 2012 20:57
How do I parallelize this?
for (round = 1; round <= 9; round++) {
temp.x =
key[round].x
^ Te0[(ciphertext.x >> 24) & 0xFF]
^ Te1[(ciphertext.y >> 16) & 0xFF]
^ Te2[(ciphertext.z >> 8) & 0xFF]
^ Te3[(ciphertext.w >> 0) & 0xFF];
temp.y =
key[round].y
^ Te0[(ciphertext.y >> 24) & 0xFF]
[bgeiger@Maximus][~]$ ls -l /Library/Internet\ Plug-Ins/
total 12
drwxrwxr-x 3 root wheel 102 Oct 31 09:08 AdobeExManDetect.plugin
lrwxr-xr-x 1 root wheel 91 Oct 17 09:56 AmazonMP3DownloaderPlugin1017287.plugin -> /Applications/Amazon MP3 Downloader.app/Contents/Resources/AmazonMP3DownloaderPlugin.plugin
drwxrwxr-x 3 root wheel 102 Jan 9 15:10 Flash Player.plugin
drwxr-xr-x 3 root wheel 102 Aug 24 17:33 Flip4Mac WMV Plugin.plugin
lrwxr-xr-x 1 root wheel 86 Jan 9 17:03 JavaAppletPlugin.plugin -> /System/Library/Java/Support/Deploy.bundle/Contents/Resources/JavaPlugin2_NPAPI.plugin
drwxr-xr-x 3 root wheel 102 Jun 20 2012 Quartz Composer.webplugin
drwxr-xr-x 3 root wheel 102 Jun 20 2012 QuickTime Plugin.plugin
drwxrwxr-x 3 root wheel 102 Apr 2 2012 SharePointBrowserPlugin.plugin
import re
# Get a list of all stories. (This will have to be written at some point.)
stories = get_stories()
for story in stories:
summary = story.get_summary()
body = story.get_body()
if (not summary) or len(summary.trim()) == 0:
@benjamingeiger
benjamingeiger / gist:6081268
Created July 25, 2013 16:10
Are lists passed by reference?
In [1]: foo = [1, 2, 3, 4, 5]
In [2]: def bar(lst):
...: lst.append(6)
...:
In [3]: bar(foo)
In [4]: foo
Out[4]: [1, 2, 3, 4, 5, 6]
@benjamingeiger
benjamingeiger / gist:6082446
Created July 25, 2013 18:31
Aliasing bug in Python.
foo = [[0] * 10] * 10
print(foo)
foo[3][5] = 1
print(foo)
@benjamingeiger
benjamingeiger / Intervalometer.ino
Created August 26, 2013 01:42
Intervalometer code that started breaking.
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
#include <EEPROM.h>
/*
** Hardware configuration.
*/
@benjamingeiger
benjamingeiger / gist:11340007
Created April 27, 2014 07:53
Python subprocess emulating a filter.
infile = open(inputfilename, "r")
outfile = open(outputfilename, "w")
filter1 = subprocess.Popen(commandline1, stdin=infile, stdout=subprocess.PIPE, stderr=None)
filter2 = subprocess.Popen(commandline2, stdin=filter1.stdout, stdout=outfile, stderr=None)
filter1.stdout.close() # required so filter2 can get SIGPIPE, apparently
filter1.wait()
filter2.wait()