Skip to content

Instantly share code, notes, and snippets.

View clue's full-sized avatar

Christian Lück clue

View GitHub Profile
@clue
clue / StreamUnblock.php
Last active December 10, 2015 13:08
extend base React\Stream\Stream class by checking stream meta data for remaining stream buffer before reading from blocking streams
<?php
// extend base Stream class by checking stream meta data for remaining stream buffer before reading from blocking streams
// heavily inspired by: https://github.com/clue/Worker/commit/8c6d7a4e733f0ee5aa431ffda1d4929229ae2336
class StreamUnblock extends \React\Stream\Stream
{
public function handleData($stream)
{
// check stream meta data for remaining buffer
// yes, the manual explicitly says this value SHOULD NOT be used,
@clue
clue / DatagramClient.php
Last active December 11, 2015 05:19
[deprecated] moved to https://github.com/clue/datagram [DRAFT] UDP DatagramClient and DatagramServer built on top of reactphp
<?php
class DatagramClient extends DatagramSocketReadable
{
public function __construct($loop, $socket, $address = null)
{
if ($address === null) {
$address = stream_socket_get_name($socket, true);
}
parent::__construct($loop, $socket, $address);
<?php
class SocketStreamAdapter extends EventEmitter
{
const DELAY_TICK = 0.01;
const DURATION_TICK = 0;
protected $loop;
protected $socket;
@clue
clue / defaultstub.php
Created May 24, 2013 08:25
Phar::createDefaultStub()
<?php
$web = 'web/index.php';
if (in_array('phar', stream_get_wrappers()) && class_exists('Phar', 0)) {
Phar::interceptFileFuncs();
set_include_path('phar://' . __FILE__ . PATH_SEPARATOR . get_include_path());
Phar::webPhar(null, $web);
include 'phar://' . __FILE__ . '/' . Extract_Phar::START;
return;
@clue
clue / thejit.php
Last active December 18, 2015 10:59
thejit graph transformer prototype/mockup
<?php
use Fhaculty\Graph\Graph;
use Fhaculty\Graph\Vertex;
use Fhaculty\Graph\Algorithm\Tree\OutTree as Tree;
class TheJit
{
private $graph;
@clue
clue / Phakefile.php
Created December 20, 2013 10:34
jaz303/phake Loading vendor/autoload.php fails https://github.com/jaz303/phake/issues/33
<?php
require __DIR__ . '/vendor/autoload.php';
task('default', function() {
echo 'Does not work.';
});
<?php
$stream = stream_socket_client('tcp://www.example.com:80');
assert(is_resource($stream));
fclose($stream);
assert(!is_resource($stream));
<?php
var_dump(array_rand(array()) === null);
@clue
clue / gist:8645729
Last active January 4, 2016 16:09
redis benchmark
host:~$ redis-server --version
Redis server v=2.6.13 sha=00000000:0 malloc=jemalloc-3.3.1 bits=64
host:~$ echo "port 1338" | redis-server -
host:~$ redis-benchmark -p 1338 -q
PING_INLINE: 156250.00 requests per second
PING_BULK: 185185.19 requests per second
SET: 192307.69 requests per second
GET: 188679.25 requests per second
INCR: 192307.69 requests per second
LPUSH: 200000.00 requests per second
@clue
clue / README.md
Last active August 29, 2015 13:57
Running Ratchet test suite in a clean schroot

This gist demonstrates how to use a transient (temporary) schroot environment to set up a controlled environment to run the Ratchet test suite. It assumes you're running this on a recent version of Ubuntu (a virtual machine will do as well).

  • We want to run the test suite in isolation without installing the required tools on our host.
  • Instead, all tools will be installed in a transient schroot that will be reset whenever we leave it.
  • The schroot is a convenient wrapper to set up a blank system in a chroot, but still provides access to your home directory where the workspace (Ratchet) is installed.
  • This allows us to easily hack the source code on the host system and running exactly the same code in the schroot test environment.
  • As such, you can read/write to your home directory from within your schroot, which is convenient in our case. Obviously, this is not a safe option if you're running untrusted code.
  • We use debootstrap to set up a new Ubuntu Precise (12.04 LTS) VM.