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
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
# 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
#!/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
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
# 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
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
#!/usr/bin/env python | |
from __future__ import print_function | |
import gevent | |
import gevent.monkey | |
gevent.monkey.patch_all() | |
import gevent.hub | |
import redis |
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
a.out: a.o b.o def.o | |
%.o: %.cpp | |
clang++ -c -o $@ $< |
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
var http = require('http'), | |
phantom=require('node-phantom'), // https://github.com/alexscheelmeyer/node-phantom | |
urlparse = require('url'); | |
function proxy_url(url, res) { | |
phantom.create(function(err,ph) { | |
return ph.createPage(function(err,page) { | |