Skip to content

Instantly share code, notes, and snippets.

@ejhayes
ejhayes / vault_export_to_env.sh
Created May 4, 2023 20:09
Merge vault secrets and export them to environment variables
export $(echo PATH1 PATH2 PATH3 | xargs -n 1 -I {} vault read -format=json {} | jq -rs 'map(.data.data) | add | keys[] as $k | "\($k)=\(.[$k])"')
@ejhayes
ejhayes / find_nearest_equivalent_commit.sh
Last active May 3, 2023 01:12
Find nearest equivalent git commit that does not differ from the current commit
#!/bin/sh
# Get the HEAD commit hash
HEAD=$(git rev-parse HEAD)
# Generate a list of all commit hashes in the repository
git rev-list --no-merges --all | while read COMMIT; do
# Compare the commit to the HEAD
if [ -z "$(git diff --name-only $COMMIT $HEAD)" ]; then
# If there are no differences, exit the loop and return the commit hash
@ejhayes
ejhayes / run_changescript.sql
Created December 7, 2012 23:38
SQL Server catch compile time and runtime errors
/*
Our runner script
*/
CREATE PROCEDURE inner_sp AS
EXEC dbo.usp_RecordChangeScript '2007-01-2012 (ERIC TEST).sql', '0.1.11'
EXEC dbo.usp_RecordChangeScript '2004-01-2012 (ERIC TEST).sql', '0.1.11'
-- CODE GOES HERE
GO
@ejhayes
ejhayes / cached-aws-iam-authenticator
Created December 12, 2019 18:19
Cached STS token for Kubectl on AWS EKS
#!/usr/bin/env bash
CACHE_FILE=${HOME}/.kube/cache/aws-${AWS_PROFILE}.cache
MAXTIME=800
if [ -f $CACHE_FILE ]; then
TS_DB=$(stat -t "%s" ${CACHE_FILE} | cut -d' ' -f10 | tr -d '"')
AGE=$(( `date +%s` - $TS_DB ))
if [[ $AGE -le $MAXTIME ]]; then
cat ${CACHE_FILE}
else
aws "$@" | tee $CACHE_FILE
@ejhayes
ejhayes / README.md
Last active November 29, 2019 14:09
Prose theme for zsh
@ejhayes
ejhayes / dummyPackage.pp
Created July 3, 2012 18:35
Install a debian package locally using puppet
class dummyPackage {
package { 'yourpackagename':
ensure => installed|absent,
provider => dpkg,
source => '/path/to/file.deb',
}
}
class { 'dummyPackage': }
@ejhayes
ejhayes / request_image_byte_range.js
Last active March 14, 2018 10:15
Request partial byte range of png using 206 partial content request
// PNG file structure
// taken from: http://www.w3.org/TR/REC-png-961001#Structure
var xhr = new XMLHttpRequest;
xhr.onreadystatechange = function () {
if (xhr.readyState != 4) {
return;
}
debugger;
# convert a number to letters only - no size limit
1.to_s.tr("0-9", "A-J")
@ejhayes
ejhayes / README.md
Created June 6, 2012 01:12
Debugging Hubot Scripts using Node Inspector

About

Use node-inspector to debug hubot!

sudo npm install -g node-inspector

Run Hubot in Debug Mode

coffee --nodejs --debug $(which hubot)

@ejhayes
ejhayes / fix_ntp_time.sh
Created May 12, 2016 22:50
NTP fix and update clock
#!/bin/bash
sudo apt-get install ntp -y
sudo service ntp stop
sudo ntpdate -s time.nist.gov
sudo service ntp start