Skip to content

Instantly share code, notes, and snippets.

@benbuckman
benbuckman / intercept-stdout.js
Created May 20, 2012 15:42 — forked from pguillory/gist:729616
Hooking into Node.js stdout, pipe stdout to telnet
var _ = require('underscore'),
util = require('util');
// intercept stdout, passes thru callback
// also pass console.error thru stdout so it goes to callback too
// (stdout.write and stderr.write are both refs to the same stream.write function)
// returns an unhook() function, call when done intercepting
module.exports = function interceptStdout(callback) {
var old_stdout_write = process.stdout.write,
old_console_error = console.error;
@tedmiston
tedmiston / nodejs-tcp-example.js
Last active May 20, 2024 11:27
Node.js TCP client and server example
/*
In the node.js intro tutorial (http://nodejs.org/), they show a basic tcp
server, but for some reason omit a client connecting to it. I added an
example at the bottom.
Save the following server in example.js:
*/
var net = require('net');
@umidjons
umidjons / nohup-output-to-file.sh
Created January 14, 2014 12:07
Redirect nohup output to a file
# redirect output and errors into file output.log:
nohup some_command > output.log 2>&1&
# abbreviated syntax for bash version >= ver.4:
nohup some_command &> output.log
@timrwilliams
timrwilliams / data.json
Last active November 27, 2019 09:21
Sample setup for refreshing a Rickshaw graph from remote JSON source
[{"color":"#DDDF0D","name":"maps.googleapis.com","data":[{"x":1397779200,"y":13},{"x":1397782800,"y":11},{"x":1397786400,"y":10},{"x":1397790000,"y":12},{"x":1397793600,"y":14},{"x":1397797200,"y":13},{"x":1397800800,"y":6},{"x":1397804400,"y":0},{"x":1397808000,"y":0},{"x":1397811600,"y":2},{"x":1397815200,"y":33},{"x":1397818800,"y":17},{"x":1397822400,"y":7},{"x":1397826000,"y":16},{"x":1397829600,"y":29},{"x":1397833200,"y":25},{"x":1397836800,"y":22},{"x":1397840400,"y":30},{"x":1397844000,"y":27},{"x":1397847600,"y":27},{"x":1397851200,"y":18},{"x":1397854800,"y":23},{"x":1397858400,"y":19},{"x":1397862000,"y":7},{"x":1397865600,"y":9},{"x":1397869200,"y":8},{"x":1397872800,"y":21},{"x":1397876400,"y":9},{"x":1397880000,"y":5},{"x":1397883600,"y":6},{"x":1397887200,"y":2},{"x":1397890800,"y":0},{"x":1397894400,"y":0},{"x":1397898000,"y":0},{"x":1397901600,"y":23},{"x":1397905200,"y":0},{"x":1397908800,"y":5},{"x":1397912400,"y":2},{"x":1397916000,"y":5},{"x":1397919600,"y":14},{"x":1397923200,"y":21},{"
@tmcw
tmcw / setup_teardown_tap_tape.md
Last active June 13, 2016 15:33
Setup & Teardown of Tests in node-tap or tape

The node-tap and tape modules are great for testing node modules. But they don't have built-in ideas of how you should do setup and teardown. So here's one approach.

  • Tests run serially. Take advantage of this, rather than doing any more advanced functional magic.
  • Use global variables.
var foo, bar;

function setup(t) {
@staltz
staltz / introrx.md
Last active July 25, 2024 16:52
The introduction to Reactive Programming you've been missing
@kgorman
kgorman / gist:134896c7414fde8e090b
Last active May 7, 2024 13:34
MongoDB Profiler Cheat Sheet
// a list of useful queries for profiler analysis. Starting with the most basic.
// 2.4 compatible
//
// output explained:
//
{
"ts" : ISODate("2012-09-14T16:34:00.010Z"), // date it occurred
"op" : "query", // the operation type
"ns" : "game.players", // the db and collection
#!/bin/bash
#
# Automate mysql secure installation for debian-baed systems
#
# - You can set a password for root accounts.
# - You can remove root accounts that are accessible from outside the local host.
# - You can remove anonymous-user accounts.
# - You can remove the test database (which by default can be accessed by all users, even anonymous users),
# and privileges that permit anyone to access databases with names that start with test_.
@xingkaixin
xingkaixin / pysftp.py
Last active December 17, 2020 12:22
Python pexpect sftp sample
#!/usr/bin/python
# -*- coding: utf-8 -*-
from pexpect import *
#import pexpect
import sys
import os
def initFile(*filenames):
#!/bin/sh
#
# This script is used on a QNAP TS-269 PRO. https://www.en0ch.se/qnap-and-rsync/
#
# You have to change:
# 1. $SHAREUSR
# 2. $EXCLUDES (if you want o change the name of the file servername.excludes)
# 3. $SOURCE & $DESTINATION
# 4. user@yourserver.se for the mysqldump
# 5. --password=SUPERSECRET