Skip to content

Instantly share code, notes, and snippets.

@ellman
ellman / gist:2c5b95ee35de1446df95
Created June 15, 2014 11:37
reduced express.js file
'use strict';
/**
* Module dependencies.
*/
var favicon = require('serve-favicon'),
morgan = require('morgan'),
compression = require('compression'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
@ellman
ellman / aboutme
Created June 11, 2014 06:30
about me
{
"name": "Yonatan Ellman",
"age": 29,
"pob": "Cape Town South Africa",
"blog": "blog.nodeside.com",
"email": {
"personal": "yonatan@nodeside.com",
"work": "yonatan@linnovate.net"
},
"quotes": [
@ellman
ellman / gist:446c2d7e40478de5e3a3
Last active August 29, 2015 14:02
mean file sructure for 0.4.0
Some of the files/folders are excluded. The structure here is a general overview
config
--env/ (per environment)
--express.js (reduced express file)
packages/
----auth
----system
----articles/ (scaffolded example)
map = function() {
emit(this.suit,{count:1});
}
reduce = function(key, values) {
var total = 0;
for ( var i=0; i<values.length; i++ )
total += values[i].count;
return { count : total };
}
@ellman
ellman / gist:8581561
Last active January 4, 2016 06:19
Get process information about process from PID using ps
ps -p <PID> -o pid,vsz=MEMORY -o user,group=GROUP -o comm,args=ARGS
@ellman
ellman / gist:8581469
Last active January 4, 2016 06:19
Get process and PID running on a port using netstat and lsof
#Ubuntu and OSX
lsof -i tcp:<PORT>
#Ubuntu
netstat -tulpn | grep --color :<PORT>
@ellman
ellman / nodejs-upstart-example.conf
Last active August 31, 2020 12:08
Run Nodejs as upstart service on Ubuntu or Centos
#Upstart Service For Nodejs in /etc/init
description 'nodejs example upstart'
author 'Yonatan Ellman (blog.nodeside.com) adpated from ivarprudnikov.com'
env NAME=TEST
env LOG_FILE=/var/log/nodejs-test.log
env USER=nodejs
env NODE_BIN=/usr/local/bin/node
env NODE_ENV="development"
env PORT=3001
@ellman
ellman / nodejs-callback-example.js
Last active May 3, 2022 11:22
Simple Nodejs callback example
// Simulate some slow I/O task
function blockingIO(callback) {
// Delay of 3 seconds
setTimeout(function() {
callback("The blocking task has been completed");
}, 3000);
}
// A demo callback function
function doThisWhenFinished(message) {
@ellman
ellman / gist:8576781
Last active January 4, 2016 05:39
Count number of connections to specific port using NETSTAT
netstat -anp | grep -w <PORT> | grep ESTABLISHED | wc -l
@ellman
ellman / dependency-injection-example.js
Last active January 3, 2016 11:19
simple example of dependency injection
var dependable = require('dependable'),
container = dependable.container();
// Could be your db connection
var mongoose = {}
// Random dependency
container.register('anotherDependency', 'I do nothing right now');
// The dbAdmin "module" could be another that we want to make that might