Skip to content

Instantly share code, notes, and snippets.

<?php
class Emitter implements EmitterInterface {
private $listeners = [];
private $order = PHP_INT_MAX;
public function on($event, callable $listener, $priority=0)
{
if (array_key_exists($event, $this->listeners) === false) {
$this->listeners[$event] = new \SplPriorityQueue;
<?php
class Router implements RouterInterface {
private $root;
private $routes = [];
public function __construct($root) {
$this->root = $root;
}
@jm42
jm42 / adr.php
Created October 5, 2015 05:21
ADR Example
<?php
class App {
public $queue = [];
public $routes = [];
public $container;
public $resolver;
@jm42
jm42 / app.php
Created October 5, 2015 23:14
Container Builder
<?php
namespace A;
use A\Container\Builder as ContainerBuilder;
class App {
public $root; /** root directory given when initilizated */
public $container; /** an array-like object to retrieve services from */
@jm42
jm42 / log.php
Created October 5, 2015 23:17
Simple Log Interface
<?php
interface Logger {
const CRITITAL = 50;
const ERROR = 40;
const WARNING = 30;
const INFO = 20;
const DEBUG = 10;
/** Logs a message with integer level $level on this logger.
@jm42
jm42 / bootstrap.php
Created October 11, 2015 23:42
Bootstrap test
<?php
### LOADER ###################################################################
include 'https://gist.githubusercontent.com/jm42/0bafdc8792c90bdec3a7/raw/c420e913bffd54878be2b23cda1e7ade6843d6ff/loader.php';
class PHPLoader extends Loader {
public function load($resource) {
include $resource;
}
<?php
function call_funcs(array $fns, array $args) {
switch (true) {
case empty($fns): return $args;
case count($fns) === 1: return call_user_func_array($fns[0], $args);
default: return call_user_func('call_funcs', array_slice($fns, 1), (array) call_user_func_array($fns[0], $args));
}
}
@jm42
jm42 / play.py
Last active October 28, 2015 13:38
Play littlealchemy.com
"""Play Little Alchemy"""
from selenium.webdriver import Firefox
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import StaleElementReferenceException, \
MoveTargetOutOfBoundsException
from os.path import join, dirname, abspath
from time import sleep
@jm42
jm42 / gendoc.php
Created October 29, 2015 21:20
Quick & Dirty (tm) PHP literate doc generator
#!/usr/bin/env php
<?php
/** Documentation Generator
*
* Command line little script that given a PHP file name will generate an HTML
* with it's documentation.
*/
function parse_doc($doc) {
$lines = preg_split('#(\r\n|\n)#', $doc);
@jm42
jm42 / settings.php
Created November 18, 2015 03:18
Settings using Choclo
<?php
class Settings extends Configurator implements \ArrayAccess {
private $path;
private $values;
function __construct($path) {
$this->path = $path;
$this->values = [];
}