Skip to content

Instantly share code, notes, and snippets.

View Marak's full-sized avatar

Marak

View GitHub Profile
@Marak
Marak / console.log.js
Created July 12, 2011 07:25 — forked from tmpvar/.gitignore
A console.log implementation that plays "nice" with large amounts of data. Keeps node alive until the output has flushed to screen.
/*
A console.log that won't leave you hanging when node exits
*/
console.log = function(d) {
var res = process.stdout.write(d + '\n');
// this is the first time stdout got backed up
if (!res && !process.stdout.pendingWrite) {
process.stdout.pendingWrite = true;
@Marak
Marak / pipedDataStream.js
Created September 20, 2011 18:49 — forked from bmeck/pipedDataStream.js
Read in data piped ala `cat config.json | node app.js`
var tty = require('tty');
exports.pipedDataStream = pipedDataStream;
//
// If there was piped input, it returns a ReadableStream of the content
// use "data" and "end" events as per the norm.
//
// Else returns falsey.
//
@Marak
Marak / vlcrc.js
Created October 5, 2011 21:32 — forked from garth/vlcrc.js
Remote control multiple VLC apps via the command line using nodejs
// To start vlc with telnet remote control:
// ./VLC --extraintf rc --rc-host 0.0.0.0:3000
//
// To connect to multiple vlc's
// node vlcrc.js host1:3000 host2:3000
var net = require('net');
var readline = require('readline');
//addresses of servers
@Marak
Marak / bbs.js
Created October 27, 2011 05:15
curl bbs
var http = require('http');
var buf0 = new Buffer([0]);
var server = http.createServer(function (req, res) {
res.setHeader('content-type', 'multipart/octet-stream');
res.write('Welcome to the Fun House\r\n');
res.write('> ');
req.on('data', function (buf) {
res.write(buf);
@Marak
Marak / gist:1431484
Created December 4, 2011 22:22 — forked from joshsmith/gist:1431472
How should I be doing the callback?
user.save().on('success', handler).on('failure', handler)
function handler (result) {
if(result.err) { // or something like this
return callback(err);
}
return callback(null, result);
@Marak
Marak / gist:1505534
Created December 21, 2011 10:27 — forked from sontek/snowjob.sh
Make your terminal snow
#!/bin/bash
LINES=$(tput lines)
COLUMNS=$(tput cols)
clear
declare -A snowflakes
declare -A lastflakes
@Marak
Marak / hack.sh
Created March 31, 2012 22:30 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
app.router.get('/:slug', function (slug) {
var that = this;
Shortlink.find( {slug: slug} , function (err, shortlink) {
if (err) { throw new(Error)(err) }
console.log( that.req ); // This returns "undefined" and I think I understand why.
// How do I access request and response objects from within
// an anon callback like this one?
});
});
@Marak
Marak / client.js
Created May 15, 2012 01:06
connecting to a dnode socket.io server from node
var io = require('socket.io-client');
var sock = io.connect('http://localhost:8080');
var dnode = require('dnode');
var Stream = require('stream');
var stream = new Stream;
stream.writable = true;
stream.readable = true;
stream.write = function (buf) {
sock.emit('message', String(buf));
node_modules
secrets.js