Skip to content

Instantly share code, notes, and snippets.

_sshm()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
ADD_OPTS=$(sshm --complete)
opts="--help --version --add --list --del --show --complete $ADD_OPTS"
if [[ ${cur} == * ]] ; then
@FrankGrimm
FrankGrimm / na-sample.js
Created July 29, 2010 23:47
Abbreviation for command line parameters in node.js
// Example code for node-abbrev
var abbrevlib = require("node-abbrev");
var sys = require("sys");
// valid run modes for the imaginary tool
var validModes = ["help", "start", "stop", "status"];
// create Abbreviate instance for the modes
// second parameter (case sensitivity) optional, defaults to false
var abbrev = new abbrevlib.Abbreviate(validModes);
@FrankGrimm
FrankGrimm / eventpassing.js
Created August 1, 2010 23:24
Event passing for #node.js
/*
* eventpassing.js
*
* Monkey patch for passing events between EventEmitters
* Usage: simply require() this module
*
* @author Frank Grimm (http://frankgrimm.net)
* @version 0.1.3
*
*/
test-client-connect.js test-client-query.js
[root@speicher node-mysql]# node test/system/test-client-connect.js
{ length: 52
, received: 52
, number: 0
, type: 0
, protocolVersion: 10
, serverVersion: '5.0.45'
, threadId: 132500
, scrambleBuffer: <Buffer 66 3c 37 3d 6c 2b 2f 47 59 6b 2e 41 3c 48 35 70 56 3f 77 5b>
var Script = process.binding('evals').Script;
var stdin = process.openStdin();
stdin.setEncoding('utf8');
var scriptCode = '';
stdin.on('data', function (chunk) {
scriptCode += chunk;
});
stdin.on('end', function () {
Script.runInThisContext(scriptCode);
/*
* syslog-messages.js
*
* Encoding and decoding of CentOS syslog messages.
*
* @version: 0.1.0
* @author Frank Grimm (http://frankgrimm.net)
*
*/
/*
* syslog-server.js
*
* @version 0.1.0
* @author Frank Grimm (http://frankgrimm.net)
*
*/
exports.getServer = function(bind_port, bind_ip, callback) {
var printMemoryUsage = function() {
var spawn = require('child_process').spawn,
getconf = spawn('getconf', ['PAGESIZE']);
getconf.stdout.on('data', function (data) {
var pageSize = parseInt(data, 10);
console.log('Page size: ' + pageSize);
var procOutput = spawn('cat', ['/proc/' + process.pid + '/status']);
var qs = require('querystring');
var query = "foo[name]=bar&foo[bar]=foobar";
var res = qs.parse(query);
console.log(res.foo.foo);
console.log(res['foo']['bar']);
@FrankGrimm
FrankGrimm / formexample.js
Created November 7, 2010 22:08
Basic example on how to get the body data of a HTTP request in node.js
var http = require('http');
var querystring = require('querystring');
var utils = require('utils');
http.createServer(function (req, res) {
switch(req.url) {
case '/':
res.writeHead(200, "OK", {'Content-Type': 'text/html'});
res.write('<html><head><title>Example</title></head><body>');
res.write('<form enctype="application/x-www-form-urlencoded" action="/formhandler" method="post">');