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:
# 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. |
# 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 |
# 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] |
$ 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} |
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 |
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]
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)) |
#!/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 "$@"; } |