Skip to content

Instantly share code, notes, and snippets.

View afirth's full-sized avatar

Alastair Firth afirth

View GitHub Profile
@afirth
afirth / gist:7437947
Created November 12, 2013 20:20
nagios 5.0.2 vs 4.2.2
diff --git a/.gitignore b/.gitignore
index fc5b76d..abf8a27 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,23 @@
-.bundle
-.cache
-.kitchen
-bin
+_Store
diff --git a/.gitignore b/.gitignore
index fc5b76d..abf8a27 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,23 @@
-.bundle
-.cache
-.kitchen
-bin
+_Store
@afirth
afirth / gist:8809839
Created February 4, 2014 18:49
new secret loading
<< secret = Chef::EncryptedDataBagItem.load_secret(Chef::EncryptedDataBagItem::DEFAULT_SECRET_FILE)
<< splunk_auth_items = Chef::EncryptedDataBagItem.load("splunk_auth",node['splunk']['indexer_env'] + '_auth_creds',secret)
>> splunk_auth_items = Chef::EncryptedDataBagItem.load("splunk_auth",node['splunk']['indexer_env'] + '_auth_creds')
def self.load(data_bag, name, secret = nil) #secret can be nil
raw_hash = Chef::DataBagItem.load(data_bag, name) #load the raw (encrypted) hash into a databag object
secret = secret || self.load_secret #if secret is specified, this or operator short circuits and returns the first value. if secret is nil, calls self.load secret (L7)
self.new(raw_hash, secret) #return a new object
end
def self.load_secret(path=nil) #again, path can be nil
path ||= Chef::Config[:encrypted_data_bag_secret] # a shortcut to saying path = path || Chef::Config... as L3
if !path #nothing in path, means the default secret location wasn't set either. are you seeing this error?
raise ArgumentError, "No secret specified to load_secret and no secret found at #{Chef::Config.platform_specific_path('/etc/chef/encrypted_data_bag_secret')}"
@afirth
afirth / save your kerbals on OSX
Created March 12, 2014 02:32
saving KSP save files with git
#this is only for OSX
#first, install git. http://git-scm.com/download/mac
cd ~/Library/Application\ Support/Steam/SteamApps/common/Kerbal\ Space\ Program/saves && git init
(crontab -l ; echo '*/5 * * * * cd ~/Library/Application\ Support/Steam/SteamApps/common/Kerbal\ Space\ Program/saves && git add -A && git commit -m "`date`" &> /dev/null') | crontab -
#confirm your crontab is good to go
crontab -l
##to revert
@afirth
afirth / gist:9b10ce1efb3b3a123fe5
Last active August 29, 2015 14:01
NestedDict
class NestedDict(dict):
def __getitem__(self, key):
if key in self: return self.get(key)
return self.setdefault(key, NestedDict())
#http://ohuiginn.net/mt/2010/07/nested_dictionaries_in_python.html retrieved 2014-05-09
#Credit (and thanks) to Dan O'Huiginn
#could also use __missing__ instead:
class NestedDict(dict):
@afirth
afirth / cron_handlers.bash
Last active April 28, 2016 07:05
cron handlers
#!/bin/bash
#don't write shell scripts without this...
set -e
cd /my/folder
#Use timeout and flock to run your unreliable script every minute. Run only one copy. Useful against REST APIs for example
timeout --signal=KILL 59 flock -n /tmp/mycommand.lock -c 'mystupid long command'
#Log stdout and stderr. Discard stdout so cron doesn't mail you about it, but still receive mail for errors.
#!/bin/bash
# From http://spargelkohl.livejournal.com/65263.html - 2016-04-08 -AF]
# This script creates a RAMFS disk with an HFS+ partition on it and
# mounts it so it is visible in the OS X filesystem (including the
# Finder).
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/opt/local/bin:$HOME/bin
umask 077
@afirth
afirth / gist:aa53ade4f7d61ac5659b667bd4754bdb
Created April 8, 2016 01:21
find merge commit containing a commit, for each local git branch
for i in $( git branch | perl -pe's/\*/ /' ); do echo $i $( git find-merge e299e $i ); done
#uses find-merge alias
### Keybase proof
I hereby claim:
* I am afirth on github.
* I am alfirth (https://keybase.io/alfirth) on keybase.
* I have a public key whose fingerprint is 0BA0 4ED7 9617 5CEB 0EBD 37A5 8865 923E 7B56 94C7
To claim this, I am signing this object: