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
open Core.Std | |
(* r = t * a + s * b *) | |
type step = { r : int; t : int; s : int } | |
let euler a b = | |
let rec loop cur prev history = | |
(* prev.r = q * cur.r + next.r *) | |
let q = prev.r / cur.r in | |
(* next.r = prev.r - q * cur.r |
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.after_request | |
def add_no_cache(response): | |
if request.endpoint != "static": | |
response.headers[b"Cache-Control"] = "no-cache" | |
response.headers[b"Pragma"] = "no-cache" | |
return response |
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/make | |
# -*- makefile -*- | |
figures = $(wildcard figure_*.pdf) | |
report.ipynb.tex : report.ipynb ../nbconvert.tplx | |
ipython3 nbconvert \ | |
--to latex \ | |
--template nbconvert \ | |
--ExtractOutputTransformer.enabled=False \ |
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
current_section = null | |
static_section = null | |
sections = null | |
url_map = {} | |
history_enable = null | |
hash_enable = null | |
log = (msg) -> console?.log? "history.coffee: #{msg}" | |
change = (to, animation="change") -> |
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 __future__ import print_function | |
# some library | |
class Base(object): | |
def method(self): | |
return "This is hard to stub" | |
# my code | |
class UUT(Base): | |
def method(self): |
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
import os | |
from os.path import dirname, realpath | |
from os.path import join as path_join | |
from flask import Flask | |
from flask.helpers import send_from_directory | |
from raven.flask_glue import AuthDecorator | |
app = Flask(__name__) | |
assert not app.has_static_folder |
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
import sys | |
import datetime | |
# expect either a single line >> assert {.... dicta ....} == {.... dictb ....} | |
# (as produced from nosetests -d assertion failures) | |
# or two dicts, on two separate lines. | |
# obviously the former breaks if == appears in a key or value... | |
line = sys.stdin.readline() |
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 format_datetime(datetime, format_name="nice short", | |
custom_format=None, convert_bst=True): | |
""" | |
Jinja2 filter to turn a datetime into a string | |
`datetime` must be timezone-naive (as far as python is concerned), | |
but its values must be UTC. | |
Either pick `format_name` from the options below, or provide | |
`custom_format` |
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 send_email(template, recipient, | |
sender=("Jinja email Gist", "[email protected]"), | |
**kwargs): | |
""" | |
Send an email, acquiring its payload by rendering a jinja2 template | |
:type template: :class:`str` | |
:param template: name of the template file in ``templates/emails`` to use | |
:type recipient: :class:`tuple` (:class:`str`, :class:`str`) | |
:param recipient: 'To' (name, email) |
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
@contextlib.contextmanager | |
def with_savepoint(postgres, name="temp_savepoint"): | |
""" | |
A context manager that wraps database queries in a PostgreSQL savepoint | |
Usage:: | |
with with_savepoint(postgres, name='my_savepoint) as rollback: | |
do_something() | |
if something: |