Skip to content

Instantly share code, notes, and snippets.

View adamrights's full-sized avatar

Adam Bedell adamrights

View GitHub Profile
@adamrights
adamrights / 0_reuse_code.js
Created September 23, 2015 19:38
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@adamrights
adamrights / test.html
Last active August 26, 2015 02:16 — forked from xmlking/test.html
Demonstrate streaming JSON data parsing with OboeJS lib. Client consuming streaming REST endpoint implemented using NodeJS/RxJava/Ratpack etc and -chunked transfer- encoding
<html>
<head>
<title>OboeJS demo</title>
<script src="https://rawgit.com/jimhigson/oboe.js/v2.1.2/dist/oboe-browser.min.js"></script>
</head>
<body>
<div ></div>
<ul id="content">
<li>AUD_CAD:</li>
</ul>
@adamrights
adamrights / Enum.es6.js
Last active August 26, 2015 02:14 — forked from xmlking/Enum.es6.js
JavaScript Enums with ES6, Type Checking and Immutability
export class EnumSymbol {
sym = Symbol.for(name);
value: number;
description: string;
constructor(name: string, {value, description}) {
if(!Object.is(value, undefined)) this.value = value;
if(description) this.description = description;
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
#!/bin/bash
# CentOS rbenv system wide installation script
# Forked from https://gist.github.com/1237417
# Installs rbenv system wide on CentOS 5/6, also allows single user installs.
# Install pre-requirements
yum install -y gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel openssl-devel \
make bzip2 autoconf automake libtool bison iconv-devel git-core
module.exports = function(config) {
config.set({
frameworks: ['browserify', 'mocha', 'chai'],
//specify browserify preproccesor so we can use server-side components
preprocessors: {
'test/*' : ['browserify']
},
myapp.factory('Comments', function ($location) {
var isInitialized = false;
var comments = {};
var getConfig = function(){
var articleId = $location.path();
var defaults = {
articleId: articleId,
collectionMeta: {
articleId: articleId,
var cluster = require('cluster');
var PORT = +process.env.PORT || 1337;
if (cluster.isMaster) {
// In real life, you'd probably use more than just 2 workers,
// and perhaps not put the master and worker in the same file.
cluster.fork();
cluster.fork();
cluster.on('disconnect', function(worker) {
@adamrights
adamrights / app.js
Created February 3, 2014 10:14 — forked from nulltask/app.js
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, cluster = require('cluster');
var app = module.exports = express.createServer()
, io = require('./socket')(app);

Clustering: The basics

The trick? pass the file descriptor from a parent process and have the server.listen reuse that descriptor. So multiprocess in their own memory space (but with ENV shared usually)

It does not balance, it leaves it to the kernel.

In the last nodejs > 0.8 there is a cluster module (functional although marked experimental)