Skip to content

Instantly share code, notes, and snippets.

Gorgi Kosev spion

Block or report user

Report or block spion

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View deferred-promise-use-case.js
// 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 Nov 27, 2018 — forked from unscriptable/flowcart.js
A typesafe shopping cart in typescript
View flowcart.ts
// 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;
}
@spion
spion / functional.js
Last active Dec 6, 2015 — forked from Arnavion/async-await.ts
Promise.any - async/await vs then()
View functional.js
let pending = new Promise((r,rj) => {})
let waitForever = () => pending
let reject = Promise.reject.bind(promise)
let identity = x => x
let promiseTransform = fns => p => p.then(fns.fullfilment, fns.rejection)
function any(promises) {
let fulfillments = promises.map(promiseTransform({fullfilment: identity, rejection: waitForever}))
let rejections = promises.map(promiseTransform({fullfilment: waitForever, rejection: identity}))
let firstFulfill = Promise.race(fulfillments);
View existing.sql
create table male
( male_id int not null
, primary key (male_id) );
create table female
( female_id int not null
, primary key (female_id) );
create table name
( id int not null
View table.ts
/// <reference path="anydb-sql.d.ts" />
import anydbsql = require('anydb-sql');
var db = anydbsql({
url: 'postgres://user:pass@host:port/database',
connections: { min: 2, max: 20 }
});
// Table Post
@spion
spion / 01-future.js
Last active Jun 26, 2016 — forked from robotlolita/0-specification.md
Future and ReaderT with auto-lifting and example
View 01-future.js
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;
View coded-error.js
export class CodedError extends Error {
constructor(code, msg) {
super(msg)
this.code = code;
this.msg = msg;
}
static is(code) {
return (e) => e.code == code;
}
static only(code, handler) {
View gist:56f539481d8a8ffa0ac0
var raven = require('raven')
, Promise = require('bluebird')
, requestAsync = require('request-promise')
var redis = Promise.promisifyAll(require('redis').createClient())
var languages = JSON.parse(require('fs').readFileSync(__dirname + '/languages.json')).languages
Promise.all(languages.map(function(language){
return redis.setAsync('lang:'+language.tag+':name', language.name)
View pipe-promises.js
exports.pipe = function (source, sink) {
var resolve, reject;
return new Promise(function(resolve_, reject_) {
resolve = resolve_;
reject = reject_;
source
.on("error", reject)
.pipe(sink)
.on("error", reject);
.on("finish", resolve);
View gist:8673903
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) {
You can’t perform that action at this time.