Skip to content

Instantly share code, notes, and snippets.

View spion's full-sized avatar
:shipit:

Gorgi Kosev spion

:shipit:
View GitHub Profile
@spion
spion / requestlimiter.js
Created August 15, 2012 12:51
hacky request limiter example for connect/express
var requestlimit = function(num) {
var queue = [];
return function(req, res, next) {
queue.push(next);
var removeAndNext = function() {
var qindex = queue.indexOf(next);
if (qindex >= 0) delete queue[qindex];
if (queue.length) queue[0]();
}
@spion
spion / server.js
Created August 15, 2012 21:58
express 3 server.js
var paper = require('./lib/paper.js/node.js');
var express = require('express');
var receiver = require('./public/receiver');
var webServer = express();
var httpServer = require('http').createServer(webServer);
var io = require('socket.io').listen(httpServer);
io.configure(function () { io.set('transports', ['flashsocket', 'xhr-polling']); });
function publishPathsToClient(socket) {
@spion
spion / prepfeeder.sh
Created August 20, 2012 22:41
Prepare a regular text file for feedtriplie
read line;
i=1
maxempty=50
empty=0
while [ "1" ]
do
if [ "$line" ]
then
echo :: $i blah blah : $line
empty=0
@spion
spion / node-complete-rpc.js
Created August 23, 2012 15:30
Complete rpc interface for node.
// on the command line:
// ./processPool --port poolport
// on any machine
// ./processWorker --connect poolip:poolport
// The process pool is a registry that delegates services to
// workers and knows which services are registered where.
var pool = ProcessPool.connect(9000);
@spion
spion / connect-list.js
Created August 27, 2012 12:17
Create a middleware from a list of middlewares.
module.exports = function () {
var list = arguments;
return function (req, res, realNext) {
var id = -1;
var innerNext = function (err) {
if (err) return realNext(err);
var nextFn = ++id < list.length - 1 ? innerNext : realNext,
mw = list[id];
mw(req, res, nextFn);
};
@spion
spion / wrap.lua
Created August 31, 2012 03:41
Wrap old-style lua functions to support both old and new styles
local table = require('table');
function wrap(cb, fn)
return function(...)
local arg = {...};
if (type(arg[cb]) == 'function') then
return fn(...);
else
local myargs = {...};
table.insert(myargs, cb, 1);
var parallelResizes = 5;
async.mapSeries(files, function (item, cb) {
im.identify(source_dir + file, cb);
}, function (err, identifies) {
var queue = async.queue(function (options, callback) {
im.resize(options, callback);
}, parallelResizes);
identifiers.forEach(function (id) {
/* create options objects for every identifier-size pair and push each like this: */ queue.push(optionsSize1, optionsSize2,...);
});
// The original function. Nothing wrong with it. Its short and simple.
// The code flow is obvious.
function myfunction(response) {
db.stuff(function stuff_cb (results) {
var transformed = trans(results);
db.stuffWith(transformed, function stuffWith_cb(endResult) {
var finalTransform = final(endResult, transformed);
response.end(finalTransform);
});
@spion
spion / blackout-mk.js
Created October 1, 2012 20:13
Blackout script v0.1 (based on SOPA)
(function (){
// update test
var root = this;
var SopaBlackout = function(){};
var addEvent = function(obj, type, fn, ref_obj){
if (obj.addEventListener){
obj.addEventListener(type, fn, false);
}else if (obj.attachEvent){
obj["e"+type+fn] = fn;
@spion
spion / a.ts
Created October 3, 2012 13:37
typescript module fail
import B = module("b");
class A extends B.B {
g(): number { return super.f(); }
};