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.contrib import admin | |
from .models import MainThing, MainThingSlug | |
class SlugInline(admin.StackedInline): | |
model = MainThingSlug | |
fields = ('slug',) | |
can_delete = False | |
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
/** | |
@license | |
Copyright 2014 David Aurelio <[email protected]> | |
Full source at https://gist.github.com/davidaurelio/4bdafd219ebf610e8fc4 | |
*/ | |
(function() { | |
'use strict'; | |
var GIVE_UP = 0; | |
var NORTH = 1, EAST = 2, SOUTH = 3, WEST = 4; |
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
node-debug () { | |
PROGRAM="$(which $1)" # make sure we get an absolute path for programs in PATH | |
shift # remove the original program argument | |
set -- "$PROGRAM" "$@" # prepend the program path | |
node --debug-brk $@ & # start node in paused debug mode, send to background | |
node-inspector # start node inspector | |
kill %% # kill the background task (if still running) | |
} |
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 partial(fn, fixedArgs) { | |
return function() { | |
var args = fixedArgs.slice(), skipped = 0; | |
for (var i = 0, n = arguments.length; i < n; i++) { | |
while (i + skipped in args) { skipped++; } | |
args[i + skipped] = arguments[i]; | |
} | |
return fn.apply(this, args); | |
}; | |
} |
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
var concat = [].concat, slice = [].slice; | |
function chain(fns, initialArgs, callback) { | |
(function next(error) { // `next` is the callback for each chained function | |
if (error) { callback(error); return; } | |
var fn = fns.shift(); | |
if (fn) { | |
fn.apply(null, slice.call(arguments, 1).concat(next)); | |
} else { |
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 AS2: | |
* class A { | |
* var foo = 5; | |
* } | |
* | |
* class A extends B { | |
* var foo = 6; | |
* } | |
*/ |
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 lazyProperty(object, name, create) { | |
Object.defineProperty(object, name, { | |
configurable: true, // or false if defined on prototype objects | |
enumerable: false, | |
get: function() { | |
return this[name] = create(this); | |
}, | |
set: function(value) { | |
Object.defineProperty(this, name, { | |
configurable: true, |
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
Object.defineProperty(Object.prototype, 'super', { | |
value: function(Constructor) { | |
var context = this; | |
var superProto = Object.getPrototypeOf(Constructor.prototype); | |
return Proxy.create({ | |
get: function(_, name) { | |
return function() { | |
return superProto[name].apply(context, arguments); | |
} | |
} |
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
Object.defineProperty(Object.prototype, 'super', { | |
get: function() { return Object.getPrototypeOf(this); } | |
}); | |
function Foo() {} | |
Foo.prototype.reset = function() { | |
this.fooProp = 'reset'; | |
console.log('Foo#reset()'); | |
} |
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
/* | |
A point constructor that creates objects supporting addition and subtraction. | |
The "trick" is to use 32bit integers and stuff two fixed 16bit fixed point | |
numbers into them that represent the coordinates of the point. | |
This approach has problems with overflow. E.g. when adding two points (0, 2) | |
and (0, -2), the addition will cause the y values to overflow into the 17th | |
bit, which is part of the x-value. When subtracting two points, e.g. | |
(.00390625, 0) - (0, -128) |