Skip to content

Instantly share code, notes, and snippets.

var child_process = require('child_process');
var forever = '/opt/local/bin/forever';
var node = '/opt/local/bin/node';
var bash = '/bin/bash';
var mongod = '/opt/local/bin/mongod';
var cwd = process.cwd();
var procs = [
@youurayy
youurayy / test.js
Created October 10, 2011 23:54
TypeError: Cannot set property 'level' of null
var winston = require('winston');
winston.addColors({
debug: 'cyan',
event: 'magenta',
fail: 'inverse'
});
var log = new winston.Logger({
require('winston/lib/winston/transports/loggly').Loggly.prototype.log =
function(level, msg, meta, callback) {
if(this.silent)
return callback(null, true);
var self = this;
/*
message = common.clone(meta || {});
@youurayy
youurayy / filesender.js
Created November 9, 2011 09:02
Node.js (v0.4) sendfile() non-caching fileserver - fast and efficient!
var http = require('http');
var fs = require('fs');
var path = require('path');
var constants = require('constants');
var timers = require('timers');
var port = 8080;
http.createServer(function(req, res) {
if(req.url == '/') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
@youurayy
youurayy / test.js
Created January 19, 2012 09:17
Testing overloadability of native Object members
var ps = [
'__defineGetter__', '__defineSetter__', 'valueOf',
'__lookupGetter__', '__lookupSetter__',
'constructor', 'hasOwnProperty',
'isPrototypeOf', 'propertyIsEnumerable',
'toLocaleString', 'toString' ];
var o = {};
for(var i = 0; i < ps.length; i++)
@youurayy
youurayy / versions.js
Created January 30, 2012 15:30
Script to search and print top-level module versions for NPM's package.json file (dependencies). Run in project root.
var fs = require('fs');
var res = {};
var base = process.cwd() + '/node_modules';
var dirs = fs.readdirSync(base);
for(var i = 0; i < dirs.length; i++) {
var module = dirs[i];
var bdir = base + '/' + module;
var cfg = bdir + '/package.json';
var ok;
@youurayy
youurayy / gist:1869292
Created February 20, 2012 13:51
quick-testing node/v8 memory/object limits
/*
node --max_old_space_size=3000 --prof nodemem.js
# --trace_incremental_marking=true --incremental_marking_steps=false
node --max_old_space_size=3000 --max_new_space_size=3000 --max_executable_size=1000 --gc_global --prof nodemem.js
# --noincremental_marking
# --nolazy_sweeping
# --never_compact
@youurayy
youurayy / test.js
Created February 22, 2012 19:02
v8/node collections benchmark (Array, Object, ES6 Set)
var assert = require('assert');
var len = 100000;
// create test clients, just empty objects
var sampleClients = [];
for(i = 0; i < len; i++)
sampleClients.push({ id: i });
// create a randomized list for tests
var randomizedClients = sampleClients.slice();
@youurayy
youurayy / profile.sh
Created June 9, 2014 20:41
Git Bash Alias Helpers
alias gitadd='git ls-files -z -o --exclude-standard | xargs -0 git add'
alias gitadde='git ls-files -o --exclude-standard'
alias gitrem='git ls-files -z -d --exclude-standard | xargs -0 git rm'
alias gitreme='git ls-files -d --exclude-standard'
alias gits='git status'
function gitcom() { git commit -a -m "${*:-update}" && git push; }
# do this manually after the very first gitcom(): git push -u origin master
alias gitrel='if [ -n "$(npm version patch)" ]; then git push && git push --tags; fi'
alias gitlog='git log --oneline --decorate --graph'
@youurayy
youurayy / test-deno.js
Created June 28, 2020 16:27
will read un-gzipped test data from https://github.com/pkg/json/tree/master/testdata; run as: deno run -A test-deno.js
import { readJsonSync }
from "https://deno.land/std/fs/mod.ts";
const repetitions = 100
const dir = './testdata'
for(const file of Deno.readDirSync(dir)) {
const fileName = `${dir}/${file.name}`
const bytes = Deno.statSync(fileName).size
let i = 1, avg = 0
for(; i <= repetitions; i++) {