Skip to content

Instantly share code, notes, and snippets.

@mmalecki
mmalecki / makeInstallBot.js
Created November 27, 2011 21:36
Bot to make @bnoordhuis' life easier
var irc = require('irc');
var client = new irc.Client(
'irc.freenode.net',
'makeInstallBot',
{ channels: ['#node.js', '#nodejitsu'] }
);
client.on('message', function (from, to, msg) {
if (~msg.indexOf('`make install` is not implemented yet. Bug bnoordhuis about it in #node.js')) {
➜ node git:(master) ./node test/simple/test-stdin-resume-pause.js
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: OK, success '/Users/maciej/dev/src/node/test/simple'
at Object.readlinkSync (fs.js:422:18)
at Object.realpathSync (fs.js:876:30)
at tryFile (module.js:140:15)
at Function._findPath (module.js:180:18)
@mmalecki
mmalecki / console.hex.js
Created November 30, 2011 18:32
Not really hex.
console.hex = function (data) {
var columns = 40,
line = '',
code;
function pad(number, length) {
var str = '' + number;
while (str.length < length) {
str = '0' + str;
}
@mmalecki
mmalecki / child.js
Created December 2, 2011 22:15
Close child's stdin
console.log('Hello');
var stdin = process.openStdin();
stdin.on('data', function (d) {
console.log('Oh, I can exit now');
stdin.pause();
});
process.on('exit', function () {
console.log('Oh, I am exitting now');
});
setTimeout(function () {
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
@mmalecki
mmalecki / master.js
Created December 9, 2011 00:49
Example of multiprocessing in node
var path = require('path'),
fork = require('child_process').fork;
var N = 8,
M = 128;
// Generate data set
console.log('Generating data sets...');
var dataSet = [], row = [];
@mmalecki
mmalecki / fork-example.c
Created December 15, 2011 23:22
Some example of daemonizing a process
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main() {
printf("Beginning to fork awesomesauce\n");
// Fork the process.
var irc = require('irc');
var client = new irc.Client(
'irc.freenode.net',
'threeLinksBot',
{ channels: ['#nodejitsu', '#nodebombrange'] }
);
client.on('message', function (from, to, msg) {
if (msg == '!threelinks') {
@mmalecki
mmalecki / mem.js
Created December 23, 2011 20:37
Messy memcached partial reimplementation I wrote on my very first day with node. Last time I checked, it's faster in some cases.
var net = require('net');
var store = { }
var server = net.createServer(function (socket) {
var buffer = "";
var index = 0;
socket.on("data", function(data) {
buffer += data.toString('utf8');
@mmalecki
mmalecki / whichStdin.sh
Created January 1, 2012 11:41 — forked from csanz/gist:1545189
My Hacker History
history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|./whichStdin|sort|uniq -c|sort -rn
1815 git
892 mvim
508 npm
477 node
475 ls
383 rm
277 cat
266 jitsu