Skip to content

Instantly share code, notes, and snippets.

@mscdex
mscdex / update_to_nan_v2.0.x.sh
Created August 30, 2015 05:55 — forked from thlorenz/update_to_nan_v2.0.x.sh
Script to update Node.js addons to work with nan 2.0.x and thus with iojs v3.x (gets you 90% there)
#!/bin/bash
replacements=(
"NanAsyncWorker/Nan::AsyncWorker"
"NanAsyncQueueWorker/Nan::AsyncQueueWorker"
"NanCallback/Nan::Callback"
"NanSetInternalFieldPointer/Nan::SetInternalFieldPointer"
"NanGetInternalFieldPointer/Nan::GetInternalFieldPointer"
"NanNewBufferHandle\\(([^;]+);/Nan::NewBuffer(\\1.ToLocalChecked();"
"(NanNew(<(v8::)?String>)?\\(\"[^\"]*\"\\))/\\1.ToLocalChecked()"
@mscdex
mscdex / node_debian_init.sh
Created August 6, 2011 09:33 — forked from peterhost/node_debian_init.sh
Daemon init script for node.js based app/server (DEBIAN/UBUNTU)
#! /bin/sh
# ------------------------------------------------------------------------------
# SOME INFOS : fairly standard (debian) init script.
# Note that node doesn't create a PID file (hence --make-pidfile)
# has to be run in the background (hence --background)
# and NOT as root (hence --chuid)
#
# MORE INFOS : INIT SCRIPT http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
# INIT-INFO RULES http://wiki.debian.org/LSBInitScripts
# INSTALL/REMOVE http://www.debian-administration.org/articles/28
@simianhacker
simianhacker / gist:3308895
Created August 9, 2012 23:11
Upstart template for Node.js
description "Node server for #{application} (#{node_env})"
start on (net-device-up
and local-filesystems
and runlevel [2345])
stop on runlevel [016]
script
exec sudo -u nobody sh -c "NODE_ENV=#{node_env} #{path_to_node} #{script_name}"
end script
@cjpartridgeb
cjpartridgeb / gist:3688880
Created September 10, 2012 04:28
Simple curry example
// assuming http.get fires back err, result
function curryGet = function(url) {
return function(callback) {
http.get(url, callback);
}
}
async.parallel([
@mscdex
mscdex / gist:4463223
Last active December 10, 2015 16:48
node binary install one-liner for *nix
Linux 32-bit: curl http://nodejs.org/dist/latest/node-v0.10.29-linux-x86.tar.gz | tar zx --strip=1 -C /usr/local
Linux 64-bit: curl http://nodejs.org/dist/latest/node-v0.10.29-linux-x64.tar.gz | tar zx --strip=1 -C /usr/local
@mscdex
mscdex / readstream.js
Last active December 15, 2015 10:08
streams2 ReadStream that uses callbacks instead of a combination of 'readable' event listening and read()
var ReadableStream = require('stream').Readable;
var EMPTY_CALLBACK = function(n) {};
function ReadStream(cfg) {
if (!(this instanceof ReadStream))
return new ReadStream();
var self = this;
this._callbacks = [];
@mscdex
mscdex / example.js
Created May 16, 2013 20:18
DataTables plug-in for displaying sort priorities in each sorted column header
$('#example').dataTable().fnSortPriorities();
@mscdex
mscdex / gist:5329227
Last active December 9, 2017 12:48
Why the IMAP protocol sucks
1. You cannot fetch .TEXT, .HEADER, etc. for parts that are not of type message/rfc822
2. Gotchas with multiple asynchronous requests
3. Response to partial body fetch does not include originally requested range, only the starting byte number
4. Fragmented fetch responses (servers are not required to collect all requested pieces of information for a particular message into a single response)
5. LIST can display child mailboxes before their parents
6. FETCHing a comma-separated list of messages (UIDs or seqnos) does not necessarily result in FETCH responses in that same order
7. Untagged FETCH responses containing FLAG updates can be sent for messages not requested *during* a FETCH request.
anonymous
anonymous / config.json
Created December 13, 2012 20:08
{
"key": "/home/me/foo_key",
"user": "foo",
"targets": {
"all": [
"example.org#Default user, key auth, port 22",
"root@example.net:2233#Root user, key auth, port 2233",
"root:toor@example.com#Root user, password auth, port 22"
],
"production": [

Notes:

  • Text in [[ ]] are the internal libuv function call.
  • Text in {{ }} are the Node functions that are affected.
  • Text in ( ) are notes about what is happening.
  • While the Windows event loop has minor variations, I don't believe any of those affect Node.

On process.nextTick():