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
for soup, file_name in soup_line("sources"): | |
print(file_name, soup("title")) |
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 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() |
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
@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 |
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 count_limiter(object): | |
def __init__(self, count_limit): | |
pass | |
def __call__(self, func): | |
def wrapper(*args, **kwargs): | |
res = func(*args, **kwargs) | |
return res |
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
#!/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 | |
} |
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
#!/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 | |
} |
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
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 |
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
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 |
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
@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")) |
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
@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")) |