Skip to content

Instantly share code, notes, and snippets.

View dhrrgn's full-sized avatar
🦙

Dan Horrigan dhrrgn

🦙
  • OH, USA
  • 02:55 (UTC -04:00)
View GitHub Profile
<?hh
class Container implements ArrayAccess<string, string>
{
protected Map<string, string> $mappings;
public function __construct()
{
$this->mappings = new Map();
}
@dhrrgn
dhrrgn / heartbleed.yml
Created April 8, 2014 14:29
Heartbleed Ansible Playbook
---
- hosts: all
sudo: true
tasks:
- apt: update_cache=yes
- apt: pkg=libssl1.0.0 state=latest
- apt: pkg=openssl state=latest
- service: name=apache2 state=restarted
ignore_errors: yes
- service: name=nginx state=restarted
@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;
@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) {
<?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 / 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 / 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
}
xdebug.profiler_enable = 1
xdebug.profiler_output_dir = "/vagrant/cachegrind"
xdebug.profiler_output_name = "callgrind.out.%t.%p"
<?php
use ArrayIterator;
/**
* Implements ArrayAccess, Countable, IteratorAggregate
*/
trait ParameterBagTrait
{
/**
<?php
function require_in_context($__path, array $__context)
{
extract($__context, EXTR_SKIP);
unset($__context);
ob_start();
require $__path;