Skip to content

Instantly share code, notes, and snippets.

View spion's full-sized avatar
:shipit:

Gorgi Kosev spion

:shipit:
View GitHub Profile
@spion
spion / README.md
Last active January 2, 2016 05:08 — forked from ithinkihaveacat/README.md

Comparison of two different approaches to structuring code that uses Promises.

Version using .then(), from Complex task dependencies:

files.getLastTwoVersions(filename)
    .then(function(items) {
        return [versions.get(items.last), 
                versions.get(items.previous)];
    })
function nextRequire(prevWorkDone) {
if(requires.length) {
return stage(requires.shift(), true, options).then(function(workDone) {
anyWorkDone = anyWorkDone || workDone;
return nextRequire();
});
} else {
return work(rules, options, isChild, anyWorkDone);
}
}
@spion
spion / proxy.js
Last active January 4, 2016 06:19 — forked from whoeverest/proxy.js
var http = require('http');
var proxy = require('http-proxy').createProxyServer({ target: 'https://192.168.88.167:5000/', secure: false });
http.createServer(proxy.web.bind(proxy))
.on('upgrade', proxy.ws.bind(proxy))
.listen(4433);
var fez = require("../../src/main.js"),
less = require("fez-less"),
clean = require("fez-clean-css"),
concat = require("fez-concat");
// Example starting files:
// css/reset.css; main.less; mobile.less
exports.build = function(spec) {
@spion
spion / 01-future.js
Last active June 26, 2016 20:52 — forked from robotlolita/0-specification.md
Future and ReaderT with auto-lifting and example
class Future {
constructor(computation) {
this.fork = computation
this.__future__ = true;
}
static is(val) {
return (val != null && val.__future__ === true)
}
static of(value) {
if (Future.is(value)) return value;
// These theoretical API requests are deferred promises;
// Not executed until `.then()` is invoked.
let a = new Request('/foo');
let b = new Request('/bar');
let c = new Request('/baz');
// If invoked directly, then issue 3 direct HTTP requests:
Promise.all([ a, b, b ]).then((results) => {
// GET /foo
// GET /bar
@spion
spion / flowcart.ts
Last active November 27, 2018 00:16 — forked from unscriptable/flowcart.js
A typesafe shopping cart in typescript
// A typesafe shopping cart in typescript.
// Immutable map :)
declare class Map<T, U> {
set(t:T, u:U):Map<T, U>
has(t:T):boolean;
delete(t:T):Map<T,U>
count:number;
}