Skip to content

Instantly share code, notes, and snippets.

remote_file "/tmp/remote_file.zip" do
source "http://www.example.com/remote_file"
checksum "sha256checksum"
notifies :run, "bash[unzip_and_own]", :immediately
end
bash "unzip_and_own" do
action :nothing
user "root"
cwd "/destination_path"
@philk
philk / i_have_a_problem.rb
Created March 1, 2013 04:05
I don't know if Ruby will let me do this and I'm pretty sure it shouldn't but I'm really enjoying this crazy idea.
cloud_monitoring_alarm "memory_usage alarm" do
check_label "memory"
criteria do
warn_if(
percentage("used", "total"),
">",
100,
"Used percentage too high"
)
warn_if metric("thing"), "<", 1
@philk
philk / seach.rb
Created August 23, 2012 18:22
Sorted each lol
class Array
def seach
self.sort.each do |a|
yield a
end
end
end
[2,1,3].seach do |i|
puts i
@philk
philk / pybool.rb
Created July 12, 2012 17:33
Convert any Ruby object into a Python string (for ERB templates in Chef)
class Object
def to_py_bool
(!!self).to_s.capitalize
end
end
@philk
philk / betterstring.rb
Created May 24, 2012 18:37
Monkeypatch string
class String
def is_valid_ip?
self.match(/\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/) ? true : false
end
end
@philk
philk / test_conn.js
Created May 4, 2012 17:47
Test connection via node
var net = require('net');
function test_connection(addr, port, cb) {
var client = net.createConnection(port, addr);
var start = (new Date()).getTime();
client.on('connect', function () {
var end = (new Date()).getTime();
client.end();
client.destroy();
cb(null, (end - start));
@philk
philk / gist:2040817
Created March 15, 2012 00:53
buildbot error
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 213, in addCallbacks
self._runCallbacks()
File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 371, in _runCallbacks
self.result = callback(self.result, *args, **kw)
File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 280, in callback
self._startRunCallbacks(result)
File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line 354, in _startRunCallbacks
self._runCallbacks()
--- <exception caught here> ---
@philk
philk / gpr.sh
Created January 10, 2012 21:28
git pull request
function git_current_branch() {
git symbolic-ref HEAD 2> /dev/null | sed -e 's/refs\/heads\///'
}
function git_current_origin() {
git config --get remote.origin.url | sed -e 's/^.*\://' | sed -e 's/\.git.*//'
}
alias gpr='open "https://github.com/$(git_current_origin)/pull/new/$(git_current_branch)"'
@philk
philk / gist:1238525
Created September 23, 2011 21:48
jconsole function
function jc {
jmx_host=$1
jmx_port=${2:-8080}
proxy_host=${3:-$jmx_host}
proxy_port=${4:-8123}
echo "connecting jconsole to $jmx_host:$jmx_port via SOCKS proxy $proxy_host using local port $proxy_port"
ssh -f -ND $proxy_port $proxy_host
jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=${proxy_port} service:jmx:rmi:///jndi/rmi://${jmx_host}:${jmx_port}/jmxrmi
kill $(ps ax | grep "[s]sh -f -ND $proxy_port" | awk '{print $1}')
@philk
philk / knife.rb
Created June 22, 2011 16:45
Chef Template
# Put this below the other knife.rb stuff
knife[:data_bag_secret_file] = '/Users/phil.kates/.chef/encrypted_data_bag_secret'