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 os | |
from fnmatch import fnmatch | |
def find(pat, root): | |
for path, dirs, files in os.walk(root): | |
for f in files: | |
if fnmatch(f, pat): | |
yield os.path.join(path, f) | |
if __name__ == "__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
class Adder(object): | |
queue = "Adder" | |
@staticmethod | |
def perform(a, b): | |
return a+b | |
if __name__ == "__main__": | |
import random | |
from pyres import ResQ |
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/env python | |
""" | |
git-branched - show metadata about where a branch came from (and optionally, | |
what commits were on the branch) | |
Based on the method here: | |
http://stackoverflow.com/a/4991675/75956 | |
Some examples: |
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/env python | |
""" | |
Command line tool for showing the result of a simple python expression. | |
Some common modules are imported for you (e.g. math, datetime, pprint, etc.). | |
Exceptions are caught and printed, instead of showing a full traceback. | |
Examples: | |
$ py "2+2" |
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/env python | |
from fabric.api import task, local, settings | |
class CommandFailed(Exception): | |
def __init__(self, message, result): | |
Exception.__init__(self, message) | |
self.result = result | |
def elocal(*args, **kwargs): | |
with settings(warn_only=True): |
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 time | |
from fabric.api import local, lcd | |
_step = 1 | |
def format_step(msg1, step, desc, msg2, fillchar=">", cols=80): | |
out = "%s %s %d (%s) %s" % ( | |
fillchar*3, | |
msg1, | |
step, |
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 sys, os | |
INTERP = "/home/username/domain/env/bin/python" | |
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv) | |
def testapp(environ, start_response): | |
import pprint | |
start_response('200 OK', [('Content-type', 'text/plain')]) | |
yield sys.version | |
yield pprint.pformat(environ) |
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: |
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
from flask import Flask, jsonify, Blueprint, current_app | |
import json | |
## REST api ################################################################### | |
api = Blueprint('api', __name__) | |
@api.route("/users") | |
def users(): | |
return jsonify(users=[ |
OlderNewer