Instantly share code, notes, and snippets.

💭
I may be slow to respond.

# David Aureliodavidaurelio

💭
I may be slow to respond.
• Sort options
Created Sep 7, 2012
`super` using `Proxy.create`
View super-proxy.js
 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); } }
Created Sep 7, 2012
Naive implementation of super in JS
View naive-super.js
 Object.defineProperty(Object.prototype, 'super', { get: function() { return Object.getPrototypeOf(this); } }); function Foo() {} Foo.prototype.reset = function() { this.fooProp = 'reset'; console.log('Foo#reset()'); }
Created Jul 18, 2012
A Point class that supports addition and subtraction of instances. Precision is 16bit fixed point per coordinate.
View point.js
 /* 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)
Created Jul 18, 2012
A toString()’able point that allows addition
View point.js
 function Point(x, y) { if (arguments.length === 1 && typeof x === 'string') { return x.slice(1, -1) .split('}{') .map(function(tuple) { return tuple.split(',', 2).map(parseFloat) }) .reduce(function(point, coords) { point.x += coords[0]; point.y += coords[1];
Created Apr 2, 2012
Angle type
View Usage
 var a = new Angle().radians(Math.PI * 3 / 4), b = new Angle().degrees(135); var c = new Angle(a + b); Math.sin(a); Math.cos(b); a.add(new Angle().degrees(30)); b.add(Math.PI);
Created Mar 22, 2012
Constructable mixins in JavaScript
View EventEmitter.js
 /* EventEmitter is usable as constructor and as mixin. */ function EventEmitter() {} // this does the trick EventEmitter.prototype = EventEmitter; EventEmitter.addListener = function(type, listener) { this.listeners(type, true).push(listener);
Created Sep 6, 2011
Checking for touch support
View hastouch.html
 has touch?

Has this device touch?

Created Feb 22, 2011
Constructor-less inheritance for ECMAScript 5
View create.js
 var BaseObject = { create: function create() { var instance = Object.create(this); instance._construct.apply(instance, arguments); return instance; }, extend: function extend(properties, propertyDescriptors) { propertyDescriptors = propertyDescriptors || {};
Created Sep 1, 2010
View jilorg_fix_filenames.py
 #!/usr/bin/env python """ Fixes file names for downloads from jil.org. jil.org delivers downloaded files with file names in e-mail header format. The fix_filename function from this module can decode such file names. When this module is executed as main program, all file names passed as program arguments are renamed properly:
You can’t perform that action at this time.