Skip to content

Instantly share code, notes, and snippets.

View clue's full-sized avatar

Christian Lück clue

View GitHub Profile
<?php
$loop = React\EventLoop\Factory::create();
$logger = new \Zend\Log\Logger();
$writer = new \Zend\Log\Writer\Syslog(array('application' => 'movim'));
$logger->addWriter($writer);
$connector = new Ratchet\Client\Factory($loop);
#!/bin/bash
#
# git-mv-with-history -- move/rename file or folder, with history.
#
# Moving a file in git doesn't track history, so the purpose of this
# utility is best explained from the kernel wiki:
#
# Git has a rename command git mv, but that is just for convenience.
# The effect is indistinguishable from removing the file and adding another
# with different name and the same content.
@clue
clue / example.php
Created July 3, 2015 08:32
React\Promise\uncancellable()
$cancellable = new Promise(function () { }, function ($resolve, $reject) { $reject(); });
$uncancellable = uncancellable($cancellable);
assertPending($cancellable);
assertPending($uncancellable);
// this is a NO-OP
$uncancellable->cancel();
assertPending($cancellable);
assertPending($uncancellable);
@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));