Skip to content

Instantly share code, notes, and snippets.

@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);
@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 / 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 / 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 / Cache.php
Last active May 6, 2017 18:20
Simplied cache interface
<?php
namespace Psr\Cache;
/**
* Cache defines a common driver interface for interacting with a cache back-end.
*/
interface Driver
{
/**
@mindplay-dk
mindplay-dk / psr6.md
Last active May 6, 2017 18:20
PSR-6 cache interface review

I just learned about the proposed cache PSR, and I have to speak up.

I must apologize in advance, as my tone may get harsh or sarcastic, but it really upsets me to see a proposed standard which probably a lot of developers will end up following, to their detriment.

First off, FIG is the "Framework Interop Group" - did you actually look at other frameworks to see what they're doing? ZF2, Laravel, Doctrine, Symfony and Yii, to name a few of the major ones - not a single one of those use an aggregate model for individual cache items. How exactly is this standard supposed to help these frameworks interoperate?

For another, none of the cache providers you're going to be wrapping with this interface use an aggregate model - and for the most part this is probably deliberate, because the operations on a cache are supposed to be very focused and atomic, allowing you to optimize by doing as little work as possible.

This kind of thinking seems

@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 / rm_r.php
Last active February 14, 2025 06:31
Recursively delete a directory and all of it's contents - USE AT YOUR OWN RISK!
<?php
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
# http://stackoverflow.com/a/3352564/283851
/**
* Recursively delete a directory and all of it's contents - e.g.the equivalent of `rm -r` on the command-line.
@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