Skip to content

Instantly share code, notes, and snippets.

Avatar
🙂
Coding away...

Sander Tolsma stolsma

🙂
Coding away...
View GitHub Profile
@stolsma
stolsma / example.js
Created Sep 20, 2011
Downgrade process after connecting to port 80
View example.js
app.listen(process.env.NODE_ENV === 'production' ? 80 : 8000, function() {
console.log('Ready');
// if run as root, downgrade to the owner of this file
if (process.getuid() === 0)
require('fs').stat(__filename, function(err, stats) {
if (err) return console.log(err)
process.setuid(stats.uid);
});
});
@stolsma
stolsma / StackScript.sh
Created Sep 20, 2011 — forked from visnup/StackScript.sh
node.js knockout 2011 StackScript
View StackScript.sh
#!/bin/bash
# <UDF name="ssh_key" Label="Paste in your public SSH key" default="" example="" optional="false" />
# root ssh keys
mkdir /root/.ssh
echo $SSH_KEY >> /root/.ssh/authorized_keys
chmod 0700 /root/.ssh
# update to latest
@stolsma
stolsma / net.js
Created Aug 12, 2011
carapace-haibu net.js test code to understand the port bind errors....
View net.js
/*
* net.js: Wrapper around node.js core `net` module for observing relevant events
*
* (C) 2011 Nodejitsu Inc.
*
*/
var net = require('net'),
binding = process.binding('net'),
carapace = require('./carapace');
@stolsma
stolsma / client.sh
Created Jun 23, 2011
Install NodeJS:master, NPM:master from Github and node-inspector from NPM on clean system. Install Haibu with standard config on system.
View client.sh
#
# Install paths to Nodejs, NPM, node-inspector and haibu in user system.
#
# this gist can be run using: curl https://raw.github.com/gist/1042374/client.sh | sh
# location of node and supporting scripts
NODE="/home/node/local/bin"
HAIBU="/home/haibu/haibu"
# put node, npm and other global node programs in path if needed
@stolsma
stolsma / pr.md
Last active Sep 14, 2015 — forked from piscisaureus/pr.md
Checkout github pull requests locally
View pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

View Install Community Node.js.md

Install first for ubuntu:

sudo apt-get install build-essential libssl-dev curl git-core

Compile the required Node.js version and put in global reach:

# install Node.js from Github (replace 4.0.0 with required version)
git clone https://github.com/nodejs/node.git node4.0.0
View Install iojs.md

Install first for ubuntu:

sudo apt-get install build-essential libssl-dev curl git-core

Compile the required iojs version and put in global reach:

# install iojs from Github (replace 1.3.0 with required version)
git clone https://github.com/iojs/io.js.git iojs
@stolsma
stolsma / Debug.md
Last active Aug 29, 2015
Enable, disable and set debug port from running process
View Debug.md

process._debugProcess(process.pid)

process._debugPause()

process._debugEnd()

process.debugPort : is getter and setter of debugport

See:

@stolsma
stolsma / node init script.md
Last active Aug 29, 2015
How to create a node init script with forever
View node init script.md

Init Script

From: source

Init scripts hopefully need no explanation. Scripts reside in /etc/init.d with root ownership and executable permissions. e.g.:

sudo su
cp my-application-script /etc/init.d/my-application
View forever-initd-example.sh
#!/bin/bash
#
# chkconfig: - 55 45
# init.d example for Forever & Node
#
# modeled after
# https://gist.github.com/jinze/3748766
#
# supports vhost
#