This file contains 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
def single_character_xor(string, xor): | |
xored = map(lambda n: n ^ ord(xor), map(ord, string)) | |
return "".join(map(chr,xored)) | |
def detect_wtf(string): | |
for i in range(255): | |
xored = single_character_xor(string, chr(i)) | |
if xored[0] == string[0].upper(): | |
print string+" when XORed with %d"%i+"="+xored |
This file contains 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
def hamming_distance(a,b): | |
""" | |
Computes the byte difference between two strings. | |
>>> hamming_distance("this is a test", "wokka wokka!!!") | |
37 | |
""" | |
count = 0 | |
a = string_to_byte_array(a) | |
b = string_to_byte_array(b) |
This file contains 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
function DatabaseClient(callback) { | |
var self = this; | |
var queue = []; | |
var ready = false; | |
console.log("Connecting to database."); | |
function run(method, args) { | |
console.log("Executing operation: Database."+method); |
This file contains 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
function concat() { | |
var output = ""; | |
Array.prototype.forEach.call(arguments, function(arg) { | |
output += arg; | |
}); | |
return output; | |
} | |
console.log(concat('abc', 'def', 'ghi')); // 'abcdefghi' |
This file contains 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
function createUser(username, callback) { | |
var connection = DatabaseClient.connect(); | |
var users = connection.call('collection', 'users'); | |
var query = users.call('query', {username: username}); | |
return query.then(function(existing){ | |
if(existing) throw new Error("User already exists: " + username); | |
else return users.call('create', {username: username}); | |
}).fin(function(connection){ return connection.call('close'); }); | |
} |
This file contains 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
function createUser(username, callback) { | |
var connection = DatabaseClient.connect(); | |
var users = connection.collection('users'); | |
var query = users.query({username: username}); | |
return query.then(function(existing){ | |
if(existing) throw new Error("User already exists: " + username); | |
else return users.create({username: username}); | |
}).fin(function(connection){ return connection.call('close'); }); | |
} |
This file contains 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
from blessings import Terminal | |
from time import sleep | |
from random import randrange, choice | |
class Glyph(): | |
def __init__(self, content, terminal): | |
self.content = content | |
self.terminal = terminal |
This file contains 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
Request.Persistent = new Class({ | |
Extends: Request, | |
onStateChange: function(e) { | |
var patt = this.laststr; | |
this.laststr = this.xhr.responseText; | |
this.fireEvent('onUpdate', this.laststr.replace(patt, '')); | |
} | |
This file contains 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
var working = false; //Not currening switching content. | |
var newBenefit = function(e) { | |
if (working) return false; | |
working = true; | |
e.stop(); | |
var cur = $$('#benefits .current')[0]; | |
if (cur) { | |
var el = this; | |
var next = $(el.get('href').split('#')[1]); | |
var mleft = cur.getElement('.photo').getStyle('margin-left'); |
This file contains 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
Element.implement({ | |
/* Adds a getArguments method to Elements that will extract the "arguments" of | |
forms. */ | |
getArguments: function(){ | |
var obj = {}; | |
this.getElements('input, select, textarea', true).each(function(el){ | |
var name = el.name, type = el.type, value = el.value; | |
if (value === false || !name || el.disabled) return; | |
$splat(value).each(function(val){ obj[name] = val; }); |
OlderNewer