Skip to content

Instantly share code, notes, and snippets.

View pcote's full-sized avatar
🏠
Working from home

Emma Cote pcote

🏠
Working from home
View GitHub Profile
for soup, file_name in soup_line("sources"):
print(file_name, soup("title"))
from threading import Thread
from random import random, seed
from time import time, sleep
from functools import wraps
def concurrent(func):
@wraps(func)
def wrapper(*args, **kwargs):
Thread(target=func, args=args).start()
@count_limiter(3)
def hello(person):
print("hi there {}".format(person))
if __name__ == '__main__':
hello("fred")
hello("george")
hello("jane")
hello("jim") # exception thrown here because it's the 4th call
class count_limiter(object):
def __init__(self, count_limit):
pass
def __call__(self, func):
def wrapper(*args, **kwargs):
res = func(*args, **kwargs)
return res
@pcote
pcote / gist:b434193ac3fefe539e2f
Created November 13, 2015 00:35
General Starter Script for 64 bit Ubuntu Linux provisioning
#!/bin/sh
function install_packages(){
sudo apt-get install -y nginx build-essential python3-dev libssl-dev openssl python3-pip fail2ban git mysql-server
sudo pip3 install -r requirements.txt
}
@pcote
pcote / provision.sh
Last active November 13, 2015 13:57
Generic provisioning script for a setting up a 64 bit Ubuntu box. (built with Trusty in mind)
#!/bin/sh
function install_packages {
sudo apt-get install -y nginx build-essential python3-dev libssl-dev openssl python3-pip fail2ban git mysql-server
sudo pip3 install -r requirements.txt
}
ipython>=2.0
sqlalchemy>=0.9
flask>=0.10
flask-sqlalchemy>=2
pymysql>=0.6
nose>=1.3
requests>=2.5
beautifulsoup4>=4.0
uwsgi>=2
def validate_json(*expected_args):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
json_ob = request.get_json()
for expected_arg in expected_args:
if expected_arg not in json_ob or json_ob.get(expected_arg) is None:
abort(400)
return func(*args, **kwargs)
return wrapper
@app.route("/addscore", methods=["POST"])
def add_score():
json_data = request.get_json()
exercise_id = json_data.get("exercise_id")
score = json_data.get("score")
model.add_attempt(exercise_id, score)
return jsonify(dict(result="success"))
@app.route("/addscore", methods=["POST"])
def add_score():
json_data = request.get_json()
if "exercise_id" not in json_data or "score" not in json_data:
abort(400)
exercise_id = json_data.get("exercise_id")
score = json_data.get("score")
model.add_attempt(exercise_id, score)
return jsonify(dict(result="success"))