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 unblock(f): | |
""" | |
sets file to nonblocked state. sets process's stdout/stderr to nonblocked state too. | |
""" | |
from subprocess import Popen | |
if type(p)==Popen: | |
unblock(p.stderr) | |
unblock(p.stdout) | |
return | |
import os,fcntl |
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 unblock(f): | |
""" | |
sets file to nonblocked state. sets process's stdout/stderr to nonblocked state too. | |
""" | |
from subprocess import Popen | |
if type(p)==Popen: | |
unblock(p.stderr) | |
unblock(p.stdout) | |
return | |
import os,fcntl |
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
// add python-like functions for attr access | |
function getattr(x,y){ | |
return x[y]; | |
} | |
function setattr(x,y,z){ | |
x[y]=z; | |
} | |
function hasattr(x,y){ | |
return (x[y]!==undefined); | |
} |
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
#!/usr/bin/python | |
from gevent import monkey; monkey.patch_all() | |
import bottle | |
from bottle import route | |
@route('/qwert') | |
def qwert(): | |
return ['qwert'] | |
@route('/static/<filepath:path>') |
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
import BaseHTTPServer | |
from SimpleHTTPServer import SimpleHTTPRequestHandler | |
import sys | |
import base64 | |
key = "" | |
class AuthHandler(SimpleHTTPRequestHandler): | |
''' Main class to present webpages and authentication. ''' | |
def do_HEAD(self): |
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
import BaseHTTPServer | |
from SimpleHTTPServer import SimpleHTTPRequestHandler | |
import sys | |
import base64 | |
key = "" | |
class AuthHandler(SimpleHTTPRequestHandler): | |
''' Main class to present webpages and authentication. ''' | |
def do_HEAD(self): |
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
ident::& ([$_A-Za-z]*);; | |
pat ::& (\(.*\)) ;; | |
item ::| ident pat ;; | |
stmt ::& expr (\;\;) ;; | |
list ::* item ;; | |
and ::& (\:\:\&) list;; | |
or ::& (\:\:\|) list;; | |
arr ::& (\:\:\*) list;; | |
expr ::| and or arr ;; | |
prog ::* expr ;; |
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 get_index(arr,n): | |
""" | |
arr is in a sparse form | |
""" | |
pos=0 | |
ret=arr[0][0] | |
seen=1 | |
for x in xrange(n): | |
seen+=1 | |
if seen>arr[pos][1]: |
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 _append_private_attr(cls,inst,propname,ret): | |
attrname = '_%s__%s' %(cls.__name__, propname) | |
if hasattr(inst,attrname): | |
ret.append( getattr(inst,attrname) ) | |
pass | |
def get_private_inherited_attrs(cls,inst,propname,ret=None): | |
""" | |
Just use this function to grab all your parents private variables in a list. |
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
#!/bin/sh | |
# Handlers - the macro processing package powered by handlebarsjs | |
# Usage: | |
# sh handlers.sh | node | |
DIR=lang/py | |
echo // requires | |
cat <<EOF | |
if (!global) global = window; | |
str = JSON.stringify; | |
LOG = console.log; |