Skip to content

Instantly share code, notes, and snippets.

View erossignon's full-sized avatar

Etienne erossignon

View GitHub Profile
@kriszyp
kriszyp / define-node.js
Created October 27, 2010 21:08
Add AMD/define() support to NodeJS
var currentModule, defaultCompile = module.constructor.prototype._compile;
module.constructor.prototype._compile = function(content, filename){
currentModule = this;
try{
return defaultCompile.call(this, content, filename);
}
finally {
currentModule = null;
}
};
anonymous
anonymous / gist:985918
Created May 22, 2011 21:33
function IntervalMonitor() {
var intervals = [];
this.start = function (callback, repeat) {
var res = setInterval(callback, repeat);
intervals.push(res);
return res;
};
this.stop = function (item) {
@isaacsanders
isaacsanders / Equity.md
Created January 21, 2012 15:32
Joel Spolsky on Equity for Startups

This is a post by Joel Spolsky. The original post is linked at the bottom.

This is such a common question here and elsewhere that I will attempt to write the world's most canonical answer to this question. Hopefully in the future when someone on answers.onstartups asks how to split up the ownership of their new company, you can simply point to this answer.

The most important principle: Fairness, and the perception of fairness, is much more valuable than owning a large stake. Almost everything that can go wrong in a startup will go wrong, and one of the biggest things that can go wrong is huge, angry, shouting matches between the founders as to who worked harder, who owns more, whose idea was it anyway, etc. That is why I would always rather split a new company 50-50 with a friend than insist on owning 60% because "it was my idea," or because "I was more experienced" or anything else. Why? Because if I split the company 60-40, the company is going to fail when we argue ourselves to death. And if you ju

@TooTallNate
TooTallNate / repl-client.js
Created March 26, 2012 20:09
Running a "full-featured" REPL using a net.Server and net.Socket
var net = require('net')
var sock = net.connect(1337)
process.stdin.pipe(sock)
sock.pipe(process.stdout)
sock.on('connect', function () {
process.stdin.resume();
process.stdin.setRawMode(true)
@jpoehls
jpoehls / node-cluster-messaging.js
Created March 29, 2012 01:48
Simple message passing between cluster master and workers in Node.js
var cluster = require('cluster');
if (cluster.isWorker) {
console.log('Worker ' + process.pid + ' has started.');
// Send message to master process.
process.send({msgFromWorker: 'This is from worker ' + process.pid + '.'})
// Receive messages from the master process.
@serby
serby / sync.js
Created May 23, 2012 14:19
JavaScript implementation of set synchronisation. Bound by memory but minimizes database read writes.
var _ = require('underscore')
, a = {
1: { id: '1', name: 'a' },
2: { id: '2', name: 'b' },
3: { id: '3', name: 'c' }
}
, b = {
2: { id: '2', name: 'b1' },
3: { id: '3', name: 'c2' },
4: { id: '4', name: 'd' }
@bruth
bruth / jsondiff.js
Last active December 12, 2015 04:38
JavaScript implementation for constructing objects diffs compatible with JSON PATCH syntax.
var jsondiff = (function() {
// Patch helper functions
function getParent(paths, path) {
return paths[path.substr(0, path.match(/\//g).length)];
}
// Checks if `obj` is an array or object
function isContainer(obj) {
return _.isArray(obj) || _.isObject(obj);
@branneman
branneman / better-nodejs-require-paths.md
Last active October 18, 2024 20:29
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@dceejay
dceejay / Dockerfile
Last active November 24, 2020 15:39
Dockerfile for Node-RED
# Dockerfile for Node-RED - pulls latest master code from git
# Use the node.js v4 LTS engine
FROM node:4-slim
MAINTAINER ceejay
RUN mkdir -p /root/.node-red
WORKDIR /root/.node-red
# download latest stable node-red
RUN npm install -g --unsafe-perm node-red
@erossignon
erossignon / test_server.ts
Last active November 12, 2019 14:59
server with hardcoded ip address in certifcate
// node --inspect-brk -r ts-node/register -r source-map-support test_server.ts
import * as path from "path";
import * as fs from "fs";
import { promisify } from "util";
import * as child_process from "child_process";
import {
makeApplicationUrn,
OPCUAServer,
OPCUAClient,