Skip to content

Instantly share code, notes, and snippets.

View mattparker's full-sized avatar

Matt Parker mattparker

View GitHub Profile
@mattparker
mattparker / onename
Created January 8, 2016 12:20
onename
Verifying that +mattparker is my blockchain ID. https://onename.com/mattparker
@mattparker
mattparker / install-and-compile-php7
Last active November 28, 2021 17:36
running php tests with lcov/gcov - setup and getting close
# install lcov
apt-get update
apt-get install lcov
mkdir /usr/local/php70-gcov5
cd ~/php-src
./configure --enable-gcov --prefix=/usr/local/php70-gcov5 --with-apxs2=/usr/bin/apxs2 --with-gd --without-pear --with-jpeg-dir=/usr --with-png-dir=/usr --with-vpx-dir=/usr --with-freetype-dir=/usr --with-t1lib=/usr --enable-gd-native-ttf --enable-exif --with-config-file-path=/etc/php7 --with-config-file-scan-dir=/etc/php7/conf.d --with-mysql=/usr --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-zlib --with-gmp --with-zlib-dir=/usr --with-gettext --with-kerberos --with-imap-ssl --with-mcrypt=/usr/local --with-iconv --enable-sockets --with-openssl --with-pspell --with-pdo-mysql=mysqlnd --with-pdo-sqlite --enable-soap --enable-xmlreader --with-xsl --enable-ftp --enable-cgi --with-curl=/usr --with-tidy --with-xmlrpc --enable-mbstring --enable-sysvsem --enable-sysvshm --enable-shmop --with-readline --enable-fpm --enable-intl --enable-zip --with-imap --with-mysqli=mysqlnd --enable-calendar
make
make install
@mattparker
mattparker / installing gcov and ltp for php.md
Last active December 3, 2023 05:08
trying to compile php with gcov
vagrant@php7dev:~/php-src$ ./configure --enable-gcov --prefix=/usr/local/php70-gcov

gives, eventually:

configure: error: To enable code coverage reporting you must have LTP installed
@mattparker
mattparker / tweettopic
Last active August 29, 2015 14:14
picture your tweet
javascript:(function () {
var d = document.createElement('canvas'),
ctx = d.getContext('2d'),
tweet = document.querySelector('.expanded-conversation .tweet .tweet-text'),
box,
w,
h = 80,
x = 0,
code_to_0256 = function (code) {
@mattparker
mattparker / pic-of-a-page
Last active August 29, 2015 14:14
Makes an image out of the content of a webpage
javascript:(function () {
var d = document.createElement('canvas'),
ctx = d.getContext('2d'),
w = window.innerWidth,
h = window.innerHeight,
x = 0,
code_to_0256 = function (code) {
if (code < 32 || code > 127) {
code = 90;
@mattparker
mattparker / mongo-test.php
Last active August 29, 2015 14:06
Using breakpoints to trigger deprecated errors
<?php
error_reporting(E_ALL);
$host = 'mongodb://127.0.0.1/test';
echo "\n Testing deprecated MongoClient::connected property \n";
$client1 = new \MongoClient($host);
echo "done"; // breakpoint on this line triggers deprecation notice
@mattparker
mattparker / super.php
Created April 22, 2014 13:13
why php is super
<?php
class Marvellous implements Community {
public function smart () {
return true;
}
public function helpful () {
return true;
}
public function join (Anyone $person) {
return true;
@mattparker
mattparker / pre-post-conditions.js
Created March 18, 2014 20:36
pre and post conditions in js
// this: https://twitter.com/raganwald/status/445938910808391680
// Wrap a function f (which accepts two arguments, and b) to enforce
// preconditions (if I understand them correctly) are guards on
// parameter values
// You can also optionally add a postcondition afterwards
// though it'd be nicer to add this in the main preCondition function really
<?php
// Domain expert says:
// Tenant can construct their own 'premium customer specification' from a list of ingredients
// Tenant chooses 3 orders, one in the last month:
$spec1 = new CustomerWith3OrdersIsPremium();
$spec2 = new CustomerWithRecentOrderIsPremium();
$allSpecs = new CompositeCustomerSpecification();
$allSpecs->add($spec1)->add($spec2);
@mattparker
mattparker / SqlSpecification.php
Last active August 29, 2015 13:56
Including SQL in Specifications
<?php
// This is another response to Mattias Verraes talk on unbreakable domain
// models (slides at http://verraes.net/2013/06/unbreakable-domain-models/)
// Near the end there's a bit where he suggests you implement business logic
// rules initially as code (i.e. an array filter) and secondly as sql.
// You can then test that these are consistent (though the tests in the talk
// don't show correctness, there needs to be a test against a known good result
// too). But with that, it seems like a nice way to have testable SQL.
// A problem for me with the example (which is obviously shortened for the slide example)