Skip to content

Instantly share code, notes, and snippets.

View lost-theory's full-sized avatar

Steven Kryskalla lost-theory

View GitHub Profile
@lost-theory
lost-theory / ssl_test.py
Created December 24, 2013 21:00
ssl_test.py
'''
From: http://superuser.com/a/224263
'''
import commands
def get_ciphers():
ciphers = commands.getoutput("openssl ciphers 'ALL:eNULL'").strip()
return ciphers.split(':')
@lost-theory
lost-theory / who_is_on_call.py
Created December 19, 2013 01:32
how to show the name of the person on-call right now for a pagerduty schedule
import pygerduty
from datetime import datetime as dt, timedelta as d
p = pygerduty.PagerDuty("user-goes-here", "api-key-goes-here")
sched = p.schedules.show('SCHEDULEID')
t0 = dt.now()
t1 = t0 + d(minutes=1)
result = sched.entries.list(since=t0.strftime("%F %T"), until=t1.strftime("%F %T"))
@lost-theory
lost-theory / worker.py
Last active December 16, 2015 04:29
simple background worker process
'''
To test, first make a bunch of job files in the same directory this file is in:
$ for i in `seq 300`; do echo $i > $i.job; done;
Then fire up a bunch of workers:
$ python worker.py &
$ python worker.py &
$ python worker.py &
@lost-theory
lost-theory / gist:4759801
Created February 12, 2013 02:40
t2s i0s f1n
>>> ' '.join(map(lambda s: "%s%s%s" % (s[0], len(s)-2, s[-1]), "steven kryskalla".split()))
's4n k7a'
>>> ' '.join(map(lambda s: "%s%s%s" % (s[0], len(s)-2, s[-1]), "this is fun".split()))
't2s i0s f1n'
@lost-theory
lost-theory / composition.py
Created October 22, 2012 05:10
composition vs. inheritance
class ListView(object):
def get_items(self):
return []
class CategoryView(ListView):
def get_items(self):
return [
{'id': 1, 'title': 'First post', 'body': 'Hello world.', 'tags': ['red', 'blue'], 'category': 'something'},
{'id': 2, 'title': 'Second post', 'body': 'Jello world.', 'tags': ['blue', 'green'], 'category': 'cool'},
{'id': 3, 'title': 'Third post', 'body': 'Yellow world.', 'tags': ['yellow'], 'category': 'cool'},
@lost-theory
lost-theory / advice.py
Created August 28, 2012 07:53
coffeescript advice method combinators a la raganwald, in python
#http://news.ycombinator.com/item?id=4439352
'''
before = (decoration) ->
(base) ->
->
decoration.apply(this, arguments)
base.apply(this, arguments)
after = (decoration) ->
@lost-theory
lost-theory / decorators.py
Created August 28, 2012 07:55
coffeescript decorator examples a la raganwald, but in python
#http://news.ycombinator.com/item?id=4439352
def has_permission_to(user, verb, subj):
if user == "steve" and verb == "write":
return True
elif user == "alice" and verb == "read":
return True
return False
def current_user():
@lost-theory
lost-theory / gist:3091483
Created July 11, 2012 16:12
flask-dropbox 0.1.2 install
stevek@thor ~
$ virtualenv flaskdropbox_env
New python executable in flaskdropbox_env/bin/python
Installing setuptools............done.
stevek@thor ~
$ cd flaskdropbox_env/
stevek@thor ~/flaskdropbox_env
$ bin/pip install Flask-Dropbox
@lost-theory
lost-theory / gist:2871500
Created June 4, 2012 23:35
my new fabric wrapping technique is unstoppable
DESC = "command description goes here"
def usage():
print "%s - %s\n" % (__file__, DESC)
print "Note: use %s --fab-help to get help on arguments specific to" % __file__
print " fabric (roles, hosts, parallel execution, etc.)\n"
new_argv = ['fab', '-f', __file__, '--list']
sys.argv = new_argv
fabric.main.main()
@lost-theory
lost-theory / gist:2576645
Created May 2, 2012 13:50 — forked from isa/gist:2571012
Convert in less than 30 lines
data = '''\
A, B, C
A, C, E
E, F, D
D, A, J
E, D, J'''
import itertools, collections
print "\n".join([" "+", ".join(a + (str(b),)) for (a,b) in sorted(collections.Counter(sum([list(itertools.combinations(sorted(x.strip().split(', ')), 2)) for x in data.split('\n')], [])).items(), key=lambda t: t[0])])
#output: