Skip to content

Instantly share code, notes, and snippets.

@xgrommx
xgrommx / furp.ls
Last active August 29, 2015 14:21 — forked from brainrake/furp.ls
import prelude
Signal = -> new (class SignalClass
(register) ->
@handlers = []
register @send
send: (value) ~>
@_value = value
for handler in @handlers => handler value

Laravel-style DI in JavaScript

Honestly, coming from PHP, I really don't like the way dependencies are handled in JavaScript. Using require() or import either gives me a singleton object, or a class that I have to instantiate myself.

The DI container in Laravel is wonderful, and allows you to basically just ask for a dependency in a class constructor and it hands it to you. You can bind things to the container, but you can also resolve things without explicitly binding them, which I think is awesome.

@xgrommx
xgrommx / index.html
Last active August 29, 2015 14:21 — forked from biovisualize/index.html
<!DOCTYPE html>
<html >
<head>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
</head>
<body>
<div class="example_div"></div>
<script type="text/javascript">
var tooltip = d3.select("body")
.append("div")

Streams in JavaScript

The slides for this code.

Function used for printing in jsfiddle:

function out() {
    var a = Array.prototype.slice.call(arguments, 0);
    document.getElementById("debug").innerHTML += a.join(" ") + "\n";
@xgrommx
xgrommx / y-memo.js
Last active August 29, 2015 14:23 — forked from therealklanni/y-memo.js
let Ym = (f, x = {}) => (...args) => {
var y = JSON.stringify(args)
return x[y] || (x[y] = f(z => Ym(f, x)(z)).apply(this, args))
}
let fib = Ym(f => n => n === 0 ? n : n === 1 ? n : f(n - 1) + f(n - 2))
console.log('fib(1000)', fib(1000))
@xgrommx
xgrommx / app.js
Last active August 29, 2015 14:24 — forked from staltz/app.js
const Cycle = require('@cycle/core');
const CycleWeb = require('@cycle/web');
const makeHTTPDriver = require('@cycle/http');
const h = CycleWeb.h;
function main(responses) {
const GITHUB_SEARCH_API = 'https://api.github.com/search/repositories?q=';
// This essentially models when search requests are supposed
// to happen
@xgrommx
xgrommx / data.js
Last active August 29, 2015 14:24 — forked from jisaacks/data.js
var data = [{
date: new Date("Jan 01, 2013"),
data: 12
},{
date: new Date("Jan 02, 2013"),
data: 17
},{
date: new Date("Jan 03, 2013"),
data: 5
},{
@xgrommx
xgrommx / README.md
Last active August 29, 2015 14:24 — forked from jasondavies/LICENSE

An example of setting x- and y-scale domains (zooming) by selecting a rectangular region using the mouse. The original question required that it work in tandem with d3.behavior.zoom for panning, hence the checkbox for switching on the “zoom by rectangle” mode.

function Y(le) {
return (function (f) {
return f(f);
}(function (f) {
return le(function (x) {
return f(f)(x);
});
}));
}
const touchStart = Rx.Observable.fromEvent(window, 'touchstart').timestamp();
const touchMove = Rx.Observable.fromEvent(window, 'touchmmove');
const touchEnd = Rx.Observable.fromEvent(window, 'touchend').timestamp();
const touchAndHold = touchStart
.flatMap(() => touchEnd.takeUntil(touchMove), (x, y) => { start: x.timestamp, end: y.timestamp })
.filter(ts => (ts.end - ts.start) / 1000 > 2);
const subscription = touchAndHold.subscribe(
() => console.log('touch and hold!')