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
# http://stackoverflow.com/a/23558809/720077 | |
def fibonacci(): | |
a, b = [1], [0] | |
def fibo(): | |
a[0], b[0] = b[0], a[0] + b[0] | |
return a[0] | |
return fibo |
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
class Password(str): | |
def __eq__(self, other): | |
if not isinstance(other, self.__class__): | |
other = bcrypt.hashpw(other, self) | |
return str.__eq__(self, other) | |
def __ne__(self, other): | |
return not self.__eq__(other) | |
def __get__(self, obj, type=None): |
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
@main.command() | |
def routes(): | |
from mainweb import app | |
sorted_rules = sorted(app.url_map.iter_rules(), key=lambda x: x.rule) | |
max_rule = max(len(rule.rule) for rule in sorted_rules) | |
max_ep = max(len(rule.endpoint) for rule in sorted_rules) | |
max_meth = max(len(', '.join(rule.methods)) for rule in sorted_rules) |
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
import inspect | |
import functools | |
from distutils.util import strtobool | |
def tobool(yesno): | |
"""Convert all kinds of possible "yes" values to True/False.""" | |
return bool(strtobool(yesno)) | |
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
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent' |
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
""" | |
setup.py | |
py2app setup script for creating a semi-standalone .app | |
around a Maya API based PyQt4 application. | |
Only bundled PyQt4 with the app, and references the Maya install | |
location for the python environment. | |
Allows for a portable GUI application that does not require |
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
import sys | |
from PySide.QtCore import QFile | |
from PySide.QtGui import QApplication, QMainWindow | |
from PySide.QtUiTools import QUiLoader | |
class MainWindow(QMainWindow): | |
def __new__(cls, *args, **kwargs): | |
"""Load widget from UI file.""" | |
super().__new__(cls, *args, **kwargs) |
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
""" | |
https://djangosnippets.org/snippets/401/ | |
Template filters to partition lists into rows or columns. | |
A common use-case is for splitting a list into a table with columns:: | |
{% load partition %} | |
<table> | |
{% for row in mylist|columns:3 %} |
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
#!/bin/bash | |
# On OS X 10.9 (see: http://stackoverflow.com/questions/19242275/sed-re-error-illegal-byte-sequence-on-mac-os-x) | |
# export LC_CTYPE=C | |
# export LANG=C | |
# http://stackoverflow.com/questions/149057/how-to-remove-trailing-whitespace-of-all-files-recursively | |
find . -not \( -name .svn -prune -o -name .git -prune \) -type f -print0 | xargs -0 sed -i '' -E "s/[[:space:]]*$//" |
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
import inspect | |
import functools | |
import Command | |
FORBIDDEN_SCHEMAS = {'public'} | |
def no_forbidden_schema(func): | |
"""Check if schema parameter is in FORBIDDEN_SCHEMAS.""" | |
@functools.wraps(func) | |
def wrapper(self, *args, **kwargs): |