Skip to content

Instantly share code, notes, and snippets.

View WyriHaximus's full-sized avatar
🐉
Breathing Fire

Cees-Jan Kiewiet WyriHaximus

🐉
Breathing Fire
View GitHub Profile
@WyriHaximus
WyriHaximus / auto_helper.php
Created October 31, 2010 10:42
Added some code to make it work with plugins
<?php
/**
* AutoHelperView
* Provides automatic helper loading for views.
*
* @author Joe Beeson <jbeeson@gmail.com>
* @auther Cees-Jan Kiewiet <ceesjank@gmail.com>
*/
class AutoHelperView extends View {
upstream websocketdomain{
server 127.0.0.1:54321;
}
server {
server_name domain;
access_log /path/to/logs/domain.access_log;
error_log /path/to/logs/domain.error_log;
@WyriHaximus
WyriHaximus / Twitter streaming API listener
Created November 21, 2013 11:14
This bit of react/http-client listens on the twitter streaming API.
$buffer = '';
$request = $this->client->request($method, $url, $headers);
$request->on('response', function($response) use (&$buffer) {
$response->on('data', function($data) use (&$buffer) {
$buffer .= $data;
if (strpos($buffer, PHP_EOL) !== false) {
$tweets = explode(PHP_EOL, $buffer);
$buffer = array_pop($tweets);
foreach ($tweets as $tweet) {
if (strlen(trim($tweet)) > 0) {
@WyriHaximus
WyriHaximus / MetadataSerializer.php
Last active December 29, 2015 05:09
Add any metadata and serialize it.
<?php
use Flysystem\FilesystemInterface;
use Flysystem\PluginInterface;
class MetadataSerializer implements PluginInterface {
protected $filesystem;
protected $fieldName;
@WyriHaximus
WyriHaximus / keybase.md
Created March 24, 2014 15:27
keybase.md

Keybase proof

I hereby claim:

  • I am WyriHaximus on github.
  • I am Wyrihaximus (https://keybase.io/Wyrihaximus) on keybase.
  • I have a public key whose fingerprint is 40D0 D8C1 E5DD 7306 3892 149D ADF6 175A D7DA 8B95

To claim this, I am signing this object:

$buffer = '';
$conn->on('data', function($data, $conn) use (&$buffer) {
$buffer .= $data;
if (strpos($buffer, PHP_EOL) !== false) {
$lines = explode(PHP_EOL, $buffer);
$buffer = array_pop($lines);
foreach ($lines as $line) {
// do something with $line
}
}
public function ls() {
$deferred = new Deferred();
$this->filesystem->ls($this->path)->then(function($result) use ($deferred) {
$this->filesystem->getLoop()->futureTick(function() use ($result, $deferred) {
$this->processLsContents($result, $deferred);
});
}, function($error) use ($deferred) {
$deferred->reject($error);
public function chownRecursive($uid = -1, $gid = -1) {
$deferred = new Deferred();
$this->ls()->then(function($list) use ($deferred, $uid, $gid) {
$this->filesystem->getLoop()->futureTick(function() use ($list, $deferred, $uid, $gid) {
$promises = [];
foreach ($list as $node) {
if ($node instanceof Directory) {
protected $recursiveInvoker;
protected function getRecursiveInvoker() {
if ($this->recursiveInvoker instanceof RecursiveInvoker) {
return $this->recursiveInvoker;
}
$this->recursiveInvoker = new RecursiveInvoker($this);
return $this->recursiveInvoker;
<?php
require 'vendor/autoload.php';
$loop = \React\EventLoop\Factory::create();
function yieldPromiseA($promise) {
while (true) {
echo 'a', PHP_EOL;
echo (yield \Async\Util::async($promise)), PHP_EOL;