Skip to content

Instantly share code, notes, and snippets.

View futurist's full-sized avatar

James Yang futurist

  • China
View GitHub Profile
@futurist
futurist / module.js
Created December 2, 2015 10:19
Mini module system for the browser with hot swapping and remote loading support, 750 bytes minified+gzipped
/**
* This file contains a primitive JS/resource loader and resolver that can load
* both local and remote files.
*
* API usage:
*
* ```js
* r.define("foo", function () { return "default export" })
*
* r.define("assert", function () {
@futurist
futurist / benchmark+go+nginx.md
Created December 25, 2015 02:24 — forked from hgfischer/benchmark+go+nginx.md
Benchmarking Nginx with Go

Benchmarking Nginx with Go

There are a lot of ways to serve a Go HTTP application. The best choices depend on each use case. Currently nginx looks to be the standard web server for every new project even though there are other great web servers as well. However, how much is the overhead of serving a Go application behind an nginx server? Do we need some nginx features (vhosts, load balancing, cache, etc) or can you serve directly from Go? If you need nginx, what is the fastest connection mechanism? This are the kind of questions I'm intended to answer here. The purpose of this benchmark is not to tell that Go is faster or slower than nginx. That would be stupid.

So, these are the different settings we are going to compare:

  • Go HTTP standalone (as the control group)
  • Nginx proxy to Go HTTP
  • Nginx fastcgi to Go TCP FastCGI
  • Nginx fastcgi to Go Unix Socket FastCGI
@futurist
futurist / index.html
Created December 25, 2015 23:46 — forked from anonymous/index.html
JS Bin j2c mithril demo // source http://jsbin.com/qoxaze
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="j2c mithril demo">
<meta charset="utf-8">
<title>JS Bin</title>
<script src="https://rawgit.com/lhorie/mithril.js/next/mithril.min.js"></script>
<script src="https://rawgit.com/pygy/j2c/next/dist/j2c.global.js"></script>
</head>
@futurist
futurist / gist:f3815f2989e51dc03810
Created December 27, 2015 00:42
Mongoose populate an array
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId;
mongoose.connect('mongodb://localhost/testy2');
var UserSchema = new Schema({
name: String
});
@futurist
futurist / make-http-request.js
Created January 5, 2016 01:27
node make-http-request
var request = require('request');
var http = require('http');
request.get('http://1111hui.com:4000/organizations/5673c95ae3b3e6e54937ede1/relationships/liaisons').on('response', function(res, body) {
console.log(res.statusCode, body)
})
var postData = JSON.stringify(
{"data":[ { "type": "people", "id": "567364ce9f62d7e72ae5f7f3" }] }
);
@futurist
futurist / yield.md
Created January 6, 2016 06:16 — forked from lukehoban/yield.md
Precedence of `yield` in ES6
// Current ES spec grammar
1 + yield //  error
1 + yield 2 //  error
yield + 1 // yield (+1)
yield 1 + yield 2 // error
yield(1) + yield(2) // error
yield 1 + 2 // yield (1+2)
yield * yield // (yield *) yield
yield + yield // error
@futurist
futurist / co.js
Created January 6, 2016 06:54 — forked from oklai/co.js
co.js simple
'use strict';
/**
* co.js simple
*/
// api
//
// var co = require('co');
//
@futurist
futurist / readme.md
Created January 8, 2016 04:51 — forked from coolaj86/how-to-publish-to-npm.md
How to publish packages to NPM

Getting Started with NPM (as a developer)

If you haven't already set your NPM author info, now you should:

npm set init.author.name "Your Name"
npm set init.author.email "you@example.com"
npm set init.author.url "http://yourblog.com"

npm adduser

var errors = {
// JSHint options
E001: "Bad option: '{a}'.",
E002: "Bad option value.",
// JSHint input
E003: "Expected a JSON value.",
E004: "Input is neither a string nor an array of strings.",
E005: "Input is empty.",
E006: "Unexpected early end of program.",
@futurist
futurist / gist:e247ad88eacd189ce76e
Created January 19, 2016 00:47 — forked from bartaz/gist:1119041
Convert JavaScript number to string of 64bit double precision floating point representation (IEEE 754)
// Convert a JavaScript number to IEEE-754 Double Precision
// value represented as an array of 8 bytes (octets)
//
// http://cautionsingularityahead.blogspot.com/2010/04/javascript-and-ieee754-redux.html
function toIEEE754(v, ebits, fbits) {
var bias = (1 << (ebits - 1)) - 1;
// Compute sign, exponent, fraction