Skip to content

Instantly share code, notes, and snippets.

View mattparker's full-sized avatar

Matt Parker mattparker

View GitHub Profile
@mattparker
mattparker / CustomerSpecificationSet.php
Last active August 29, 2015 13:56
Building up specifications
<?php
// This relates to Matthias Verraes talk on unbreakable domain models
// (which is very good). Slides are http://verraes.net/2013/06/unbreakable-domain-models/
// and this is about the end of the talk (about three-quarters through the slide deck).
//
// I like the whole specification thing, but want to be able to combine them
// dynamically (in the language of the talk, the tenant can create their own
// specification of what a premium custom is), using building blocks we provide.
class CustomerSpecificationSet
@mattparker
mattparker / uses for traits.md
Last active December 28, 2015 14:29
Traits

Replace globals

E.g.

trait ConfigProvider {
    
    private $_configProviderConfig;
    
    public function setConfigProvider($cfg) {
 }
@mattparker
mattparker / gist:5636276
Created May 23, 2013 14:00
amends yui scroll beacon to add a 'left' synthetic event
/* Gallery beacon with extra module */
YUI.add('gallery-scroll-beacon', function(Y) {
/**
* Provides synthetic event to detect beacon element arriving in or leaving the browser viewport.
*
* @module scroll-beacon
*/
/**
@mattparker
mattparker / yui2uploaderpatch.js
Last active December 16, 2015 21:49
Patches for YUI2 Uploader for IE9+
////////////////////////////////////////////////////
////////////////////////////////////////////////////
// Patch
//
// Was using a non-standard quirk of IE to do
// document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />')
// when it should really be just document.createElement('iframe') and then add attributes
// IE9 is strict about this and breaks.
//
//
@mattparker
mattparker / gist:5420634
Last active December 16, 2015 10:29 — forked from lsmith/gist:5417052
var buildParser = Y.cached(function (prefix, suffix, separator, decimal) {
var regexBits = []
regex;
if (prefix) {
regexBits.push('^' + prefix.replace(safeRegExp, '\\$1'));
}
if (suffix) {
regexBits.push(suffix.replace(safeRegExp, '\\$1') + '$');
}
@mattparker
mattparker / wheresTheMemory.js
Created April 3, 2013 22:39
A little hacky effort at testing YUI javascript memory usage using Node.js and phantomjs
var util = require('util')
http=require('http'),
phantom=require('node-phantom'),
// simple logging of memory use:
memoryCache = [0],
logMemory = function (msg) {
var mem = process.memoryUsage();
//console.log(msg + " current memory use: ", util.inspect(process.memoryUsage()));
console.log(msg + " heapUsed change: " + (mem.heapUsed - memoryCache[memoryCache.length - 1]));
@mattparker
mattparker / gist:4505998
Created January 10, 2013 21:34
docblock efforts for strtotime
/**
* @class Date
* @static
*/
/**
* @for Date
* @method strtotime
*
* Parses English (or other languages) date-related sentences into
@mattparker
mattparker / _getOffsetAndFinish.js
Created November 6, 2012 17:27
idea for kb refactor of Y.Color.Harmony
/**
Generates a series of colors from startColor at various offsets
@protected
@method _getOffsetAndFinish
@param {String} startColor Start color
@param {Array} arrOffsets Array of colors
@param {String} [to]
@returns {Array} Of offsetted and finished colors
**/
_getOffsetAndFinish: function (startColor, arrOffsets, to) {
@mattparker
mattparker / graphics-static-chooser.js
Created October 16, 2012 12:34
To assign the correct graphics implementation when all are loaded statically
// relates to YUI ticket http://yuilibrary.com/projects/yui3/ticket/2532864
//
//
YUI.add("graphics-static-chooser", function (Y) {
//
//
// Loading graphics (statically) using the configurator is tricky,
// because it feature detects on the browser you're using the configurator
@mattparker
mattparker / arrayset.test.js
Created October 8, 2012 09:23
Test cases for Y.Array set methods (https://gist.github.com/3527740)
YUI.add("arraySet-tests", function (Y) {
var ASSERT = Y.Assert,
ARRAYASSERT = Y.ArrayAssert;
var testSimpleIntersects = new Y.Test.Case({
name: "Test of simple arrays of numbers, strings",
testNumbers: function () {