Skip to content

Instantly share code, notes, and snippets.

View netroy's full-sized avatar

कारतोफ्फेलस्क्रिप्ट™ netroy

View GitHub Profile
IMPORTANT: this is outdated, go to https://github.com/netroy/Lockets
"npm install socket-io" & you are ready to go
/**
* A `tail -f` implementation in Node.js.
*
* Original author : Bratish Goswami <bratishgoswami AT gmail DOT com>
* Modified by : Michel Bartz <michel.bartz AT manwin DOT com>
*
*/
var sys = require("sys"),
fs = require('fs'),
@netroy
netroy / 000-lessthan140chars.js
Created March 16, 2011 09:46
Pseudo-random Token generator .. dont have to worry about uniques. Coded for nodejs ... outputs to console the generated tokens.. can be used as IDs in any application
function(){var a=1E15;return function(){var b=~~(1E3*Math.random());a>9E15-b&&(a=1E15);a+=b;return a.toString(36)}}();
@netroy
netroy / HashSet.js
Created March 22, 2011 08:42
a HashSet implementation in JS (for NodeJS)... no prototype involved to prevent inheritence
/*
** This is broken... working on a Hashtable implementation first & then use that instead of plain Objects to implement this
*/
HashSet = function HashSet(){
if(!(this instanceof HashSet)) return;
var _data = {};
var _length = 0;
var _DEFAULT = new Date();
@netroy
netroy / 000-lessthan140chars.js
Created March 31, 2011 11:16
A small template rendering engine in JS ... uses Function constructor, unfortunately
function(b,c){return b.replace(/{[\w\.\(\)]+}/g,function(a){a=a.replace(/[\{\}]/g,"");try{with(c)return eval(a)}catch(b){return""}})};
@netroy
netroy / Clojure Version.clj
Last active September 25, 2015 16:07
finding the largest product of 5 consecutive digits in an array/string of a rather large size
(apply max
(map #(reduce * %)
(for [i (range (count x))]
(take 5 (drop i x)))))
@netroy
netroy / 000-lessthan140chars.js
Created May 15, 2011 11:19
Better AttachEvent
function(c,a,e,b){function d(a){e.apply(c,[a||event].concat(b))}b=b||[];try{c.addEventListener(a,d,!1)}catch(f){c.attachEvent("on"+a,d)}};
@netroy
netroy / ReadMe.md
Created October 14, 2011 20:08
Simplest Static Webserver in Node.JS

Just install connect from npm. Run this in a directory that you'll like to serve static content from. To run on a specific port set ENV "StaticPort"

@netroy
netroy / git tutorials.md
Created October 27, 2011 10:09
Awesome git tutorials I am finding here and there
@netroy
netroy / 000-server.js
Created November 5, 2011 11:30
Using cluster to scale existing Express/Connect apps
var cluster = require('cluster'),
app = require('./app');
var workers = {},
count = require('os').cpus().length;
function spawn(){
var worker = cluster.fork();
workers[worker.pid] = worker;
return worker;