Skip to content

Instantly share code, notes, and snippets.

Dave Hulbert dave1010

Block or report user

Report or block dave1010

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
dave1010 / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
dave1010 / bench1.php
Last active Aug 29, 2015
PHP object instantiation benchmark
View bench1.php
class Foo {
public function __construct($i)
$this->bar = $i;
$start = microtime(true);
$count = 1000000;
dave1010 / repo.php
Created Nov 18, 2014
cqs repo with creation on fetch
View repo.php
class Repo
public function fetchByName($name)
$entity = $this->em->fetch(['name' => $name]);
if (!$entity) {
$entity = new NullEntity($name);
$this->dispatcher->dispatch(new EntityRetrievedEvent($entity));
return $entity;
dave1010 / interpreter.php
Last active Aug 29, 2015
PHP Interpreter
View interpreter.php
$stack = [];
$labels = [];
$pointer = 0;
$instructions = [];
* @param $stack
* @param $instructions

Improved retry function for igorw/retry, as proposed by @acleon.


  • Appears to use fewer opcodes (This is the 1st time I've used VLD, I could be wrong)
  • Doesn't use goto
dave1010 / array-map-break-yield.php
Last active Sep 19, 2017
array_map in php, with break
View array-map-break-yield.php
class BreakOut extends Exception {}
function mapGenerator(array $arr, $callback)
$ret = [];
foreach ($arr as $val) {
try {
yield $callback($val);
dave1010 / variadics.php
Created Apr 29, 2014
Type hinting in PHP variadics
View variadics.php
class Bar{}
$bars = [new Bar, new Bar, new Bar];
$ints = [1, 2, 3];
// without variadics
// lots of manual type checking
function oldFoo($bars)
dave1010 / monolog-setup.php
Created Apr 22, 2014
Monolog setup for FingersCrossedHandler, RotatingFileHandler, NativeMailerHandler & BufferHandler
View monolog-setup.php
$logger = new Logger('my logger');
// log DEBUG messages to file when there's at least a NOTICE
$fileHandler = new RotatingFileHandler(ABSPATH . '../logs/log.log', 0, Logger::DEBUG, true, 0777);
$fingersCrossedHandler = new FingersCrossedHandler($fileHandler, Logger::NOTICE, 1000);
dave1010 / monolog-setup.php
Created Apr 22, 2014
Make sure a Monolog logger can log
View monolog-setup.php
$handler = new RotatingFileHandler(ABSPATH . '../logs/log.log', 0, Logger::DEBUG, true, 0777);
try {
$record = array(
'message' => (string) "Write test",
'context' => null,
'level' => Logger::DEBUG,
'level_name' => 'DEBUG',
# Quick and dirty demonstration of CVE-2014-0160 by Jared Stafford (
# The author disclaims copyright to this source code.
import sys
import struct
import socket
import time
import select
You can’t perform that action at this time.