Skip to content

Instantly share code, notes, and snippets.

@xphere
xphere / FileLocator.php
Created November 5, 2013 16:18
Adds globbing support to FileLocator in symfony/config
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@xphere
xphere / CSVType.php
Created November 7, 2013 13:15
Store arrays of strings into comma-separated values with Doctrine2
<?php
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class CSVType extends StringType
{
const NAME = 'csv';
const DELIMITER = ',';
@xphere
xphere / QueueBuilder.php
Created November 13, 2013 10:24
Verbose method for AMQP queue declaration. Before: $queue = $channel->queue_declare('queue_name', false, true, false, false, true); Now: $queue = QueueBuilder::create($channel, 'queue_name')->setDurable()->setAutoDelete()->buildQueue();
<?php
namespace Amqp;
use PhpAmqpLib\Channel\AMQPChannel;
class QueueBuilder
{
/** @var AMQPChannel */
protected $channel;
@xphere
xphere / ConfigurationTest.php
Created November 26, 2013 09:13
Why is the "empty set of test" test not passing?
<?php
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Processor;
class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider provideDefaultValues
@xphere
xphere / AsyncTrait.php
Created December 2, 2013 10:51
Async events
<?php
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\Event;
trait AsyncDispatcherTrait
{
/** @var EventDispatcherInterface */
protected $dispatcher;
@xphere
xphere / CombinatorialIterator.php
Created December 4, 2013 10:54
Iterates over all combinations of the values on an input array
<?php
class CombinatorialIterator implements \Iterator
{
protected $valid;
protected $iteration;
protected $data;
public function __construct(array $data = array())
{
@xphere
xphere / debounce.js
Created February 17, 2014 15:59
debounce.js
function debounce(callback, timeout) {
var timer;
return function() {
timer && clearTimeout(timer);
timer = setTimeout(function(args) {
timer = null;
callback.apply(this, args);
}.bind(this, arguments), timeout||100);
}
}
function setSelectionPlugin() {
var _setSelectionRange, _getCursorPosition, support = (function() {
var input = document.createElement('input'), result;
result = {
setSelectionRange: ('setSelectionRange' in input) || ('selectionStart' in input),
createTextRange: ('createTextRange' in input) || ('selection' in document)
};
input = null;
return result;
}());
@xphere
xphere / Stream.js
Last active August 29, 2015 13:56
Streams javascript naïve implementation
var Stream = (function () {
var undefined, empty, proto;
function extend(dest, source) {
for (var arg = 1; arg < arguments.length; ++arg) {
for (var key in arguments[arg]) {
if (arguments[arg].hasOwnProperty(key)) {
dest[key] = arguments[arg][key];
}
}
@xphere
xphere / functions.sh
Last active August 29, 2015 13:56
Bash function for Symfony console
sf() {
local DIR
pushd . > /dev/null 2>&1
while ! git exec test -x app/console; do
if [ $PWD = "/" ]; then
popd > /dev/null 2>&1
echo "Can't find a suitable Symfony application" 1>&2
return 1
fi