Skip to content

Instantly share code, notes, and snippets.

@cboden
cboden / UvConnection.php
Created July 13, 2012 13:55
Ratchet w/ php-uv
<?php
namespace Ratchet\Server;
use Ratchet\ConnectionInterface;
class UvConnection implements ConnectionInterface {
private $client;
public function __construct($client) {
$this->client = $client;
}
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@igorw
igorw / FooController.php
Created September 5, 2012 22:13
Silex convention-based controllers
<?php
// src/Foobar/Controller/FooController.php
namespace Foobar\Controller;
class FooController
{
public function helloAction($request)
{
<?php
require __DIR__.'/vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
// Create a blob of data for testing
$data = '';
for ($i = 1; $i <= 8; $i++) $data .= $i.str_repeat("\0", 1022)."\n";
@davedevelopment
davedevelopment / index.php
Created November 13, 2012 16:36
Tinkering with a Hal resource DTO, separating the framework from the app and content negotiation
<?php
namespace Demo {
require __DIR__."/vendor/autoload.php";
use Nocarrier\Hal;
class Resource extends Hal {}
class ResourceResponse
@beberlei
beberlei / tailrecursion.php
Created November 25, 2012 21:25 — forked from pkriete/gist:2425817
PHP Tail Recursion
<?php
class TailRecursion
{
public $func;
public $acc;
public $recursing;
public function tail()
{
return call_user_func_array($this->func, func_get_args());
@davedevelopment
davedevelopment / RussianDependencyRoulettePimple.php
Created January 7, 2013 15:42
RussianDependencyRoulettePimple
<?php
class RussianDependencyRoulettePimple extends Pimple
{
public function offsetGet($id)
{
return parent::offsetGet(reset(shuffle($this->keys())));
}
}
@igorw
igorw / FooController.php
Last active December 11, 2015 01:38
Convention-based Reflection Controller Provider for Silex.
<?php
// src/Igorw/FooController.php
namespace Igorw;
class FooController
{
function getIndexAction()
{
@simensen
simensen / gist:4527433
Created January 14, 2013 02:41
PHP FQDN Golf scores
find src -name '*.php' | grep -iv tests | cut -f2- -d/ | cut -f1 -d\. | awk '{ print length, $0 }' | sort -n | tr / \\
<?php
/**
* Ideas for parameter converters
*
* I've used the word argument here rather than convert or converter,
* because there may not be any converting as such. It may be that things are
* plucked out of the request etc
*
* The idea being that some of the controller arguments come from the url,