Skip to content

Instantly share code, notes, and snippets.

@Tukki
Tukki / gist:18836ecae196006ae886
Last active August 29, 2015 14:01
voluptuous demo
def validate_iid(iid):
    pass


def get_action_id(action_name):
    pass


def form_error_to_json(view_func):

pass

@Tukki
Tukki / gist:5943755
Last active December 19, 2015 10:49
flask with static file, but not css/js... temporary, in development
http://stackoverflow.com/questions/13706382/how-to-get-static-files-in-flask-without-url-forstatic-file-name-xxx
You can Setup your own route to serve static
files. Add this method and update the static path director in the send_from_directory method and your img tag should work.
@app.route('/pic/<path:filename>')
def send_pic(filename):
return send_from_directory('/path/to/static/files', filename)
For a production app however, you should setup your server to serve static files directly.
import time
class cached_property(object):
'''Decorator for read-only properties evaluated only once within TTL period.
src http://wiki.python.org/moin/PythonDecoratorLibrary#Cached_Properties
It can be used to created a cached property like this::
import random
@Tukki
Tukki / gist:3954052
Created October 25, 2012 17:02
获取昨天的某个时刻
import datetime
yestoday = datetime.date.today() - datetime.timedelta(days=1)
print yestoday
yestoday_datetime = datetime.datetime.combine(yestoday, datetime.time.min)
print yestoday_datetime
yestoday_datetime = datetime.datetime.combine(yestoday, datetime.time())
print yestoday_datetime
@Tukki
Tukki / gist:3953990
Created October 25, 2012 16:52
filter by time in sqlalchemy
#http://stackoverflow.com/questions/7075828/make-sqlalchemy-use-date-in-filter-using-postgresql
from sqlalchemy import Date, cast
from datetime import date
my_date = (session.query(MyObject)
.filter(cast(MyObject.date_time, Date) == date.today())
.all())