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:
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 "$@"; } |
#!/bin/sh | |
# WARNING: REQUIRES /bin/sh | |
# | |
# - must run on /bin/sh on solaris 9 | |
# - must run on /bin/sh on AIX 6.x | |
# | |
# Copyright:: Copyright (c) 2010-2015 Chef Software, Inc. | |
# License:: Apache License, Version 2.0 | |
# | |
# Licensed under the Apache License, Version 2.0 (the "License"); |
#!/bin/bash | |
# | |
# Assume the given role, and print out a set of environment variables | |
# for use with aws cli. | |
# | |
# To use: | |
# | |
# $ eval $(./iam-assume-role.sh) | |
# |
MIT License
Copyright (c) [year] [fullname]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
require 'chefspec' | |
module SpecHelper | |
def global_stubs | |
# Don't worry about external cookbook dependencies | |
Chef::Cookbook::Metadata.any_instance.stub(:depends) | |
# Test each recipe in isolation, regardless of includes | |
@included_recipes = [] | |
Chef::RunContext.any_instance.stub(:loaded_recipe?).and_return(false) |
app.filter('bytes', function() { | |
return function(bytes, precision) { | |
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-'; | |
if (typeof precision === 'undefined') precision = 1; | |
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'], | |
number = Math.floor(Math.log(bytes) / Math.log(1024)); | |
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number]; | |
} | |
}); |