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
from render import render | |
def some_context(request): | |
return {…} | |
def some_different_context(request): | |
return {…} | |
@render("template.html") |
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
function monkeyPunch<A, B extends A>(o:A, extend:(o:B)=>void) { | |
var o2 = <B>Object.create(o); | |
extend(o2); | |
return o2; | |
} | |
interface Foo { | |
name: string; | |
} |
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 Animal { | |
constructor(public name) {} | |
toString() { return this.name; } | |
} | |
class Dog extends Animal { | |
fetch (thing:any) { | |
alert("fetching: " + thing); |
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
(require '[clojure.string :as str]) | |
(->> (map (comp rand-nth | |
(group-by first (seq (.split (slurp "/usr/share/dict/words") "\n"))) | |
char) | |
[121 111 108 111]) | |
(str/join " ") | |
print) |
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
"""This is an alternate typescript handler from future webassets as there | |
is a bug in the 0.8 version with recent tsc | |
""" | |
import os | |
import subprocess | |
import tempfile | |
from io import open # Give 2 and 3 use same newline behaviour. | |
from webassets.filter import Filter, register_filter |
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
from sorl.thumbnail import get_thumbnail | |
def make_thumbnail_method(get_fn=lambda o:o.image, | |
dimensions="100x60", | |
crop="center"): | |
"""A function factory for producing admin_thumbnail methods. | |
""" | |
def admin_thumbnail(self): | |
image = get_fn(self) |
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
from django.db import models | |
class LambdaManager(models.Manager): | |
"""LambdaManager is a simple manager extension that is instantiated with a callable. | |
This callable is passed the query set by get_query_set so that it can perform any | |
additional transformations to it such as eg filtering. | |
""" | |
def __init__(self, f): |
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
function on_drag(el, handler) { | |
var el = $(el); | |
el.on("mousedown", function (e) { | |
var initial_x = e.clientY; | |
var initial_y = e.clientY; | |
function drag_handler(e) { | |
var delta_x = e.clientX - initial_x; | |
var delta_y = e.clientY - initial_y; |
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
// the first hack needed to support mutable refs in Roy is allowing in place edits | |
// to JS arrays | |
let aSet (arr:[#a]) (idx:Number) (v:#a) :[#a] = | |
Array.prototype.splice.call arr idx 1 v | |
arr | |
// wrapper type is currently a structural type rather than an ADT because I couldn't | |
// get ADTs to have an Array as a field | |
type Ref = {_val: [#a]} |
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
// parser | |
var _parser_global_state = null; | |
function ParseFailed () {}; | |
function run_parser(p, input_list) { | |
input_list = input_list.slice() | |
try { | |
var old_parser_input = _parser_global_state; | |