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 / 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
# convert a number to letters only - no size limit
1.to_s.tr("0-9", "A-J")
@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
@ejhayes
ejhayes / 0_reuse_code.js
Created April 26, 2016 16:44
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ejhayes
ejhayes / boot2docker_network_timeout.sh
Created April 3, 2015 21:30
Fix Boot2Docker network timeout issue (sometimes VPN might affect this)
# fix boot2docker network timeouts (check boot2docker network interface name, mine is vboxnet0, yours may vary)
sudo route -nv add -net 192.168.59 -interface vboxnet0
#u: inet 192.168.59.0; u: link vboxnet0:a.0.27.0.0.0; RTM_ADD: Add Route: len 140, pid: 0, seq 1, errno 0, flags:<UP,STATIC>
#locks: inits:
#sockaddrs: <DST,GATEWAY,NETMASK>
# 192.168.59.0 vboxnet0:a.0.27.0.0.0 (0) 0 ffff ff
# add net 192.168.59: gateway vboxnet0
@ejhayes
ejhayes / logstash_setup_notes.md
Created February 18, 2015 20:03
Logstash setup notes

Logstash Master Setup on AWS

AWS Configurations

  • Port 80 should be open on the server so kibana can be accessed
  • Port 5000 should be open for incoming traffic via logstash-forwarder aka lumberjack (this is where logstash data comes in). I set this to 0.0.0.0/0 although you could restrict it to just the internal machines you are monitoring.

MASTER: ElasticSearch Install

@ejhayes
ejhayes / declarative_goal_specifications.rb
Created September 10, 2014 08:05
Goals are a high level concept--having a user set a goal should be validated in a way that keeps the model closed for modification, allows maximum flexibility in expressing goal validation per user, and keeps the data in the database rather than mixed throughout the application logic.
# - simplified
module Goals
class WeightLossGoal < Goal
db_identifier :weight_loss_goal
validates_goal_with do |user, amount_weight|
# user is the user we are validating against
if amount_weight >= user.weight
raise InvalidGoalError.new('cannot lose more than you weigh')
@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;