Skip to content

Instantly share code, notes, and snippets.

View atheiman's full-sized avatar
😬

Austin Heiman atheiman

😬
View GitHub Profile
# Source: https://gist.github.com/vfarcic/70a14c8f15c7ffa533ea7feb75341545
######################
# Create The Cluster #
######################
# Make sure that you're using eksctl v0.1.5+.
# Follow the instructions from https://github.com/weaveworks/eksctl to intall eksctl.
@atheiman
atheiman / docker_run_nginx.sh
Last active February 11, 2024 01:28
Run nginx in docker container to serve PWD
# Run nginx docker container in background
docker run --name nginx --rm -d -p 8080:80 -v ${PWD}:/usr/share/nginx/html:ro nginx
# Load a file in curent directory
curl http://localhost:8080/index.html
# Stop the docker container (the container will be removed / cleaned up)
docker stop nginx
@atheiman
atheiman / include_recipe_spec.rb
Last active November 21, 2017 15:42
Stubbing `include_recipe` while ensuring correct recipes are included. complete example: https://github.com/atheiman/test-cookbook/pull/4
# test_cookbook/recipes/default.rb
include_recipe 'test_cookbook::included_recipe'
include_recipe 'apt'
# test_cookbook/spec/recipes/default_spec.rb
describe 'test_cookbook::default' do
before(:all) { @included_recipes = [] }
before do
@stubbed_recipes = %w[test_cookbook::included_recipe apt]
@atheiman
atheiman / echo_and_run.sh
Created November 3, 2017 20:12
echo_and_run simple shell function to print timestamp and command then execute the command (useful in build tools that dont log well)
$ echo_and_run() { echo "$(date +%T) $*"; $*; }
$ echo_and_run ls
# 15:09:35 ls
# Gemfile Gemfile.lock README.md spec
gfixup() {
set -x
git add --all
git commit --fixup=$(git log --oneline | head -1 | cut -d ' ' -f 1)
git rebase --interactive HEAD~2 --autosquash
set +x
local branch_name=$(git symbolic-ref -q HEAD)
branch_name=${branch_name##refs/heads/}
branch_name=${branch_name:-HEAD}
@atheiman
atheiman / java_properties.rb
Last active January 29, 2017 01:00
Ruby hash to Java properties file
class Hash
def to_java_properties_hash(prefix='')
properties = {}
self.each do |property, value|
new_prefix = prefix.empty? ? property.to_s : prefix + '.' + property.to_s
if value.respond_to? :to_java_properties_hash
properties.merge!(value.to_java_properties_hash(new_prefix))
else
properties[new_prefix] = value.to_s
@atheiman
atheiman / README.md
Last active July 17, 2016 18:00
Deep merge hashes. If both values are numeric they are summed. (Ruby)

Deep merge hashes. If both values are numeric they are summed.

$ ruby deep_sum_merge.rb
source:
layer_1: 10
deeper:
  layer_2: 20
  deeper:
    layer_3: 30
 deeper:

Messing around with knife exec

SEARCH='chef_environment:*dev*' knife exec partial_search.rb
# - name: node-a
#   hostname: node-a
#   fqdn: node-a.domain.net
#   ipaddress: 10.190.116.124
#   run_list:
# - role[base_os]
@atheiman
atheiman / chef_search_nodes.rb
Last active June 11, 2016 18:46
Chef Node Search API
require 'chef'
def config_chef
chef_config_env_var = 'CHEF_CONFIG'
if ENV[chef_config_env_var]
chef_config = ENV[chef_config_env_var]
else
default_chef_configs = ['~/.chef/knife.rb', '/etc/chef/client.rb']
default_chef_configs.each do |c|
if File.exists?(File.expand_path(c))
@atheiman
atheiman / logging.sh
Created June 6, 2016 21:12
simple shell script logging utility - logging.sh
#!/bin/bash
# Prints all arguments passed to the function with a timestamp prepended. `LOG_DATE_STRING` can be
# overridden by exporting the var. Prepend to the log using `LOG_LEVEL`.
log() {
[[ -z "$LOG_LEVEL" ]] && log_str='' || log_str="$LOG_LEVEL "
log_str="${log_str}$(date "+${LOG_DATE_STRING-%Y-%m-%d %H:%M:%S}") $@"
echo "$log_str"
}
info() { LOG_LEVEL='INFO' log "$@"; }