Skip to content

Instantly share code, notes, and snippets.

View AllenJB's full-sized avatar

AllenJB AllenJB

  • UK
View GitHub Profile
@AllenJB
AllenJB / async-worker-cancel.php
Last active July 6, 2018 11:55
Bunny Async Worker w/ signal handler
<?php
use Bunny\Channel;
use Bunny\Async\Client;
use Bunny\Message;
use Bunny\Protocol\MethodBasicConsumeOkFrame;
use React\EventLoop\Factory;
require '../../vendor/autoload.php';
@AllenJB
AllenJB / gist:872553b5cb2086b0b8de9b0c50044ce5
Last active June 30, 2018 17:47
MySQL join same table on different fields
SELECT table1.employee_id_1, table1.employee_id_2, e1.first_name AS e1_first_name, e2.first_name AS e2_first_name
FROM table1
LEFT JOIN employee_tbl AS e1 ON table1.employee_id_1 = e1.employee_id
LEFT JOIN employee_tbl AS e2 ON table2.employee_id_2 = e2.employee_id
@AllenJB
AllenJB / _solution notes
Last active September 12, 2016 14:01
Fun with perl system()
https://bugzilla.yoctoproject.org/show_bug.cgi?id=9131
Run: LD_USE_LOAD_BIAS=0 perl -e 'print fork'
Temporarily disables prelink
Permanent solution: unprelink all the things!
See also:
https://bugs.gentoo.org/show_bug.cgi?id=579374
<FilesMatch "^php-fpm-ping|php-fpm-status$">
SetHandler "proxy:unix:/var/run/php-fpm/dcr_v4.sock|fcgi://localhost/"
deny from all
allow from localhost
</FilesMatch>
@AllenJB
AllenJB / chart.time-preparse.js
Created May 13, 2016 16:14
Chart.js: Pre-parse time values into moment objects
var preparsePlugin = Chart.PluginBase.extend({
beforeInit: function(chartCtrlr) {
var chart = chartCtrlr.chart;
var labels = chartCtrlr.data.labels;
var momentLabels = [];
labels.forEach(function(v) {
momentLabels.push(moment(v, moment.ISO_8601));
});
chartCtrlr.data.labels = momentLabels;
},
<?php
$type = error_reporting();
$levels = array (
'E_ERROR' => (($type & E_ERROR) == E_ERROR),
'E_WARNING' => (($type & E_WARNING) == E_WARNING),
'E_PARSE' => (($type & E_PARSE) == E_PARSE),
'E_NOTICE' => (($type & E_NOTICE) == E_NOTICE),
'E_CORE_ERROR' => (($type & E_CORE_ERROR) == E_CORE_ERROR),
'E_CORE_WARNING' => (($type & E_CORE_WARNING) == E_CORE_WARNING),
function bytes_to_human($bytes) {
$human = NULL;
if ($bytes < 1024) {
$human = number_format ($bytes, 0) .' bytes';
} else if ($bytes < 1024*1024) {
$human = number_format (($bytes / 1024), 1) . ' KB';
} else {
$human = number_format (($bytes / (1024*1024)), 1) . ' MB';
}
return $human;