Skip to content

Instantly share code, notes, and snippets.

💭
I may be slow to respond.

David Aurelio davidaurelio

💭
I may be slow to respond.
  • Munich, Germany
Block or report user

Report or block davidaurelio

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View output-beautified.js
!function() {
function n() {
for (var n = arguments.length, e = Array(n), r = 0; r < n; r++) e[r] = arguments[r];
return "(s*(" + e.join(")s*,s*(") + ")s*)";
}
new RegExp("rgb" + n()), new RegExp("rgba" + n()), new RegExp("hsl" + n()), new RegExp("hsla" + n());
}();
View repro.js
var u = require('uglify-es');
var code = `
(function() {
var NUMBER = '[-+]?\\d*\\.?\\d+';
var PERCENTAGE = NUMBER + '%';
function call() {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
@davidaurelio
davidaurelio / container.js
Created Mar 4, 2015
React: custom validator for type of children
View container.js
const {forEach} = React.Children;
class Child extends React.Component { /**/ }
class Container extends React.Component { /**/ }
Container.propTypes = {
children: function(props, propName, componentName) {
forEach(props[propName], (element) => {
const {type} = element;
if (type !== Child) {
@davidaurelio
davidaurelio / admin.py
Created Dec 13, 2014
Versioned slug model
View admin.py
from django.contrib import admin
from .models import MainThing, MainThingSlug
class SlugInline(admin.StackedInline):
model = MainThingSlug
fields = ('slug',)
can_delete = False
View voidbot.js
/**
@license
Copyright 2014 David Aurelio <dev@david-aurelio.com>
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;
@davidaurelio
davidaurelio / .profile
Last active Dec 20, 2015
bash helper function to make debugging node cli programs easier.
View .profile
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)
}
@davidaurelio
davidaurelio / partial.js
Created Apr 30, 2013
Simple higher-order partial function that takes advantage of sparse arrays to make parameters skippable.
View partial.js
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);
};
}
@davidaurelio
davidaurelio / async.js
Created Mar 28, 2013
Naïve parallel/chain implementation for asynchronous functions taking node-style callbacks
View async.js
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 {
View lazyProperty-example.js
/**
* From AS2:
* class A {
* var foo = 5;
* }
*
* class A extends B {
* var foo = 6;
* }
*/
@davidaurelio
davidaurelio / lazy-property.js
Created Dec 3, 2012
Lazy properties for ES5
View lazy-property.js
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,
You can’t perform that action at this time.