Skip to content

Instantly share code, notes, and snippets.

def flatten_structure(path, structure)
results = {}
if structure.is_a? Hash
structure.each_pair do |name, value|
new_path = "#{path}_#{name}".gsub(/\-|\//, '_')
results.merge! flatten_structure(new_path, value)
end
elsif structure.is_a? Array
structure.each_with_index do |value, index|
root@master:/etc/puppetlabs/facter/facts.d # cat foo.sh
#! /bin/sh
FACT=$(facter hostname)
echo "foo=${FACT}"
root@master:/etc/puppetlabs/facter/facts.d # chmod +x foo.sh
root@master:/etc/puppetlabs/facter/facts.d # facter ipaddress
<hangs and explodes>
[root@default ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:0f:d2:76 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
inet6 fe80::a00:27ff:fe0f:d276/64 scope link
@adrienthebo
adrienthebo / benchmark.rb
Created January 22, 2014 06:42
ruby command execution
#!/usr/bin/env ruby
require 'benchmark'
require 'childprocess'
require 'systemu'
argv = %w[git rev-parse HEAD^{commit}]
args = argv.join(" ")
COUNT = 100
describe 'a big laser' do
it 'can cut through steel'
it 'can shoot your eye out'
describe 'when being used for evil' do
it 'glows in an ominous fashion'
it 'crackles loudly when firing'
end
end
sed -i.bak -e \
":BEGIN
/\"[^\"']*[^\\]*\$[[:alnum:]_:].*\"/ \
s/\(\"[^\"]*\)\$\([[:alnum:]_:][[:alnum:]_:]*\)\([^\"]*\"\)/\1$\{\2\}\3/
t BEGIN" $manifest
sed -e '1i\
user literarybot foo foo literarybot' -e 'i2\
nick literarybot' -e '3i\
join #example' -ne '/^[[:space:]]*$/d' -ne 's/^/PRIVMSG #example :/p' < input.txt| while read line; do sleep 1; echo $line; done | nc irc.freenode.net 6667
@adrienthebo
adrienthebo / apod.rb
Created February 6, 2012 22:23
Download today's apod image
#!/usr/bin/env ruby
require 'fileutils'
require 'open-uri'
def get_links
image_urls = []
# Download latest page
puts "Downloading #{$apod_url}"
open($apod_url) do |stream|
@adrienthebo
adrienthebo / puppet_interp.sh
Created January 24, 2012 00:49
Attempts to add braces around quoted interpolated strings in puppet.
#!/bin/sh
#
# Attempts to add braces around quoted interpolated strings in puppet.
#
# Caveats
#
# This is a lot of sed and duct tape. It is not very smart. It's probably the
# most horrible regex I've ever written.
# I'm sorry.
@adrienthebo
adrienthebo / nTerm
Created September 20, 2011 16:51
Applescript shortcut for creating a new terminal window
tell application "iTerm"
set _term to (make new terminal)
tell _term
launch session "Default"
activate
end tell
end tell