Skip to content

Instantly share code, notes, and snippets.

@mindplay-dk
mindplay-dk / woohah.ts
Last active September 16, 2015 17:09
Typescript event hook and hookable boxed value classes
/// This interface defines an event listener
interface Listener<Event> {
(event: Event): void
}
/// This interface represents a hookable type
interface Hookable<Event> {
/// Attach a handler to this hookable
(handler: Listener<Event>): void
}
@mindplay-dk
mindplay-dk / session-life-cycle.md
Last active July 28, 2026 12:23
Complete overview of the PHP SessionHandler life-cycle

This page provides a full overview of PHP's SessionHandler life-cycle - this was generated by a set of test-scripts, in order to provide an exact overview of when and what you can expect will be called in your custom SessionHandler implementation.

Each example is a separate script being run by a client with cookies enabled.

To the left, you can see the function being called in your script, and to the right, you can see the resulting calls being made to a custom session-handler registed using session_set_save_handler().

@mindplay-dk
mindplay-dk / event-hooks.ts
Last active March 15, 2022 16:51
Type-safe event hooks in Typescript
type Handler<TEvent> = (event: TEvent) => void;
interface Hook<TEvent> {
(handler: Handler<TEvent>): void;
send(event: TEvent): void;
}
function hook<TEvent>(): Hook<TEvent> {
const handlers: Array<Handler<TEvent>> = [];
@mindplay-dk
mindplay-dk / UUID.php
Last active May 24, 2016 02:02
Basic UUID v4 creator
/**
* Basic UUID v4 creator
*/
abstract class UUID
{
/**
* @type string path to the dev/urandom device on Linux
*/
const DEV_URANDOM = '/dev/urandom';
@mindplay-dk
mindplay-dk / cookie.js
Created March 19, 2015 20:02
Simple client-side cookie reader/writer module in Typescript
@mindplay-dk
mindplay-dk / jquery.console.js
Created March 19, 2015 09:36
jquery.console.js
/**
* jQuery wrapper/plugin for console functions in FF/IE/Chrome.
*
* These functions execute silently when no console is available, so
* you can safely leave diagnotics calls in place during development
* and beta-testing.
*
* Examples:
*
* $.log('Hello, World.',1,2,3);
@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
@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 / modeling.md
Created February 11, 2015 17:00
Approaches to modeling

Approaches to modeling

In this short write-up, I will briefly summarize the types of modeling I have seen and attempted over the years, highlighting some of the advantages and drawbacks of each, ending with a conclusion explaining which one I prefer and why.

1. Bare Models

@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);