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
''' | |
From: http://superuser.com/a/224263 | |
''' | |
import commands | |
def get_ciphers(): | |
ciphers = commands.getoutput("openssl ciphers 'ALL:eNULL'").strip() | |
return ciphers.split(':') |
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 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")) |
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
''' | |
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 & |
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
>>> ' '.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' |
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
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'}, |
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
#http://news.ycombinator.com/item?id=4439352 | |
''' | |
before = (decoration) -> | |
(base) -> | |
-> | |
decoration.apply(this, arguments) | |
base.apply(this, arguments) | |
after = (decoration) -> |
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
#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(): |
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
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 |
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
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() |
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
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: |