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
def myapp(environ): | |
print environ | |
query_string = environ['QUERY_STRING'] | |
return '<html><body>hello<body></html>' | |
def hello_world_app(environ, start_response): | |
status = '200 OK' # HTTP Status |
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
def announce(self, torrent): | |
"""Returns data from Tracker specified in torrent""" | |
announce_query_params = { | |
'info_hash' : torrent.info_hash, | |
'peer_id' : self.client_id, | |
'port' : self.port, | |
'uploaded' : 0, | |
'downloaded' : 0, | |
'left' : torrent.length, | |
'compact' : 1, # sometimes optional |
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
class Other(object): | |
def Task(self, x): | |
print 'called task' | |
class Foo(object): | |
def __init__(self): | |
self.tom = 12 | |
self.stuff = [] | |
@property |
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
// Closures are sometimes unintuitive! | |
console.log('the smart way'); | |
funs = [] | |
for (var a = 0; a < 3; a++){ | |
funs.push(function(){ | |
var newa = a; | |
return function(){console.log(newa);} | |
}()) |
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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <stdint.h> | |
#define MAX_CANDIDATES 25000 | |
#define TWOTOTHE32 4294967296 | |
int64_t random64bit(){ | |
// we need 64 bits of random data |
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
javascript: (function () { | |
if (document.timesClicked == undefined) { | |
document.timesClicked = 0; | |
}; | |
document.timesClicked++; | |
var names = document.getElementsByClassName('name'); | |
for (var i = 0; i < names.length; i = i + 1) { | |
if (!names[i].savedName) { | |
names[i].savedName = names[i].innerHTML; | |
} |
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
var data = $('.message_row, .recipient_row').map(function(i, x){ | |
return { | |
name : jQuery.makeArray($(x).find('.sender_name').map(function(i, x){return x.innerText})), | |
message : jQuery.makeArray($(x).find('.message_content').map(function(i, x){return x.innerText})), | |
time : jQuery.makeArray($(x).find('.message_time').map(function(i, x){return x.innerText})), | |
stream : jQuery.makeArray($(x).find('.stream_labels').map(function(i, x){return x.innerText})), | |
subject : jQuery.makeArray($(x).find('.narrows_by_subject').map(function(i, x){return x.innerText})) | |
}; | |
}) | |
var s = JSON.stringify(jQuery.makeArray(data)) |
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
#!/usr/bin/env python | |
from subprocess import Popen | |
import sys | |
def say_blocking(msg): | |
p = Popen(['say', msg]) | |
p.communicate() | |
while True: | |
line = sys.stdin.readline() |
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
[alias] | |
glog = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short | |
co = checkout | |
unstage = reset HEAD | |
[core] | |
pager = less -FRSX | |
editor = vim | |
[color] | |
ui = auto | |
status = auto |
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
def get_transitions(n): | |
"""Return a dictionary of array spots to neighbors for an nxn grid""" | |
return {initial_row*n + initial_col : | |
{row * n + col | |
for row in range(max(0, initial_row-1), min(n, initial_row+2)) | |
for col in range(max(0, initial_col-1), min(n, initial_col+2)) | |
if (row, col) != (initial_row, initial_col)} | |
for initial_row in range(n) | |
for initial_col in range(n)} |