Skip to content

Instantly share code, notes, and snippets.

View benjamingeiger's full-sized avatar

Benjamin Geiger benjamingeiger

View GitHub Profile
@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]
@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: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 / 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 / sorted.py
Created August 28, 2012 01:30
Python script to find the longest words with letters in reverse alphabetical order.
# Remove non-alphabetic characters (hyphens, etc) from the word.
def strip_non_alpha(word):
return "".join([x for x in list(word.lower()) if (x >= 'a' and x <= 'z')])
# Sort the letters in the word (in reverse).
def sort_letters(word):
letters = sorted(list(word))
letters.reverse()
return "".join(letters)
@benjamingeiger
benjamingeiger / gist:3476235
Created August 26, 2012 08:32
GCC vs. Clang in Mountain Lion
[bgeiger@Maximus][~/Desktop]$ which clang
/usr/bin/clang
[bgeiger@Maximus][~/Desktop]$ clang --version
Apple clang version 4.0 (tags/Apple/clang-421.0.57) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.1.0
Thread model: posix
[bgeiger@Maximus][~/Desktop]$ which gcc
/usr/bin/gcc
[bgeiger@Maximus][~/Desktop]$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
@benjamingeiger
benjamingeiger / gist:3224160
Created August 1, 2012 06:01
Grid search implementation.
def grid_search(features, results):
gamma_values = [(2 ** n) for n in range(-15, 4)]
cost_values = [(2 ** n) for n in range(-5, 16)]
params_values = [(gamma, cost) for gamma in gamma_values
for cost in cost_values]
best_auc = 0
best_gamma = None
best_cost = None
@benjamingeiger
benjamingeiger / gist:2410509
Created April 18, 2012 01:54
Zebralisting plugin
// lib/main.js
var pageMod = require("page-mod");
var self = require("self");
pageMod.PageMod({
include: "*",
contentScriptWhen: 'ready',
contentScriptFile: [self.data.url("jquery-1.7.2.min.js"),
self.data.url("zebra.js")]
@benjamingeiger
benjamingeiger / gist:1124599
Created August 4, 2011 06:27
Chrome plugin options page - can't find "restore_blocklist()"
<html>
<head>
<title>Porcupine Options</title>
</head>
<script src="jquery.js" type="text/javascript" />
<script type="text/javascript">
function restore_blocklist() {
//var blocklist = localStorage["porcupine-blocklist"];
var blocklist = [ "foo", "bar", "baz" ];
@benjamingeiger
benjamingeiger / gist:1025488
Created June 14, 2011 18:10
output of 'rake' in nifty-generators source tree
bgeiger@siwoti-rails:~/src/nifty-generators$ rake --trace
WARNING: Global access to Rake DSL methods is deprecated. Please include
... Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Cucumber::Rake::Task#desc called at /home/bgeiger/.rvm/gems/ruby-1.9.2-p180@nifty-generators/gems/cucumber-0.9.4/lib/cucumber/rake/task.rb:140:in `define_task'
WARNING: DSL method Cucumber::Rake::Task#task called at /home/bgeiger/.rvm/gems/ruby-1.9.2-p180@nifty-generators/gems/cucumber-0.9.4/lib/cucumber/rake/task.rb:141:in `define_task'
** Invoke default (first_time)
** Invoke features (first_time)
** Execute features
rake aborted!
uninitialized constant Cucumber::Rake::Task::ForkedCucumberRunner::RUBY