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
#!/usr/bin/env python | |
from flask import Flask, render_template, Markup | |
from flask.ext.bootstrap import Bootstrap | |
import markdown2 | |
app = Flask(__name__) | |
Bootstrap(app) | |
@app.route("/") |
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
#...somewhere above self.model = some SQLAlchemy model | |
def shoes(self): | |
filter1 = self.model.shoe == 'donkey' | |
self.model.query.filter(filter1) | |
def shoes2(self): | |
filters = [] | |
# filters.append(self.model.shoe <= 'donkey') | |
filters.append(getattr(operator, 'le')(self.model.shoe, 'donkey')) | |
filters.append(getattr(operator, 'eq')(self.model.donkey, 'shoe')) |
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
in upload handler | |
in file close | |
.. | |
---------------------------------------------------------------------- | |
Ran 2 tests in 0.021s | |
OK |
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
percentify = lambda number, percentage: float(number) * (percentage / 100) | |
restaraunt_tax_percentage = 6.75 | |
tip_percentage = 15 | |
meal = float(input("How much was the meal? $") or 44.50) | |
restaraunt_tax = percentify(meal, restaraunt_tax_percentage) | |
tip = percentify(meal + restaraunt_tax, tip_percentage) | |
print("Your tip should be ${:.2f}".format(tip)) |
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 Parent(object): | |
def __new__(cls, to, *args, **kwargs): | |
if hasattr(to, 'something'): | |
return object.__new__(Child) | |
return object.__new__(Parent) | |
def send(self): | |
raise RuntimeError('You must override the send method for this Parent subclass') |
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 multiprocessing import Process | |
import flask | |
app = flask.Flask(__name__) | |
autokill_time = 0 | |
thing_i_was_sent = '' | |
@app.route('/kill') |
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 flask import make_response | |
def protect_http_call(func): | |
""" | |
Decorator that handles all standard and fall-through exceptions for a REST view. Protect will swallow all exceptions. | |
Args: | |
func: Function to be wrapped and protected from raising | |
Returns: |
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
{ | |
"color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme", | |
"font_size": 17, | |
"ignored_packages": | |
[ | |
"Vintage" | |
], | |
"highlight_line": true, | |
"scroll_past_end": true, |
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
#!/usr/bin/env python | |
class BaseClass(object): | |
bar = 'baz' | |
class PantsMixin(object): | |
@property |
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 Singleton(type): | |
_instances = {} | |
def __call__(cls, *args, **kwargs): | |
if cls not in cls._instances: | |
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) | |
return cls._instances[cls] | |
NewerOlder