Skip to content

Instantly share code, notes, and snippets.

View iansinnott's full-sized avatar

Ian Sinnott iansinnott

View GitHub Profile
import React from 'react';
import { render } from 'react-dom';
import { Router } from 'react-router';
import createBrowserHistory from 'history/lib/createBrowserHistory';
import routes from './routes.js';
const history = createBrowserHistory();
// Setup google analytics tracking for react router transtions
@iansinnott
iansinnott / README.md
Created March 21, 2016 18:41
Babel ES6 Example
import ms from 'ms';
import Rx from 'rxjs/Rx';
const clicks$ = Rx.Observable.fromEvent(document.body, 'click');
const createActionStream = () => Rx.Observable.merge(
Rx.Observable.of({ type: 'warning' }).delay(ms('14m')),
Rx.Observable.of({ type: 'logOut' }).delay(ms('15m'))
);
@iansinnott
iansinnott / debounce-vs-throttle.js
Last active September 14, 2016 20:49
Debounce vs. Throttle (Rx.js v5)
// Just look the console output.
// NOTE: Requires Rx.js v5.x
var mousemoves$ = Rx.Observable.fromEvent(document.body, 'mousemove');
// Events will be fired at most once every 200ms
var throtttled = mousemoves$.throttleTime(200);
// The latest event will be fired after 200ms. This means that if you are continually
// moving your mouse around the browser, causing mousemove events, none of them will
@iansinnott
iansinnott / .block
Created September 26, 2016 15:35
Collision Detection
license: gpl-3.0
const bleh = ['b', 'c', 'd'];
// Want arr === ['a', 'b', 'c', 'd']
const arr = [ 'a', ...bleh ]; // ['a', 'b', 'c', 'd']
// Also for objects
const basicInfo = {
name: 'Person',
document.addEventListener('click', (e) => {
console.log(`The node that was clicked was ${e.target.toString()}`);
});
@iansinnott
iansinnott / .block
Last active November 1, 2016 18:00
Tick Format
license: gpl-3.0
@iansinnott
iansinnott / XHR.js
Created November 2, 2016 07:06
Quick XHR API intro
const ajax = (method, url, success) => {
// Create the new XHR
const xhr = new XMLHttpRequest();
// "Open" the request. I.e. configure its method and request URL
xhr.open(method, url);
// Set up a success handler. For XHR we need to respond to changes in the readyState. However,
// the readyState can change for a number of reasons and we are only interested in the change
// that represents completion of the request. So we check whether readyState is equal to
@iansinnott
iansinnott / .block
Last active November 9, 2016 17:25
Draggable Network II
license: gpl-3.0