Skip to content

Instantly share code, notes, and snippets.

@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 = {};
@xat
xat / gist:5690206
Last active December 17, 2015 23:38
<?php
function setter($val) {
return function(&$val) use ($val) {}
};
$fooSetter = setter('foo');
$fooSetter($x);
@xat
xat / gist:6141235
Last active December 20, 2015 13:49
<?php
function treeWalker($fnCallback, $strTable, $intStart=0, $orderBy='pid, sorting')
{
$arrItemsByPid = array();
$arrItems = \Database::getInstance()->execute('SELECT * FROM ' . $strTable . ' ORDER BY ' . $orderBy)->fetchAllAssoc();
$strResult = '';
foreach($arrItems as $arrItem)
var page = require('webpage').create(),
system = require('system'),
address, output, size;
if (system.args.length < 3 || system.args.length > 5) {
console.log('Usage: rasterize.js URL filename');
phantom.exit(1);
} else {
address = system.args[1];
output = system.args[2];
@xat
xat / gist:8882979
Last active August 29, 2015 13:56
scrollTo
var scrollTo = function($target) {
var $body = $('body,html');
var currentOffset = $(window).scrollTop();
var targetOffset = $target.offset().top;
var distance = Math.abs(currentOffset - targetOffset);
if (!$target.length) {
return;
}
@xat
xat / gist:8898538
Created February 9, 2014 12:41
automatic answerscript for speedsums.com: Just open the page and execute this script in your JS console.
(function($) {
var $question = $('#question');
var $answer = $('#answer');
var checkInterval = 250;
var cheat = function() {
var rawVal = $question.html();
rawVal = rawVal.replace(' =', '')
.replace('x', '*')
.replace('÷', '/');
@xat
xat / gist:9978542
Last active August 29, 2015 13:58
An untested node-port of https://github.com/foertel/pihp
var Gpio = require('onoff').Gpio,
async = require('async'),
_ = require('underscore');
var measureDistance = function(opts) {
var options = _.defaults(opts, {
trigger: 24,
echo: 25,
leds: [4, 17, 18, 27, 22, 23],
timeout: 2000
var engine = SearchEngine({
url: 'http://localhost:3333/'
});
engine.use(searchbox({
el: '#box',
autocomplete: true
}));
engine.use(results({