Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
def Ord(ch): return ord(ch) - ord('A') # convert A-Z to 0-25
def Chr(ch): return chr(ch + ord('A')) # convert 0-25 to A-Z
def Text(s): return "".join(ch for ch in s if ch in "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
Rotors = { # name: (wiring, notches)
"I": ("EKMFLGDQVZNTOWYHXUSPAIBRCJ", "Q"), # 1930 Enigma I
"II": ("AJDKSIRUXBLHWTMCQGZNPYFVOE", "E"), # 1930 Enigma I
"III": ("BDFHJLCPRTXVZNYEIWGAKMUSQO", "V"), # 1930 Enigma I
import urllib, re, os, urlparse, json, random, sys, getopt, gzip, math, time
from multiprocessing.dummy import Pool as ThreadPool
from cStringIO import StringIO
from PIL import Image
import numpy as np
def download_all_thumbs(ld_num,dest_folder=None):
event_name = 'ludum-dare-%d' % ld_num
entries_page_url_template = "http://www.ludumdare.com/compo/%s/?action=preview&etype=&start=%%d" % event_name
@williame
williame / gist:935a47a6262fc5023847
Last active August 29, 2015 14:05
swap patterns of mosaic rotations placement
XX.XX@XXX.XXX@@.XX..XXX..X.XX....X@.X.X...XXX......X.X@.@@.X@.XX......X...@....@X.X.X.X@@..X....@.X@.........@X.X.@.@@X.@.X.@...X..X.@@X...X.X.X....@X@XX.....XX.X.@X......X..X@..@@.X...@XXX@.@@XXX.XXXXXXX.X..X@XX.X@X.@@@..X.@...XX..X@XXX@X..XX.@..@.@@X.@..X.X..XX....X@@...X.XXXX.....X@...@..@...X@X@X.XXXX.@X..@....@......X...X@.....@@..X@X@..X....@@.X..@.@@XXX.X.....XX@X.@...@XX..@X@....XX..X.@.@X@X.XX...X.@..@..@@X.XXX..@X.XX..X....@@.X@...XX@X........X.@.XX.XX.X..@X@X.......X.XX@..X..XX.X@.....X.X@.@X.@@...X.@@.XX..@X.X@X@X@@@.XXX@.@.XX....X....@...X@@@X.@.@.@..X@.X.XX@@.X.X.@.@X.X..XXX.@.X..@XX.XX@XXX....X@.XXX.X.XX@X@.X..@X...X..X@X.@XX...X....@@.XXX...XXXXX...XX..X.X.X.@X@XX.XX.@X.XXX...@.X.@XX@X@X...@X...@.XXX...@X.@XX..XX..X..@.@X....X.X@.X@X.X@.@.@X....@@..@.X.X.@.@.X@.X@...@......@@X.XX..@X.XXXX.X.X.XX@.XX..XX.XXX.@@.X...X.X..X.@@..X@....@..XX@X....@X...@X..X.X...XX..@XX@X.XX.@........X.X...X@@@X@@.@.X..X.X.X..X.@XXX@XX.X@....X.X@XX.X.@.@...@@@.@X...@@XX@..@......@X@...X.X.@..@.@X....@X....@.X@.@.X@.
import os, sys
from PIL import Image
size = 128, 128
w, h = size
reds = [0] * w * h
greens = [0] * w * h
blues = [0] * w * h
count = 0
@williame
williame / gist:482fee74d096e47e006b
Last active August 29, 2015 14:02
benchmark iterating over set bits in a uint32_t
#include <cinttypes>
#include <cstdlib>
#include <ctime>
#include <iostream>
int main(int argc, char** args) {
srand(time(NULL));
@williame
williame / gist:3fcfeb1d424f01b2fa59
Created June 13, 2014 07:43
iterating over the set bits in an int efficiently
for(uint32_t m = mask, i = ~0U; m; ) {
auto shift = __builtin_ffs(m);
m >>= shift;
i += shift;
... do something with i
}
import urllib, re, os, urlparse, json, random, sys, getopt, gzip, math, time
from multiprocessing.dummy import Pool as ThreadPool
from cStringIO import StringIO
import Image
def download_all_thumbs(ld_num=28,dest_folder="thumbs"):
event_name = 'ludum-dare-%d' % ld_num
entries_page_url_template = "http://www.ludumdare.com/compo/%s/?action=preview&etype=&start=%%d" % event_name
class Test {
static void func(final String X) {
new Test() {
String X = X.toLowerCase(); <-- I want to init X to be something derived from the parameter X
};
}
}
@williame
williame / gist:5934448
Created July 5, 2013 13:12
broken ray cast code
// adapting http://gamedev.stackexchange.com/a/49423/4129
castRay: function(ray) {
var oX = ray[0][0], oY = ray[0][1], oZ = ray[0][2],
dX = ray[1][0]-oX, dY = ray[1][1]-oY, dZ = ray[1][2]-oZ,
x = Math.floor(oX), y = Math.floor(oY), z = Math.floor(oZ),
intbound = function(s,ds) {
if(ds < 0)
return intbound(-s,-ds);
return (1-((s%ds+ds)%ds))/ds;
function emitCube(blf,trb,array,ofs) {
ofs = ofs || 0;
var left = blf[0], right = trb[0],
bottom = blf[1], top = trb[1],
front = blf[2], back = trb[2],
tlb = [left,top,back],
trf = [right,top,front],
tlf = [left,top,front],
brb = [right,bottom,back],
blb = [left,bottom,back],