Skip to content

Instantly share code, notes, and snippets.

Generators vs Fibers

Both ES6 generators and node-fibers can be used to block a coroutine while waiting on some I/O without blocking the entire process. Both can do this for arbitrarily deep call stacks. The main difference between the capabilities of the two is how explicit the syntax is.

Generators - Safe, but Explicit

In code that uses ES6 generators:

var run = require('gen-run'); // https://github.com/creationix/gen-run
global
daemon
defaults
mode http
timeout connect 86400000
timeout server 86400000
timeout client 86400000
timeout check 5s
javascript:( function() {
console.group( 'Performance Information for all entries of ' + window.location.href );
console.log( '\n-> Duration is displayed in ms\n ' )
var entries = window.performance.getEntries();
entries = entries.sort( function( a, b ) {
return b.duration - a.duration;
} );
function inNetwork(){
var thingie = 0
var next = function(){
console.log("herp", thingie)
thingie++
if(thingie < 10)
//registers next
setTimeout(next, 0);
}
//registers first
@iksose
iksose / gist:feeb9693d5d45a234095
Last active August 29, 2015 14:02
atom angular.js atom syntax
{
"match": "(?<!\\.)\\b(.forEach|.then)(?!\\s*:)\\b",
"name": "entity.name.function.js"
},
// matches .then & .forEach
{
"match": "(?<=\\).)(t(he(n)))\\b",
"name": "entity.name.function.js"
var OAuth2 = require('OAuth').OAuth2;
var https = require('https');
var oauth2 = new OAuth2(KEY, SECRET, 'https://api.twitter.com/', null, 'oauth2/token', null);
oauth2.getOAuthAccessToken('', {
'grant_type': 'client_credentials'
}, function (e, access_token) {
console.log(access_token); //string that we can use to authenticate request
var options = {
<ul>
<li ng-repeat="item in items | orderObjectBy:'color':true">{{ item.color }}</li>
</ul>
@iksose
iksose / uri.js
Created August 24, 2014 15:39 — forked from jlong/uri.js
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@iksose
iksose / gist:4ca3772785f54005123a
Last active August 29, 2015 14:12
es6 symbols
const privateFoo = Symbol("foo");
function Public() {
this[privateFoo] = "bar";
}
Public.prototype.method = function () {
// Do stuff with `this[privateFoo]`...
};
import queryString from "query-string";
let _route = "api/v2.0/";
const headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
};
const verbs = {