Skip to content

Instantly share code, notes, and snippets.

View leebyron's full-sized avatar
🌎

Lee Byron leebyron

🌎
View GitHub Profile
@leebyron
leebyron / index.js
Last active August 29, 2015 14:07
Immutable vs transducers.js (operation only)
var Benchmark = require('benchmark');
var t = require('transducers.js');
var Immutable = require('immutable');
var suite = Benchmark.Suite('transducers');
function benchArray(n) {
var arr = new Immutable.Range(0, n).toVector();
var transform = t.compose(
t.map(function(x) { return x + 10; }),
@leebyron
leebyron / index.js
Last active August 29, 2015 14:07
Immutable vs transducers.js (inline)
var Benchmark = require('benchmark');
var t = require('transducers.js');
var Immutable = require('immutable');
var suite = Benchmark.Suite('transducers');
function benchArray(n) {
var arr = new Immutable.Range(0, n).toVector();
suite
.add('Immutable map/filter (' + n + ')', function() {
@leebyron
leebyron / geocode
Created October 14, 2014 21:50
Simple geocoder
class Geocoder{
// google maps api key
String apiKey;
Geocoder(String apiKey){
this.apiKey = apiKey;
}
double[] locate(String location){
var data = {...}
var react = React.renderComponentToString(<Component data={data} />);
writeToClient(
'<html><head><script src="myCompiledJS.js"></script></head>' +
'<body><div id="foo">' + react + '</div>' +
'<script>React.renderComponent('+
'Component({data:'+ JSON.stringify(data) + '}), document.getElementById("foo")'+
')</script>' +
'</body></html>'
function handleClick(element, event) {
if (event.button === 1) {
return { count: 0 };
}
if (element.props.onClick) {
element.onClick();
}
element.updateState(s => {...s, count: s.count + 1 });
}
@leebyron
leebyron / index.js
Created November 11, 2014 22:44
requirebin sketch
var insertCSS = require('insert-css')
insertCSS('.foo { color: red; }')
var React = require('react/addons');
var CSSCore = require('react/lib/CSSCore');
window.r = React;
var Component = React.createFactory(React.createClass({
render: function() {
@leebyron
leebyron / index.js
Created November 20, 2014 01:05
requirebin sketch
/*
This is a trivial example of using Immutable structures as React state.
Note that replaceState() must be used instead of setState(), as setState expects
an object literal and will merge it (Object.assign) with the previous state.
replaceState() is a simple swap.
*/
@leebyron
leebyron / gist:755227877ce47077e16d
Created November 21, 2014 02:18
Jasmine matcher for Immutable
beforeEach(function () {
this.addMatchers({
is: function(expected) {
return Immutable.is(this.actual, expected);
}
})
})
@leebyron
leebyron / gist:d4ad335f833389642af8
Created December 29, 2014 03:53
Unsubscribe from all Amazon Birthday Alerts
/*
At some point I connected Facebook friends to Amazon wishlists. Now I get
multiple emails from Amazon for the birthday of everyone I ever met.
Removing people from this list requires a bunch of manual clicking.
Automation FTW.
1) http://www.amazon.com/gp/registry?ie=UTF8&type=wishlist
@leebyron
leebyron / es6_import.js
Last active August 29, 2015 14:13
ES6 import -> CJS example
import * as foo from "foo"
var $foo = require("foo");
var foo = $foo;
import foo from "foo"
var $foo = require("foo");
var foo = $foo.default;
import { foo } from "foo"
var $foo = require("foo");