Skip to content

Instantly share code, notes, and snippets.

View kwlzn's full-sized avatar

Kris Wilson kwlzn

View GitHub Profile
@kwlzn
kwlzn / per.py
Created January 3, 2013 21:10
quick/dirty stdin line counter in python
#!/usr/bin/env python
import sys, time, select, signal
try: window = int(sys.argv[1])
except: print 'usage: %s <window>' % sys.argv[0]; sys.exit(1)
a_time, b_time = long( time.time() ), 0
count = 0
def ctrlc(signum, frame): sys.exit(0)
@kwlzn
kwlzn / taskgraph.py
Last active November 30, 2017 10:04
#!/usr/bin/env python
from collections import deque
class TaskGraph(object):
''' simple acyclic, directed property graph with iteration
use case:
1) model nodes as dicts and dependencies as directed edges (name=occ -> name=twist)
2) start with all nodes colored down (_st=0)
@kwlzn
kwlzn / uwsgi-pex.md
Last active June 13, 2018 15:55
uWSGI + pex

Building a test pex

setup.py

yakuza:src kw$ cat testapp/setup.py
#!/usr/bin/env python

from distutils.core import setup
@kwlzn
kwlzn / Makefile
Created May 6, 2014 00:37
uWSGI + pex Makefile
PYTHON := python2.6
BUILD_DIR := buildtmp
AURORA_CLUSTER := test
AURORA_ROLE := $(shell whoami)
UWSGI_VER = 2.0.4
UWSGI_DIR = uwsgi-$(UWSGI_VER)
UWSGI_FILE = $(UWSGI_DIR).tar.gz
UWSGI_URL = http://projects.unbit.it/downloads/$(UWSGI_FILE)
@kwlzn
kwlzn / .slate
Created May 16, 2015 01:25
slate config
## configs
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
config checkDefaultsOnLoad true
config focusCheckWidthMax 3000
config windowHintsShowIcons true
config windowHintsIgnoreHiddenWindows false
config windowHintsSpread true
@kwlzn
kwlzn / pants_exe.py
Created September 15, 2015 22:50
yappi profiling
import atexit, yappi
def init_yappi():
print('[YAPPI START]')
yappi.set_clock_type('wall')
yappi.start()
@atexit.register
def finish_yappi():
print('[YAPPI STOP]')

PEX

image

pex is a library for generating .pex (Python EXecutable) files which are executable Python environments in the spirit of virtualenvs. pex is an expansion upon the ideas outlined in PEP 441 and makes the deployment of Python applications as simple as cp. pex files may even

cold `./pants list ::`
pre gc, post-execution object count deltas
------------------------------------------
tuple 10409897 +10400188
set 7851229 +7845649
list 5010959 +4998632
StepRequest 3989446 +3989446
Entry 2572224 +2572224
dict 2305074 +2290623
@kwlzn
kwlzn / datatype.py
Last active November 30, 2017 10:04
python datatype factory
#!/usr/bin/env python2.7
import itertools
def datatype(type_name, params):
"""A faster/more efficient namedtuple replacement with better subclassing properties.
>>> RustLibrary = datatype('RustLibrary', ['sources', 'dependencies'])
>>> rl = RustLibrary([1,2,3], [4,5,6])
@kwlzn
kwlzn / docstring_grep.py
Created March 23, 2017 04:51
docstring_grep.py
#!/usr/bin/env python2.7
import ast
import itertools
import fnmatch
import os
import sys
class DocstringScanner(object):