Skip to content

Instantly share code, notes, and snippets.

View medikoo's full-sized avatar

Mariusz Nowak medikoo

View GitHub Profile

This is an attempt at getting a promise library to run as fast as native callbacks while still offering Promises/A+ compatability. It was sparked by these tweets:

@izs

We would not give up perf in core. You can already do this in userland if you have diff priorities.

@forbeslindesay:

It would take some work to optimise and you couldn’t use something like Q, but I’d be surprised if it couldn’t be done.

@WebReflection
WebReflection / Object.setPrototypeOf.js
Last active February 24, 2018 04:13
Object.setPrototypeOf(O, proto) full/complete polyfill with boolean flag for partial implementation.
/*jslint devel: true, indent: 2 */
// 15.2.3.2
if (!Object.setPrototypeOf) {
Object.setPrototypeOf = (function(Object, magic) {
'use strict';
var set;
function checkArgs(O, proto) {
if (typeof O !== 'object' || O === null) {
throw new TypeError('can not set prototype on a non-object');
}
// Accepts a map function, return a push-filter function.
function mapToPush(map) {
return function (emit) {
return function (err, item) {
if (item === undefined) return emit(err);
emit(null, map(item));
};
};
}
@domenic
domenic / promises.md
Last active April 1, 2025 01:54
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@domenic
domenic / oauth2-restify.js
Created June 2, 2012 06:25
OAuth2 with Restify
"use strict";
var restify = require("restify");
var users = require("./users");
// The users module will have a getAuthorizationFromAccessTokenAsync promise-returning export. (Convert to callbacks if you wish).
// It rejects in cause of not authorized, or fulfills with a { scope, customerId } object if the user is authorized.
// The scope property indicates which scopes the user corresponding to a given access token has.
module.exports = function authPlugin(serverRequest, serverResponse, next) {
@jed
jed / after.js
Created October 19, 2011 20:54
crushing 1000 booleans
a="[                                      true]";for(b in c="         true,false,false,true,".split(""))a=a.replace(RegExp(c[b][0],"g"),c[b].slice(1));eval(a)
//
// ### function randomString (bits)
// #### @bits {integer} The number of bits for the random base64 string returned to contain
// randomString returns a pseude-random ASCII string which contains at least the specified number of bits of entropy
// the return value is a string of length ⌈bits/6⌉ of characters from the base64 alphabet
//
helpers.randomString = exports.randomString = function (bits) {
var chars, rand, i, ret;
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-';