Skip to content

Instantly share code, notes, and snippets.

@stevendanna
stevendanna / danger_add_users_to_global_admins_group
Created January 24, 2015 01:15
danger_add_users_to_global_admins_group
#!/opt/opscode/embedded/bin/ruby
require 'sequel'
require 'json'
require 'uri'
require 'net/http'
orgname = ARGV[0]
if orgname.nil?
STDERR.puts "usage: danger_add_users_to_global_admins_group ORGNAME"
@stevendanna
stevendanna / pre-commit
Last active March 21, 2016 15:42
Pre-commit hook to help prevent key leakage
#!/bin/bash
#
# Warn about possible cloud access keys before committing
#
exec </dev/tty
unset possible_keys
possible_keys=$(git diff --cached | egrep '^[+\-].*(AKIA|AWS_ACCESS|AWS_SECRET|OS_PASSWORD|OS_USERNAME)')
if [[ -n "$possible_keys" ]];then
echo -e "WARNING: Diff contains possible access keys:\n"
echo "${possible_keys}"
my_test "foo" do
action :create
end
save-last-command() {
last_command=$(fc -nl 0)
command_name="$1"
read -r -d '' new_fun <<EOF
${command_name}() {
$last_command
}
EOF
eval "$new_fun"
}
@stevendanna
stevendanna / sigign
Created September 22, 2014 11:18
sigign(1): start process with signal disposition set to SIG_IGN
#!/usr/bin/env ruby
#
# sigign: exec a command with signals ignored
#
# Usage: sigign SIGNAL[,SIGNAL..] COMMAND
#
# sigign sets the disposition of the specified signals to SIG_IGN
# before exec'ing the specified command.
ignored_signals = ARGV.shift.split(",")
sdanna@thrace ~/tmp/foo > irb
irb(main):001:0> Dir.pwd
=> "/Users/sdanna/tmp/foo"
irb(main):002:0>
[1]+ Stopped irb
146 sdanna@thrace ~/tmp/foo > cd
sdanna@thrace ~ > rm -rf ~/tmp/foo
sdanna@thrace ~ > fg
irb (wd: ~/tmp/foo)
Dir.pwd
@stevendanna
stevendanna / gist:cc34968e4626eb11bf72
Last active August 29, 2015 14:04
verify monkey-patch
class Chef::Resource::File
def verify(&block)
if block_given?
@verify_block=block
else
@verify_block
end
end
end
#!/usr/bin/env bash
#
# Authors:: Chef Support Team <[email protected]>
#
modified_within_last_x_minutes=180
tail_lines=10000
type='EC'
if [[ -n $1 ]];
then
whyrun_safe_ruby_block "log" do
block do
Chef::Log.info "foo"
end
end
ruby_block "dump run_state" do
block do
require 'pp'
pp node.run_state
end
end