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
import threading | |
from functools import wraps | |
from UserDict import UserDict | |
state = threading.local() | |
class DictProxy(UserDict, object): | |
def __init__(self, getter, dict=None, **kwargs): | |
object.__setattr__(self, 'getter', getter) | |
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
import os | |
from glob import glob | |
for file in glob('*-script.py'): | |
exe = file.replace('-script.py', '.exe') | |
bat = file.replace('-script.py', '.bat') | |
ax = filter(os.path.exists, [exe, bat]) | |
print file |
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
try: | |
from twisted.internet import pollreactor | |
pollreactor.install() | |
except: pass | |
from twisted.internet import protocol, reactor, defer, task | |
from twisted.web import http, proxy, resource, server | |
from twisted.python import log | |
import sys | |
import time |
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
#Volume up | |
"amixer sset Master 5+ unmute" | |
m:0x0 + b:9 | |
#Volume down | |
"amixer sset Master 5- unmute" | |
m:0x0 + b:8 |
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
import json | |
from collections import OrderedDict | |
from lxml import objectify | |
def xml_to_py(el): | |
if len(set([x.tag for x in el.getchildren()])) == 1: | |
return [xml_to_py(x) for x in el.getchildren()] | |
if hasattr(el, 'pyval'): | |
return el.pyval |
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/expect | |
trap { | |
set rows [stty rows] | |
set cols [stty columns] | |
stty rows $rows columns $cols < $spawn_out(slave,name) | |
} WINCH | |
spawn "/bin/bash" |
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
INDENT = ' ' | |
lines = open('data').read().splitlines() | |
def calc_indent(line): | |
return len([x for x in line.split(INDENT) if not x]) | |
_last_id = 0 | |
def next_id(name): |
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:window.location = document.getElementsByTagName('frame').length?document.getElementsByTagName('frame')[1].src:$('object').attr('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
import struct | |
from_hex = lambda hx: struct.unpack('>f', struct.pack('>I', hx))[0] | |
to_hex = lambda dc: '0x' + ''.join(['%.2x' % ord(x) for x in struct.pack('>f', dc)]) | |
chr_to_bin = lambda ch: ('0'*8 + bin(ord(ch))[2:])[-8:] | |
to_32_bits = lambda fl: '|'.join((lambda bits: [bits[:1], bits[1:9], bits[9:]])(''.join(map(chr_to_bin, struct.pack('>f', fl))))) | |
to_64_bits = lambda fl: '|'.join((lambda bits: [bits[:1], bits[1:12], bits[12:]])(''.join(map(chr_to_bin, struct.pack('>d', fl))))) | |
from_bits = lambda bs: from_hex(int(bs.replace('|', ''), 2)) | |
a = 0xfb |
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
import sys | |
import os | |
import time | |
from collections import namedtuple | |
Cell = namedtuple('Cell', ['x', 'y']) | |
class World: | |
def __init__(self, cells): | |
self.cells = set(cells) |
OlderNewer