Skip to content

Instantly share code, notes, and snippets.

View leebyron's full-sized avatar
🌎

Lee Byron leebyron

🌎
View GitHub Profile
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");
<!DOCTYPE html>
<html>
<head>
<script src="http://fb.me/react-with-addons-0.12.0.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
<!DOCTYPE html>
<html>
<head>
<script src="http://fb.me/react-with-addons-0.12.0.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
[ -z "$PS1" ] && return
# first load in the master bash
if [ -f /etc/master_bash ]; then
. /etc/master_bash