Skip to content

Instantly share code, notes, and snippets.

View cboden's full-sized avatar
📉
Munging data

Chris Boden cboden

📉
Munging data
View GitHub Profile
@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.
git clone https://github.com/reactphp/react source
cd source
# list all branches that should be preserved
# only version branches listed, as to skip WIP branches
git branch 0.3 origin/0.3
git branch 0.4 origin/0.4
#master is already included (default from clone)
# remove reference from origin to speed up rewriting its references
@steverhoades
steverhoades / gist:c7d2528491418bd06bd5
Created August 25, 2014 20:47
Blocking test with Event extension
<?php
require __DIR__ . '/../vendor/autoload.php';
/** @var $loop \React\EventLoop\ExtEventLoop */
$cfg = new \EventConfig();
$cfg->requireFeatures(\EventConfig::FEATURE_FDS);
$loop = new \React\EventLoop\ExtEventLoop($cfg);
$dir = getcwd();
$fd = fopen($dir . DIRECTORY_SEPARATOR . 'largefile', "r");
@clue
clue / ssl.php
Created August 31, 2014 09:46
Reproduce SSL buffering issue
<?php
use React\SocketClient\Connector;
use React\SocketClient\SecureConnector;
use React\Socket\Server;
use React\Stream\Stream;
require __DIR__ . '/../vendor/autoload.php';
$loop = React\EventLoop\Factory::create();
<?php
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use Ratchet\Server\IoServer;
use Ratchet\WebSocket\WsServer;
/**
* chat.php
* Send any incoming messages to all connected clients (except sender)
*/
@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,
<?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,
@lrvick
lrvick / controllers.js
Last active December 14, 2015 19:09
Websocket AngularJS controller/services pattern
app.controller( 'AppCtrl', function ($scope, socket) {
socket.onopen(
function(){
console.log('Socket is connected :D')
}
)
socket.onclose(
function(){
console.log('Socket is disconnected :(')
}
@igorw
igorw / gist:7030479
Last active December 25, 2015 19:49
alternate react API
<?php
React\Socket\connect('igor.io')
->then(function ($conn) {
$conn->write('foo');
$conn->end();
});
React\DNS\resolve('igor.io')
->then(function ($host) {
@mloughran
mloughran / page.html
Created March 16, 2012 19:27
Mobile Safari crash when returning to WebSocket page
<html>
<head>
<script>
function debug(string) {
var element = document.getElementById("debug");
var p = document.createElement("p");
p.appendChild(document.createTextNode(string));
element.appendChild(p);
}