Skip to content

Instantly share code, notes, and snippets.

View val314159's full-sized avatar

val314159 val314159

View GitHub Profile
@val314159
val314159 / gist:b50475e75a75e27be766
Created December 14, 2014 20:57
unblock (files and subprocesses)
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
@val314159
val314159 / unblock.py
Created December 14, 2014 20:59
sets file to nonblocked state. sets process's stdout/stderr to nonblocked state too.
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
@val314159
val314159 / attr.js
Created December 19, 2014 18:45
{get,set,has}attr for javascript, works just like python. Sort-kinda cross-platformish!
// 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);
}
@val314159
val314159 / gevent_ssl_svr.py
Created January 13, 2015 17:37
bottle on top of gevent ssl WGSI server
#!/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>')
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):
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):
@val314159
val314159 / parser.prs
Last active August 29, 2015 14:13
self describing parser language
ident::& ([$_A-Za-z]*);;
pat ::& (\(.*\)) ;;
item ::| ident pat ;;
stmt ::& expr (\;\;) ;;
list ::* item ;;
and ::& (\:\:\&) list;;
or ::& (\:\:\|) list;;
arr ::& (\:\:\*) list;;
expr ::| and or arr ;;
prog ::* expr ;;
@val314159
val314159 / sparse_array_get.py
Created January 23, 2015 02:52
get n from sparse array
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]:
@val314159
val314159 / get_private_inherited_attrs.py
Last active August 29, 2015 14:16
Just use this function to grab all your parents' private variables in a list.
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.
@val314159
val314159 / handlers.sh
Created March 16, 2015 03:24
Handlers - the macro processing package powered by handlebarsjs
#!/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;