Skip to content

Instantly share code, notes, and snippets.

@mindplay-dk
mindplay-dk / view-proxy.php
Created January 29, 2014 22:52
Sort of like the presenter pattern, I guess - but the View can proxy any view-model type (no base class required) and can e.g. html-encode or filter and of it's properties... plus you get auto-completion and inspections via the type-hint on $view in an IDE...
<?php
/**
* This class acts as a proxy for arbitrary view-models
*/
class View
{
/**
* @var ViewModel raw view-model
*/
@mindplay-dk
mindplay-dk / auth.php
Created March 12, 2014 21:30
Authorization service and context
<?php
/**
* Provides authorization services
*/
class AuthorizationService
{
/** @var AuthorizationRules */
public $rules;
@mindplay-dk
mindplay-dk / bench.js
Created March 22, 2014 04:36
JavaScript benchmark function
// noprotect
/**
* JavaScript benchmark function
*
* Usage: console.log(bench(function(){ ... }));
*/
bench = (function() {
var
@mindplay-dk
mindplay-dk / bench.php
Created July 19, 2014 09:16
Cut-and-paste benchmarking library with baseline compensation and weighted averages
<?php
header('Content-type: text/plain');
define('NUM_RUNS', 200); // total number of runs/readings
define('NUM_LOOP', 100); // number of iterations per run
// benchmark a function using various PHP features to establish
// a performance baseline for the PHP version / platform / etc.:
@mindplay-dk
mindplay-dk / error-relay.php
Last active August 29, 2015 14:08
Relay php errors to exceptions
<?php
/**
* Map php errors to the built-in ErrorException class.
*
* Respects the error_reporting() setting and the error-suppression operator.
*
* @see ErrorException
*/
@mindplay-dk
mindplay-dk / hook.php
Created November 12, 2014 08:30
GitHub service hook example in PHP
<?php
// basic GitHub service hook example
$payload = file_get_contents("php://input");
$secret_key = 'secret';
$computed_signature = 'sha1=' . hash_hmac('sha1', $payload, $secret_key, false);
@mindplay-dk
mindplay-dk / README.md
Last active August 29, 2015 14:14
Replace a checkbox with a custom div for styling

jQuery plugin to replace checkboxes with <div> elements for styling.

This plugin makes no assumptions about class-names or the contents of the <div> element, it only implements the behavior - it returns the generated <div> elements for further operations with jQuery functions, so you can do for example:

$('input[type=checkbox]')
    .checkbox()            // returns set of <div> elements
    .addClass('checkbox')  // adds class="checkbox" to every <div> element

.html('✔') // inserts a unicode checkmark into every element

@mindplay-dk
mindplay-dk / README.md
Last active August 29, 2015 14:14
Semantic grid mix-ins for LESS

Example LESS file:

.layout {
    .row();    
    background: #ddd;
}

.nav {
 .col(4);
@mindplay-dk
mindplay-dk / run.php
Last active August 29, 2015 14:15
Example middleware using Walkway as a router with Conduit
<?php
use mindplay\walkway\Route;
use Phly\Conduit\MiddlewareInterface;
use Phly\Conduit\MiddlewarePipe;
use Phly\Http\Server;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
require __DIR__ . '/vendor/autoload.php';
@mindplay-dk
mindplay-dk / ConduitFilterAdapter.php
Last active August 29, 2015 14:15
Draft filter interface for standardization of message exchange
<?php
// Sample implementation of a FilterInterface apadater for Conduit (UNTESTED)
use Phly\Conduit\MiddlewareInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\FilterInterface as Filter;
class ConduitFilterAdapter implements MiddlewareInterface