Skip to content

Instantly share code, notes, and snippets.

View ryanuber's full-sized avatar

Ryan Uber ryanuber

View GitHub Profile
@ryanuber
ryanuber / README.md
Last active August 29, 2015 13:57
Example Serf router-style handler

Serf handler router

When using @hashicorp's excellent Serf orchestration tool, you typically configure a handler for each type of event you expect to encounter (more about events and handlers here). To change handler configuration, one must update the Serf configuration and reload the agent with a SIGHUP or a restart.

Thanks to the flexibility and open-endedness Serf offers for configuring and executing handlers, we can achieve similar functionality by configuring only a single "router" handler, which we will never

@ryanuber
ryanuber / gist:9014174
Created February 15, 2014 03:31
Vagrant re-import box from files on local system

If you find that vagrant box list somehow does not contain a box you previously had, you can sometimes add the box back if you still have the sources for it in ~/.vagrant.d/boxes.

$ cd ~/.vagrant.d/boxes/precise64/0/virtualbox/
$ tar czf ~/precise64.box .
$ vagrant box add precise64 ~/precise64.box 
Downloading box from URL: file:/Users/ryanuber/precise64.box
Extracting box...te: 417M/s, Estimated time remaining: --:--:--)
Successfully added box 'precise64' with provider 'virtualbox'!
@ryanuber
ryanuber / monthPlus29.php
Created February 5, 2014 05:53
Print a formatted date exactly 29 days from the 1st of every month
<?php
$result = array();
foreach (range(1, 12) as $m) {
array_push($result, date('Md', mktime(0,0,0,1,date('z', mktime(0,0,0,$m,1))+29)));
}
print implode(',', $result);
@ryanuber
ryanuber / ruby 1.8.7
Last active January 2, 2016 22:09
Ruby 1.8.7 > 2.x SystemStackError
irb(main):001:0> def method_missing(*args) args.join(' ') end
=> nil
irb(main):002:0> hello world
=> "hello world"
@ryanuber
ryanuber / app.php
Created September 28, 2013 03:35
PHP: "use" statement resolving both class and namespace in one statement. What if you have a namespace called `\fruit\apple`, and also a class called `\fruit\apple` ? If you do `use fruit\apple`, what does it "use" ? The answer is, both. It will now allow you to refer to both `apple` and `apple\...` as you please.
<?php
namespace fruit {
class apple {
public static $x = 'this is the apple class';
}
}
namespace fruit\apple {
class seed {
public static $x = 'this is the seed class';
}
@ryanuber
ryanuber / depth.py
Created July 26, 2013 23:44
Determine depth of data structure in Python. This recursive function will return the depth as an integer of the deepest-nested object.
def depth(data):
d = 1
if type(data) is dict:
for item in data.keys():
if type(data[item]) is dict or type(data[item]) is list:
d += depth(data[item])
elif type(data) is list:
for item in data:
if type(item) is dict or type(item) is list:
d += depth(item)