Skip to content

Instantly share code, notes, and snippets.

View Danack's full-sized avatar

Danack

  • Bristol, England
View GitHub Profile
<?php
define('BYTE_SAFE_PHRASE', 'byte safe');
define('PATH_TO_ROOT', '../');
// I always close off my php files with "\?\>" so as to detect accidental truncations
// Other people seem to leave that off, so only check certain directories for
// missing "\?\>" at the end of files.
CREATE TEMPORARY TABLE mediaSelected (
mediaId int,
itemId int
);
CREATE TEMPORARY TABLE mediaRejected (
mediaID int,
itemID int
);
@Danack
Danack / FizzBuzz
Created November 14, 2014 13:41
FizzBuzz functional in PHP
<?php
$defaultCase = function ($x) {
return $x."\n";
};
$buzz = function ($x, callable $modify) {
if (($x%5) == 0) {
return "Buzz\n";
@Danack
Danack / contra
Last active August 29, 2015 14:10
Contravariance for multiple interface
interface Document {}
interface JSONDocument extends Document {}
interface XMLDocument extends Document {}
// If PHP had it we could use covariance on the params
// interface Printer {
@Danack
Danack / ConstructorCleanup.md
Last active August 29, 2015 14:13
PHP constructor clean up

Hi,

I've been going through some bug reports, and have found there are several bad behaviours related to class constructors that ought to be corrected, but could only be done at a major version. The bad behaviours are:

Constructors returning null

Several classes in PHP return null when there is a problem in the parameters passed to their constructor e.g.

@Danack
Danack / batchStrace.sh
Created April 29, 2015 18:08
Batch strace
#!/bin/bash
# Prevent strace from abbreviating arguments?
# You want the -s strsize option, which specifies the maximum length of a string to display (the default is 32).
# running siege
# siege -d10 -c50 http://basereality.test
@Danack
Danack / ReferencesRock
Created May 5, 2015 12:21
References rock
<?php
$numbers = [];
define('size', 10000);
for ($i=0 ; $i<size; $i++) {
$numbers[] = $i;
}

Hold my beer and watch this

@Danack
Danack / BlockSelecting.sql
Last active December 10, 2015 21:59
How to order within blocks
// Given the following table:
//
// --------------
// | id | event |
// --------------
// | 00 | start |
// | 01 | data |
// | 02 | end |
// | 03 | data |
// | 04 | data |
@Danack
Danack / co-routines compared to class
Created May 10, 2013 18:47
Co-routines can be done as objects instead.
<?php
function loggerCoroutine(){
// set something up
$fileHandle = fopen($fileName, 'a');
while($continue == true){
//Do something
fwrite($fileHandle, yield . "\n");