Skip to content

Instantly share code, notes, and snippets.

var spawn = require('child_process').spawn;
var tailStream = function(file) {
return spawn('tail', ['-f', file]).stdout;
};
tailStream('./blah.txt').pipe( ... );
@xat
xat / gist:3ad9e6637944082b46ef
Last active August 29, 2015 14:06
simple flood script
var net = require('net');
var HOST = 'localhost';
var PORT = 7777;
var WORKERS = 1;
var TIMEOUT = 30; // sec
var data = 'FLOODATTACK';
var counter = 0;
var circulate = function(arr) {
var localfiles = function(opts, player, type, next) {
if (type !== 'launch') return next();
if (isUrl(opts.path)) return next();
// start local webserver, change the path to an url
};
var defaultmedia = function(opts, player, type, next) {
player.on('app-launch-pre', function(err, app) {
var group = function(arr, cb, ctx) {
var buckets = [];
for (var i=0, len=arr.length; i<len; i++) {
if (cb.call(ctx, arr[i], i) || !buckets.length) {
buckets.push([arr[i]]);
} else {
buckets[buckets.length-1].push(arr[i]);
}
}
return buckets;
@xat
xat / gist:9452fcb14e5d8440563a
Created November 7, 2014 19:42
contains.js
var contains = function(arr, cb) {
for (var i=0, len=arr.length; i<len; i++) {
if (cb(arr[i], i)) return true;
}
return false;
};
var last = function(fn, l) {
return function() {
var args = Array.prototype.slice.call(arguments);
args.push(l);
return l = fn.apply(null, args);
};
};

Keybase proof

I hereby claim:

  • I am xat on github.
  • I am xat (https://keybase.io/xat) on keybase.
  • I have a public key whose fingerprint is FAF5 5550 9A02 5279 1FB0 76F3 5B49 2B19 0149 FC24

To claim this, I am signing this object:

@xat
xat / gist:4426999
Created January 1, 2013 12:09
The Problem is, func_get_args() generates copies of the arguments and we need references.
<?php
class MyHook
{
public function run(&$arg)
{
$arg = 'bar';
}
}
@xat
xat / gist:4574119
Created January 19, 2013 18:21
The goal is to find a nice way to merge multiple configs where the inner-configs ($localConfig) are able to unset keys of the outer-configs ($globalConfig)
<?php
// Global Configuration
$globalConfig = array
(
'key1' => 'val1',
'key2' => array
(
'key2.1' => 'val2.1',
'key2.2' => 'val2.2',
@xat
xat / scheduler.js
Last active December 14, 2015 01:39
A simple demonstrantion of a sheduler done in Node.JS. Tasks can be split up in multiple Queues. Tasks can be marked as "exclusive" if they should not be run concurrent with other tasks.
var http = require('http'),
async = require('async'),
queueBuilder,
taskBuilder,
counter,
maxConcurrent = Number.POSITIVE_INFINITY,
debug = true,
queues = {},
tasks = {};