Skip to content

Instantly share code, notes, and snippets.

View Danack's full-sized avatar

Danack

  • Bristol, England
View GitHub Profile

Hold my beer and watch this

@Danack
Danack / ReferencesRock
Created May 5, 2015 12:21
References rock
<?php
$numbers = [];
define('size', 10000);
for ($i=0 ; $i<size; $i++) {
$numbers[] = $i;
}
@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 / gist:6bd30de6247bc5148986
Last active April 13, 2017 08:23
PHP memory recursive.
<?php
$performGC = false;
if ($performGC) {
echo "GC collection will be done - app should not crash.\n";
}
else {
echo "GC collection won't be done - app should crash.\n";
@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 / 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 / batchStrace
Last active February 25, 2020 03:28
Strace all the PHP-FPM
#!/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).
# -etrace=!open means to trace every system call except open. In addition, the special values all and none have the obvious meanings.
#-etrace=!open
#-e trace=!write.
@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 / Mem Test Output
Last active July 12, 2019 22:33
An example of how creating cycles in variables leads to
Without manually calling gc_collect_cycles()
============================================
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 139264 bytes) in - on line 27
GC Statistics
-------------
Runs: 0
CREATE TEMPORARY TABLE mediaSelected (
mediaId int,
itemId int
);
CREATE TEMPORARY TABLE mediaRejected (
mediaID int,
itemID int
);