Skip to content

Instantly share code, notes, and snippets.

View pierswarmers's full-sized avatar
🏡
Working remotely since 2018

Piers Warmers pierswarmers

🏡
Working remotely since 2018
View GitHub Profile
<template name="coll" value="class $COLLECTION$ implements \Countable, \IteratorAggregate&#10;{&#10; private $$$INTERNAL_STORE$;&#10;&#10; public function __construct($ENCAPSULATED_TYPE$ ... $$$INTERNAL_STORE$) &#10; { &#10; $this-&gt;$INTERNAL_STORE$ = $$$INTERNAL_STORE$; &#10; }&#10;&#10; public function count(): int &#10; { &#10; return count($this-&gt;$INTERNAL_STORE$); &#10; }&#10; &#10; /**&#10; * @return \Traversable|$ENCAPSULATED_TYPE$[]&#10; */&#10; public function getIterator(): \Traversable &#10; {&#10; foreach ($this-&gt;$INTERNAL_STORE$ as $$$ITEM_VAR$)&#10; {&#10; yield $$$ITEM_VAR$;&#10; }&#10; }&#10; }" description="Typed immutable collection" toReformat="true" toShortenFQNames="true">
<variable name="COLLECTION" expression="" defaultValue="" alwaysStopAt="true" />
<variable name="INTERNAL_STORE" expression="camelCase(COLLECTION)" defaultValue="" alwaysStopAt="false" />
<variable name="ENCAPSU
@pierswarmers
pierswarmers / parallel_testing.php
Created June 1, 2018 04:57
Legacy Refactor with Comparative Analysis
<?php
function processOrder(Order $order): Invoice
{
$invoiceA = $order->processOrderOnLegacyLogic();
$invoiceB = $order->processOrderOnRefactoredLogic();
if($invoiceA->getTotal() !== $invoiceB->getTotal()) {
$this->log->error(
'Invoice comparison failed.',
@pierswarmers
pierswarmers / flattenExceptionBacktrace.php
Created December 18, 2017 23:38 — forked from Thinkscape/flattenExceptionBacktrace.php
Make any PHP Exception serializable by flattening complex values in backtrace.
<?php
function flattenExceptionBacktrace(\Exception $exception) {
$traceProperty = (new \ReflectionClass('Exception'))->getProperty('trace');
$traceProperty->setAccessible(true);
$flatten = function(&$value, $key) {
if ($value instanceof \Closure) {
$closureReflection = new \ReflectionFunction($value);
$value = sprintf(
'(Closure at %s:%s)',
#!/bin/bash
DYNAMODB_USER=vagrant
sudo apt-get install openjdk-7-jre-headless -y
cd /home/${DYNAMODB_USER}/
mkdir -p dynamodb
cd dynamodb
<?php
use ManDate\Mandate;
use ManDate\Rule\WeekdayRule;
use ManDate\Rule\DaytimeRule;
use ManDate\Rule\MorningRule;
$mandate = new Mandate();
$mandate
@pierswarmers
pierswarmers / check.sh
Created March 9, 2015 23:50
PHP Project: Syntax Checker, Unit Test and Git Commiter
#!/bin/bash
guiltmode=0
browse=0
push=0
iconbeer="🍺"
phpunitconfig="app"
phpunitdir="src"
coveragelocation="./coverage/index.html"
@pierswarmers
pierswarmers / nginx-symfony2
Last active December 10, 2015 16:59
Nginx config for Symfony2
server {
server_name www;
root /usr/share/nginx/www;
index app.php;
try_files $uri $uri/ /app.php?$query_string;
location ~ ^/(app_dev|app)\.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
@pierswarmers
pierswarmers / mobile-meta-links.html
Created October 11, 2012 23:36
iOS Web App Configuration
@pierswarmers
pierswarmers / less_watcher.sh
Created September 4, 2012 04:25
Script to run watchr and compile LESS
#!/bin/bash
# These are the original commands, courtesy of:
# http://www.ravelrumba.com/blog/watch-compile-less-command-line/
# Requires watchr: https://github.com/mynyml/watchr
# watchr -e 'watch(".*\.less$") { |f| system("lessc #{f[0]} > #{f[0]}.css && echo \"#{f[0]} > #{f[0]}.css\" "}') }
# Requires inotify-tools: https://github.com/rvoicilas/inotify-tools
# while true;do N=`find -name "*.less" `;inotifywait -qe modify $N ;for f in $N;do lessc $f ${f%.*}.css;done;done
@pierswarmers
pierswarmers / less_watcher.sh
Created September 4, 2012 04:24
Script to run watchr and compile LESS
#!/bin/bash
# These are the original commands, courtesy of:
# http://www.ravelrumba.com/blog/watch-compile-less-command-line/
# Requires watchr: https://github.com/mynyml/watchr
# watchr -e 'watch(".*\.less$") { |f| system("lessc #{f[0]} > #{f[0]}.css && echo \"#{f[0]} > #{f[0]}.css\" "}') }
# Requires inotify-tools: https://github.com/rvoicilas/inotify-tools
# while true;do N=`find -name "*.less" `;inotifywait -qe modify $N ;for f in $N;do lessc $f ${f%.*}.css;done;done