Skip to content

Instantly share code, notes, and snippets.

Avatar

Danack

  • Bristol, England
View GitHub Profile
View foo.md

Hold my beer and watch this

View ReferencesRock
<?php
$numbers = [];
define('size', 10000);
for ($i=0 ; $i<size; $i++) {
$numbers[] = $i;
}
View batchStrace.sh
#!/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 Apr 13, 2017
PHP memory recursive.
View gist:6bd30de6247bc5148986
<?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 Aug 29, 2015
PHP constructor clean up
View ConstructorCleanup.md

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 Aug 29, 2015
Contravariance for multiple interface
View contra
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 Feb 25, 2020
Strace all the PHP-FPM
View batchStrace
#!/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 Nov 14, 2014
FizzBuzz functional in PHP
View FizzBuzz
<?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 Jul 12, 2019
An example of how creating cycles in variables leads to
View Mem Test Output
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
View tempMediaQuery
CREATE TEMPORARY TABLE mediaSelected (
mediaId int,
itemId int
);
CREATE TEMPORARY TABLE mediaRejected (
mediaID int,
itemID int
);