Skip to content

Instantly share code, notes, and snippets.

@akre54
akre54 / react-svg-patch.coffee
Last active November 23, 2015 18:02
React SVG element monkeypatch
ReactDOM = require 'react/lib/ReactDOM'
ReactElement = require 'react/lib/ReactElement'
ReactElementValidator = require 'react/lib/ReactElementValidator'
SVGDOMPropertyConfig = require 'react/lib/SVGDOMPropertyConfig'
MUST_USE_ATTRIBUTE = DOMProperty.injection.MUST_USE_ATTRIBUTE
createFactory = if __DEV__
ReactElementValidator.createFactory
else
ReactElement.createFactory
@akre54
akre54 / backbone.fetch.js
Last active November 22, 2023 19:10
Backbone.ajax with window.fetch
var defaults = function(obj, source) {
for (var prop in source) {
if (obj[prop] === undefined) obj[prop] = source[prop];
}
return obj;
}
var stringifyGETParams = function(url, data) {
var query = '';
for (var key in data) {
var jsdom = require('jsdom').jsdom;
global.document = jsdom();
global.window = document.parentWindow;
var Backbone = require('backbone');
Backbone.$ = require('jquery');
@akre54
akre54 / draw-circles.coffee
Last active August 29, 2015 14:04
Draw circles on canvas
{requestInterval, clearRequestInterval} = require './animation-helpers'
NUM_CIRCLES = 2500
MAX_RADIUS = 80
MIN_RADIUS = 4
bgCanvas = document.getElementById "bg"
fgCanvas = document.getElementById "fg"
bg = bgCanvas.getContext "2d"
fg = fgCanvas.getContext "2d"
@akre54
akre54 / frank.txt
Created May 23, 2014 13:22
Frank Costanza lines
Today, I went record shopping in Greenwich Village.
I bought this record, but I can't seem to find the hi-fi.
Didn't I give you my old record player?
Cosmo?
Who's Cosmo?
Well, I want it back.
I wanna listen to that cha-cha record.
(putting down the bowl) Lemme change my shirt.
Thank you, Kramer.
(indicating a chair) Put it over there.
@akre54
akre54 / handlebars_helper.js
Created April 22, 2014 15:11
Handlebars for mocha with browserify
var Handlebars = require('handlebars'),
fs = require('fs');
require.extensions['.hbs'] = function (module, filename) {
var raw = fs.readFileSync(filename, 'utf8');
return Handlebars.compile(raw);
}
@akre54
akre54 / parser.coffee
Created March 29, 2014 15:26
KML to GeoJSON
fs = require 'fs'
xml2js = require('xml2js').parseString
fs.readFile "#{__dirname}/history.kml", (err, data) ->
xml2js data, (err, result) ->
doc = result.kml.Document[0].Placemark[0]['gx:Track'][0]
points =
type: "Feature"
properties: {}
@akre54
akre54 / dropdown-option.hbs
Last active August 29, 2015 13:56
Chaplin dropdown
<label>
<input class="dropdown__item__toggle" type="checkbox"></input>
{{title}}
</label>
var rules = [], each = [].forEach;
each.call(document.styleSheets, function(s) {
s.cssRules && each.call(s.cssRules, function(rule) {
rule.media && rules.push(rule.media[0]);
})
});
@akre54
akre54 / Slider.js
Last active December 28, 2015 00:49
var runner = document.querySelector('.ticker'), // a <ul>
frames = runner.children,
timeout = 4000; // in ms
var cycleFrames = function() {
var child = runner.removeChild(frames[0]).cloneNode(true);
runner.appendChild(child);
}
// from https://gist.github.com/joelambert/1002116