This file contains hidden or 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
server { | |
#listen 80; ## listen for ipv4; this line is default and implied | |
#listen [::]:80 default ipv6only=on; ## listen for ipv6 | |
listen 80 default_server; | |
server_name _; | |
root /home/ubuntu/landing-page; | |
access_log /var/log/nginx/access_80.log; | |
error_log /var/log/nginx/error_80.log; |
This file contains hidden or 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
# Modified by adding names from https://github.com/richardasaurus/nginx-access-log-parser/blob/master/main.py | |
pat = (r'' | |
'(?P<ip>\d+.\d+.\d+.\d+)\s-\s-\s' #IP address | |
'\[(?P<time>.+)\]\s' #datetime | |
'"(?P<method>GET|POST)\s(?P<uri>.+)\s(?P<ver>\w+/.+)"\s(?P<status>\d+)\s' #requested file | |
'(?P<content_length>\d+)\s"(?P<referrer>.+)"\s' #referrer | |
'"(?P<user_agent>.+)"' #user agent | |
) | |
r = re.match(pat, logline) | |
r.groupdict() |
This file contains hidden or 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
def cmpsz(s1, s2): | |
tosz = lambda s: ('KMG'.find(s[-1]), float(s[:-1]) if s[-1] in 'KMG' else float(s)) | |
u1, s1 = tosz(s1) | |
u2, s2 = tosz(s2) | |
scmp = cmp(u1, u2) | |
return scmp if scmp != 0 else cmp(s1, s2) |
This file contains hidden or 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 __future__ import unicode_literals, print_function | |
import os | |
import subprocess as sp | |
from subprocess import check_output | |
from flask import Flask, Blueprint, current_app, \ | |
request, redirect, url_for |
This file contains hidden or 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
# When calling functions, remove unused arguments | |
# Useful for framework callbacks | |
def args_sink(f): | |
import inspect | |
dst_args = inspect.getargspec(f) | |
args = set(dst_args.args) | |
@wraps(f) | |
def wrapper(*a, **kw): | |
nkw = deepcopy(kw) |
This file contains hidden or 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
def runserver(port=5000, profile_log=None): | |
"""Runs a development server.""" | |
from gevent.wsgi import WSGIServer | |
from werkzeug.serving import run_with_reloader | |
from werkzeug.debug import DebuggedApplication | |
from werkzeug.contrib.profiler import ProfilerMiddleware | |
port = int(port) | |
if profile_log: |
This file contains hidden or 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
N=30 | |
PRINT = False | |
def f1(n): | |
if n < 2: return n | |
return f1(n-1) + f1(n-2) | |
print f1(N) if PRINT | |
def f2(n, mem={}): | |
if n < 2: return n |
This file contains hidden or 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 gevent | |
from gevent import Greenlet | |
from gevent.queue import Queue | |
from gevent.lock import BoundedSemaphore | |
class Worker(object): | |
def __init__(self, *a, **kw): | |
self._glet = Greenlet(self.run, *a, **kw) | |
self._q = Queue() |
This file contains hidden or 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 gevent | |
import logging | |
import requests | |
try: | |
import simplejson as json | |
except: | |
import json | |
from gevent.pool import Group, Pool |
This file contains hidden or 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 subprocess as sp | |
def list_revs(path, limit=10): | |
""" Parse output from svn log and find log headers. Maybe fooled if log entry contains some other svn log entries, etc.""" | |
out = sp.check_output('svn log -l {limit} {path}'.format(path=path, limit=limit), shell=True) | |
lines = out.split('\n') | |
for pre, line, space in zip(lines[:-2], lines[1:], lines[2:]): | |
if pre.startswith('-------') and space.strip() == '': | |
parts = line.split('|') | |
if len(parts) == 4 and parts[0].startswith('r'): |