Skip to content

Instantly share code, notes, and snippets.

View afirth's full-sized avatar

Alastair Firth afirth

View GitHub Profile
@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.
@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 / 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
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 / 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')
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: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