Skip to content

Instantly share code, notes, and snippets.

Alastair Firth afirth

  • Berlin, Germany
Block or report user

Report or block afirth

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@afirth
afirth / gist:8809839
Created Feb 4, 2014
new secret loading
View gist:8809839
<< 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')
View gist:8829468
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 Mar 12, 2014
saving KSP save files with git
View save your kerbals on OSX
#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
View gist:9b10ce1efb3b3a123fe5
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 / gist:7437947
Created Nov 12, 2013
nagios 5.0.2 vs 4.2.2
View gist:7437947
diff --git a/.gitignore b/.gitignore
index fc5b76d..abf8a27 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,23 @@
-.bundle
-.cache
-.kitchen
-bin
+_Store
View gist:7566839
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:aa53ade4f7d61ac5659b667bd4754bdb
Created Apr 8, 2016
find merge commit containing a commit, for each local git branch
View gist:aa53ade4f7d61ac5659b667bd4754bdb
for i in $( git branch | perl -pe's/\*/ /' ); do echo $i $( git find-merge e299e $i ); done
#uses find-merge alias
View cron_handlers.bash
#!/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.
View gist:4ee5898a7f99ec90886624d91a831efe
### 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:
@afirth
afirth / git-matching-branches.pl
Last active Aug 2, 2018
looks for git branches whose head is the same ref as HEAD
View git-matching-branches.pl
#!/usr/bin/env perl
##### git-matching-branches #####
# aws codebuild checks out webhook payloads in a detached head state
# This script looks for branches whose head is the same ref as HEAD
# It prints the short branch names, newline separated, and should play nicely with xargs
# e.g. ./git-matching-branches | xargs -n1 -I '{}' cp tarball_version.tar.gz tarball_version-'{}'.tar.gz
#
# N.B. Branches whose name does not satisfy semver 2.0.0 item 9 will cause this script to exit abnormally
# and probably break the build [0-9A-Za-Z.-]
You can’t perform that action at this time.