Skip to content

Instantly share code, notes, and snippets.

View cameronjacobson's full-sized avatar

Cameron Jacobson cameronjacobson

View GitHub Profile
@cameronjacobson
cameronjacobson / reactphp_middleware.php
Created November 12, 2012 17:46
reactphp/react socket server middleware
<?php
define('CLIENT_PORT', 10000);
define('HOST','127.0.0.1');
define('SERVER_PORT', 10001);
gc_enable();
$loop = React\EventLoop\Factory::create();
@cameronjacobson
cameronjacobson / simple_gc_strategy.php
Created November 12, 2012 21:30
simplified GC strategy for long-running / high volume
<?php
define('SCRIPT_MEMORY_CONSUMPTION', memory_get_usage(true));
gc_enable();
/**
* we might call gc_collect_cycles if
* memory_get_usage >= original memory * threshold
*/
@cameronjacobson
cameronjacobson / tcp_monitor.php
Created November 13, 2012 00:01
Simplistic TCP Monitor
<?php
error_reporting(0);
define('MONITOR_INTERVAL', 60);
$monitors = [
['127.0.0.1',25,80,110]
];
@cameronjacobson
cameronjacobson / ReactStream.php
Created November 15, 2012 06:56
concept for react:// streamWrapper (reactphp/react)
<?php
class ReactStream {
private $components;
private $position;
private $queue;
function stream_open($path, $mode, $options, &$opened_path)
{
@cameronjacobson
cameronjacobson / EventLoop.php
Created November 16, 2012 13:52
early stages of a php libevent project (inspired by reactphp/react)
<?php
include('EventTrait.php');
class EventLoop
{
use EventTrait;
private $base;
private $events;
@cameronjacobson
cameronjacobson / useful
Created January 9, 2013 23:05
Useful links
How to do inferred dependency injection in PHP [similar to concept employed by AngularJS]
- http://php.net/manual/en/function.parsekit-func-arginfo.php
@cameronjacobson
cameronjacobson / gist:4533300
Last active December 11, 2015 02:48
reading AngularJS POST with PHP
<?php
// If you don't want to depend on HTTP client to serialize POST body into URI
// encoded format
// ** For Example: AngularJS doesn't natively POST the same way jQuery does.
$post = json_decode(file_get_contents('php://input'), true);
@cameronjacobson
cameronjacobson / simpletokenizer.php
Created January 19, 2013 14:19
Simple tokenizer which only splits on space character, while maintaining context for single or double-quoted strings. Uses include creation of very basic DSLs in PHP.
<?php
for($x=0;$x<strlen($argv[1]);$x++){
$tokens[] = getNextToken(substr($argv[1],$x),$x);
}
print_r($tokens);
function getNextToken($input,&$prefix){
@cameronjacobson
cameronjacobson / PhreezerExample.php
Last active December 15, 2015 08:29
Intuitive way to interact with CouchDB documents
<?php
/**
* Phreezer project page:
* https://github.com/cameronjacobson/Phreezer
*/
class Vehicle
{
public function __construct(){}
@cameronjacobson
cameronjacobson / form.php
Created August 17, 2013 07:13
bare-bones Browser-based S3 POST
<?php
if(isset($_GET['success'])){
echo 'done';
exit;
}
$policy = base64_encode(str_replace(array("\r","\n"),"",'{ "expiration": "2023-01-01T12:00:00.000Z", "conditions": [
{"acl": "public-read" },
{"bucket": "MYBUCKET" },