Skip to content

Instantly share code, notes, and snippets.

View dhrrgn's full-sized avatar
🦙

Dan Horrigan dhrrgn

🦙
  • OH, USA
  • 03:13 (UTC -04:00)
View GitHub Profile
<?php
use ArrayIterator;
/**
* Implements ArrayAccess, Countable, IteratorAggregate
*/
trait ParameterBagTrait
{
/**
@dhrrgn
dhrrgn / install.sh
Last active August 24, 2018 13:06
Setting up Selenium as a Service in OS X
#!/usr/bin/env bash
if [ ! -d /usr/lib/selenium/ ]; then
sudo mkdir /usr/lib/selenium/
fi
if [ ! -f /usr/lib/selenium/selenium-server-standalone-2.41.0.jar ]; then
sudo curl -o /usr/lib/selenium/selenium-server-standalone-2.41.0.jar http://selenium-release.storage.googleapis.com/2.41/selenium-server-standalone-2.41.0.jar
fi
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/vagrant/cachegrind"
xdebug.profiler_output_name = "callgrind.out.%t.%p"

Configure

xdebug.ini

xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_port=9000
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
@dhrrgn
dhrrgn / vagrant_plugins.sh
Created April 28, 2014 21:58
Install Vagrant Plugins, but only if they aren't already installed.
#!/bin/sh
function install_vagrant_plugin {
if [[ -z $(vagrant plugin list | grep "$1") ]]; then
vagrant plugin install $1
else
echo "Vagrant Plugin '$1' already installed...skipping."
fi
}
@dhrrgn
dhrrgn / benchmark.php
Last active August 29, 2015 14:00
Handy Benchmarking Function
<?php
function benchmark($name, $iterations, Closure $function)
{
echo "Starting Benchmark: {$name} (".number_format($iterations)." Iterations)\n";
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$function();
}
$elapsed = microtime(true) - $start;
@dhrrgn
dhrrgn / typecheck.php
Last active January 14, 2022 11:53
PHP Type Check Function
<?php
/**
* Checks the type of the given value against an array of valid types.
*
* If the value is a valid type, `true` is returned, if not, an
* InvalidArgumentException is thrown.
*
* // Throws: Invalid type: string, Expected type(s): array, ArrayAccess
* checktype('foo', ['array', 'ArrayAccess']);
<?php
/**
* Parses the given Entry into its constituent parts.
* @param mixed $entry The entry to parse
* @return array
* @throws \InvalidArgumentException
*/
protected function parseEntry($entry)
{
if (! is_array($entry) || $entry instanceof \ArrayAccess) {
@dhrrgn
dhrrgn / gist:11227014
Created April 23, 2014 18:23
Is there a better way to do this I am not thinking about? It feels "gross".
<?php
/**
* Parses the given Entry into its constituent parts.
* @param mixed $entry The entry to parse
* @return array
* @throws \InvalidArgumentException
*/
protected function parseEntry($entry)
{
if (is_array($entry) || $entry instanceof \ArrayAccess) {
@dhrrgn
dhrrgn / func.php
Last active August 29, 2015 13:58
Simple Redis Based Data Caching
<?php
class DataCache
{
protected $redis;
protected $ttl = 300; // Seconds
public function __construct($redis)
{
$this->redis = $redis;