This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
NewerOlder