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
def fizzbuzz4(maxnum):
fizzbuzz_pairs = ((num,
("" if num % 3 else "fizz") + ("" if num % 5 else "buzz"))
for num in range(1, maxnum + 1))
for num, msg in fizzbuzz_pairs:
print("{}: {}".format(num, msg))
def fizzbuzz3(maxnum):
fizzbuzz_pairs = [(num,
("" if num % 3 else "fizz") + ("" if num % 5 else "buzz"))
for num in range(1, maxnum + 1)]
for num, msg in fizzbuzz_pairs:
print("{}: {}".format(num, msg))
def fizzbuzz2(max_num):
for num in range(1, max_num+1):
fizz = "fizz" if num % 3 == 0 else ""
buzz = "buzz" if num % 5 == 0 else ""
print("{}: {}".format(num, fizz + buzz))
def fizzbuzz1(max_num):
for num in range(1, max_num+1):
msg = ""
if num % 3 == 0:
msg += "fizz"
if num % 5 == 0:
msg += "buzz"
print("{}: {}".format(num, msg))
from functools import wraps
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)
from functools import wraps
def validate_json(func):
@wraps(func)
def wrapper(*args, **kwargs):
json_data = request.get_json()
if "exercise_id" not in json_data or "score" not in json_data:
abort(400)
return func(*args, **kwargs)
return wrapper
@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"))
@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"))
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
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