Skip to content

Instantly share code, notes, and snippets.

View humanchimp's full-sized avatar

Chris Thorn humanchimp

View GitHub Profile
export function testRoutes() {
return function() {
this.post('/api/user/login', login());
};
function login() {}
}
/*
Fails jshint:
let pendingRequests = 0;
$(document)
.ajaxStart(() => { pendingRequests += 1; })
.ajaxStop(() => { pendingRequests -= 1; });
function andThen(callback) {
wait().then(callback);
}
let flip = (flopped => {
return function flip(fn) {
if (flopped.has(fn)) {
return flopped.get(fn);
}
flopped.set(fn, flipped);
flopped.set(flipped, fn);
return flipped;
import getAt from './get-at';
export default function injectTemplate(text, context) {
return String(text).replace(/(?:\{\{)([^}]*)(?:\}\})/g,
(placeholder, path) => getAt(context, path.split('.')));
}
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
name: '',
something: function() {
console.log('dirtied something');
return !!this.get('name');
$ grasp -e 'invoke($f, _$rest)' tests -r -R '() => {{f}}({{rest | join ", "}})' --in-place
@humanchimp
humanchimp / this-binding.js
Created January 18, 2017 23:48
method this binding in JS
cont foo = {
bar() { return this.baz },
baz() { console.log(this) },
}
foo.baz() // Logs `foo`
foo.bar().baz() // Logs `undefined`
@humanchimp
humanchimp / mouse-drags.js
Created March 25, 2017 02:50
observable toy
// from https://github.com/tc39/proposal-observable/blob/master/demo/mouse-drags.js
// Emits each element of the input stream until the control stream has emitted an
// element.
function takeUntil(stream, control) {
return new Observable(sink => {
let source = stream.subscribe(sink);
function guard(predicate, callback) {
return function guarded(reason) {
if (!predicate(reason)) {
throw reason;
}
return callback(reason);
};
}
function instanceOf(constructor, callback) {
import xs from 'xstream'
import {Sources, Sinks} from './interfaces'
const intent = (sources$: Sources) => sources$.DOM
.select('button')
.events('click')
.map(ev => 1);
const model = (intent$: any) => intent$
.fold((total, change) => total + change, 1);