Skip to content

Instantly share code, notes, and snippets.

@mindplay-dk
mindplay-dk / shared-toolbar.js
Last active March 21, 2016 10:21
Shared toolbars plugin for Guardian's Scribe editor
define(function () {
"use strict";
var active_scribe = null;
function create_handler_for(button) {
return function (event) {
if (!active_scribe) {
return;
}
@mindplay-dk
mindplay-dk / anonymous.php
Created March 10, 2016 11:25
class or object???
<?php
// anonymous classes are both instances and types. huh? what?
$type = new class {
public function foo() {
echo "YAY";
}
};
@mindplay-dk
mindplay-dk / dafuq.php
Created March 10, 2016 09:19
DAFUQ PHP?
<?php
function kthxbai() {
$result = "hey";
try {
return $result;
} finally {
$result = "dafuq";
}
@mindplay-dk
mindplay-dk / Container.php
Last active February 16, 2022 16:37
Minimal DI container
<?php
class Container
{
/** @var Closure[] */
private $factories = [];
/** @var array */
private $components = [];
@mindplay-dk
mindplay-dk / blah.md
Last active February 16, 2016 07:38
Documenting accessors

How do you document model attributes implemented using synchronous accessor methods?

Example - bare model, no documentation:

class Contact
{
    protected $phone;
    
    public function getPhone() {
@mindplay-dk
mindplay-dk / hooks.ts
Last active October 26, 2015 10:07
Type-safe event hooks and boxed values (aka "getter-setters") in Typescript
/// This interface defines an event listener
interface IListener<Event> {
(event: Event): void
}
/// This interface represents an event hook
interface IHook<Event> {
/// Attach a handler to this hookable
(handler: IListener<Event>): void
@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 March 28, 2024 19:52
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';