Skip to content

Instantly share code, notes, and snippets.

@jm42
jm42 / btree.class.php
Created February 12, 2016 04:41
BTree tagged union
<?php
abstract class Tree {}
class Leaf extends Tree {
function __construct($n) {
$this->value = $n;
}
}
@jm42
jm42 / http.php
Created December 23, 2015 13:06
HTTP Server
<?php
class Request {
public $get;
public $post;
public $server;
function __construct($server, $get, $post) {
$this->get = $get;
$this->post = $post;
@jm42
jm42 / logger.php
Created December 21, 2015 17:53
Simple logger
<?php
// Smaller and friendlier (?) alternative to https://github.com/badphp/logger
function logger($path, $priority=0) {
return function($level, $msg) use($path, $priority) {
if ($level > $priority) {
return false;
}
<?php
use App\Config\Configurator;
use App\Config\ConflictException;
use App\HTTP\Message;
use App\HTTP\Request;
use App\HTTP\Response;
class ConfiguratorTest extends \PHPUnit_Framework_TestCase
<?php
namespace App;
use App\Config\Configurator;
use App\HTTP\Request;
class App {
private $name;
private $config;
@jm42
jm42 / partial1.php
Created December 13, 2015 22:48
Example of partial1 in PHP
<?php
function partial1(/* A */ $a, /* (A, B) => C */ callable $f) /* B => C */ {
return function(/* B */ $b) use($a, $f) {
return $f($a, $b);
};
}
/* A :: String
* B :: String
@jm42
jm42 / match.php
Created December 13, 2015 19:20
Match and call... match and call.
<?php
function match() {
func_num_args() or die('Remember the milk?');
$fnm = function() { return true; };
$fns = func_get_args();
if (is_string($match = func_get_arg(0))) {
$fnm = function() use($match) {
@jm42
jm42 / trvoid.py
Created December 11, 2015 15:00
Travel to the Void -- a game in progress
import pygame
import math
from random import random, randint, uniform
WIDTH = 640.0
HEIGHT = 480.0
CENTER = (WIDTH / 2.0, HEIGHT / 2.0)
class SceneManager:
@jm42
jm42 / doctest.php
Created December 10, 2015 01:00
Unit testing from documentation
<?php
/**
* PHP Doc. Tests
* ==============
*
* Unit testing library that extract tests from documentation.
*
* This is only a POC and should not be used in production.
*
* Under the WTFPL-2.0 license.
// ==UserScript==
// @name OK Plus
// @namespace guide42
// @description Enchant OK Cupid
// @include http://www.okcupid.com/*
// @include https://www.okcupid.com/*
// @version 0.1
// ==/UserScript==
;(function($, window, undefined) {