Skip to content

Instantly share code, notes, and snippets.

View nijikokun's full-sized avatar
🍀
working

Niji nijikokun

🍀
working
  • Product Manager
  • San Diego, California
View GitHub Profile
@nijikokun
nijikokun / about.md
Last active August 29, 2015 13:55
Javascript parallelization explained using cars and roads, because people have a hard time understanding things.

Road.js

Parallelization made easy in JavaScript / Node.js

Usage

var road = new Road();

road.onClear(function (error, results) { 
@nijikokun
nijikokun / es8-wish.js
Last active August 29, 2015 14:02
ES8/Future
apis = []
foreach result in results do
await api = async client.getApiById
id: result.apiId
if !api continue
await api.account = do
async client.getAccountById
Built-in Atom packages (74)
├── archive-view@0.33.0
├── atom-dark-syntax@0.19.0
├── atom-dark-ui@0.32.0
├── atom-light-syntax@0.20.0
├── atom-light-ui@0.28.0
├── autocomplete@0.28.0
├── autoflow@0.17.0
├── autosave@0.14.0
├── background-tips@0.15.0
@nijikokun
nijikokun / gist:1d6fb5cf7add704fb440
Created September 25, 2014 03:57
Binary Alphabet
A 01000001
B 01000010
C 01000011
D 01000100
E 01000101
F 01000110
G 01000111
H 01001000
I 01001001
J 01001010
@nijikokun
nijikokun / meta.truncate.js
Created October 7, 2014 22:04
Function for truncating strings for description meta tag
function truncate (str, start, end) {
str = str.replace(/^\s\s*/, '').replace(/(\r|\n)+/, '').replace(/\s\s*$/, '');
var re = str.match(new RegExp('^.{' + (start || 0) + ',' + (end || 25) + '}[\S]*'));
var l = re[0].length;
var re = re[0].replace(/\s$/,'');
if (l < str.length) {
re += "&hellip;";
}
return re;
}
@nijikokun
nijikokun / atom.pack
Last active August 29, 2015 14:07
Installed atom packages
/Users/mashape/.atom/packages (68)
├── Stylus@0.3.1
├── Sublime-Style-Column-Selection@1.1.3
├── Watchmenesque-Dark@0.6.0
├── abw-syntax@0.1.0
├── api-blueprint-preview@0.2.2
├── ask-stack@0.1.0
├── atom-lint@0.20.0
├── atom-spotify@0.6.1 (disabled)
├── atomatigit@1.0.0

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns                     on recent CPU
L2 cache reference ........................... 7 ns                     14x L1 cache
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns                     20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs 4X memory

@nijikokun
nijikokun / serverObjectToHeaderString.js
Last active August 29, 2015 14:09
Create raw HTTP header string from request and response objects in nodejs (Express / Connect / Restify)
var util = require('util');
function setCharAt (str, index, chr) {
return (index > str.length - 1) ? str : str.substr(0, index) + chr + str.substr(index + 1);
}
function normalizeHeaderName (headerName) {
var pieces = headerName.split('-');
var length = pieces.length;
var index = 0;
@nijikokun
nijikokun / getServerIPv4Address.js
Created November 19, 2014 11:52
Get server IPv4 address in nodejs
var os = require('os');
var networkInterfaces = os.networkInterfaces();
function getServerAddress () {
for (var name in networkInterfaces) {
var face = networkInterfaces[name];
for (var i = face.length; i--;) {
var alias = face[i];
@nijikokun
nijikokun / parseResponseHeaderString.js
Last active August 29, 2015 14:10
Parse respone header string, request status line is different.
function parseResponseHeaderString (string) {
var output = {};
var lines = string.split('\r\n');
var status = lines.shift();
function parseStatusLine (line) {
var pieces = line.split(' ');
var versionNumberPieces;
var versionPieces;