Skip to content

Instantly share code, notes, and snippets.

View sym3tri's full-sized avatar
🌴
On vacation

Ed Rooth sym3tri

🌴
On vacation
View GitHub Profile
@sym3tri
sym3tri / proto.js
Last active January 10, 2019 09:14
Explanation of prototypes
// http://dailyjs.com/2012/11/26/js101-proto/
var assert = require('assert');
function User() {
}
var user = new User();
assert.equal(user.__proto__, User.prototype);
@sym3tri
sym3tri / function.js
Created November 28, 2012 17:57
JS function behind the scenes
// Every time you define a function it's as if all this happens behind the scenes...
function foo() {
// var arguments = new array-like object corresponding to the function arguments
// foo.length = number of parameters in function definition (different from arguments.length);
// foo.name = 'foo';
// foo.prototype = {};
// foo.constructor = Function;
//// (only if no explicit return statement exists and is not invoked with 'new' operator)
function mixin(receiver, supplier) {
Object.keys(supplier).forEach(function(property) {
Object.defineProperty(receiver, property, Object.getOwnPropertyDescriptor(supplier, property));
});
}
var name = 'Ed',
supplier = {
get name() {
return name;
@sym3tri
sym3tri / monad.js
Last active February 24, 2020 02:31
Simple Monad example in JavaScript
// as discussed by Crockford here: http://www.youtube.com/watch?v=dkZFtimgAcM
// more detailed example here: https://github.com/douglascrockford/monad/blob/master/monad.js
function MONAD() {
return function unit(value) {
var monad = Object.create(null);
monad.bind = function (func) {
return func(value);
};
return monad;
@sym3tri
sym3tri / svg-spinner.js
Last active December 10, 2015 23:08
A pure svg spinner generated with d3. Play with this here: http://enjalot.com/inlet/4513075/
// tweak these options
var lineTotal = 16,
lineLength = 30,
speed = 1.28,
width = 1.96,
radius = 16,
color = '#333',
// dont touch these
posX = 100,
@sym3tri
sym3tri / _.md
Created January 11, 2013 19:03
pure svg spinner generator
@sym3tri
sym3tri / _.md
Created January 18, 2013 18:41 — forked from anonymous/config.json
An inlet to Tributary
@sym3tri
sym3tri / viewbox.js
Created January 25, 2013 22:14
A simple example of auto-resize using svg viewBox.
var svg = d3.select('#container').append('svg')
.attr({
viewBox: '0 0 1000 1000',
});
svg.append('rect')
.attr({
width: '1000',
height: '1000'
});
angular.module('myServices')
.factory('visibilityBroadcaster', function($rootScope, $document, _) {
var document = $document[0],
features,
detectedFeature;
features = {
standard: {
eventName: 'visibilitychange',
@sym3tri
sym3tri / _.md
Created March 14, 2014 05:58
arc percent (incomplete)