Skip to content

Instantly share code, notes, and snippets.

View atheiman's full-sized avatar
😬

Austin Heiman atheiman

😬
View GitHub Profile
require 'rspec'
def remove_whitespace(string)
lines = string.lines
# remove leading and trailing blank lines
lines.shift while lines.first.strip.empty?
lines.pop while lines.last.strip.empty?
# remove trailing whitespace from lines
lines.map(&:rstrip).join("\n")
end
# https://gist.github.com/atheiman/2b359b3da6a80fc0a6c8d54c78abfc5b
#
# Write a function (with helper functions if needed) called to Excel that takes
# an excel column value (A,B,C,D…AA,AB,AC,… AAA..) and returns a corresponding
# integer value (A=1,B=2,… AA=27..).
module ExcelAlpha
ALPHA_HASH = Hash[('A'..'Z').to_a.zip (1..26).to_a].freeze
DECIMAL_HASH = ALPHA_HASH.invert.freeze
@atheiman
atheiman / README
Created September 27, 2017 14:27
CentOS 7 CA cert issues
[root@dokken ~]# /usr/local/ruby/jruby-9.1.13.0/bin/ruby -rnet/http -e "Net::HTTP.get(URI('https://www.google.com/'))"
OpenSSL::SSL::SSLError: certificate verify failed
connect_nonblock at org/jruby/ext/openssl/SSLSocket.java:228
connect at /usr/local/ruby/jruby-9.1.13.0/lib/ruby/stdlib/net/http.rb:938
do_start at /usr/local/ruby/jruby-9.1.13.0/lib/ruby/stdlib/net/http.rb:868
start at /usr/local/ruby/jruby-9.1.13.0/lib/ruby/stdlib/net/http.rb:857
start at /usr/local/ruby/jruby-9.1.13.0/lib/ruby/stdlib/net/http.rb:585
get_response at /usr/local/ruby/jruby-9.1.13.0/lib/ruby/stdlib/net/http.rb:480
get at /usr/local/ruby/jruby-9.1.13.0/lib/ruby/stdlib/net/http.rb:457
<main> at -e:1
ruby_build $ KITCHEN_LOCAL_YAML=.kitchen.dokken.yml bundle exec kitchen test default-centos-6
-----> Starting Kitchen (v1.17.0)
-----> Cleaning up any prior instances of <default-centos-6>
-----> Destroying <default-centos-6>...
Deleting kitchen sandbox at /Users/austinheiman/.dokken/kitchen_sandbox/8db929f748-default-centos-6
Deleting verifier sandbox at /Users/austinheiman/.dokken/verifier_sandbox/8db929f748-default-centos-6
Finished destroying <default-centos-6> (0m0.03s).
-----> Testing <default-centos-6>
-----> Creating <default-centos-6>...
Creating kitchen sandbox at /Users/austinheiman/.dokken/kitchen_sandbox/8db929f748-default-centos-6
@atheiman
atheiman / home_dir_spec.rb
Created November 17, 2017 22:19
Stubbing methods interacting with /etc/passwd
describe 'cookbook::recipe' do
cached(:chef_run) do
ChefSpec::ServerRunner.new.converge(described_recipe)
end
it 'creates home directories' do
%w[/home/testuser1 /home/testuser2].each do |d|
expect(chef_run).to create_directory(d)
end
end
@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 / with_retries.rb
Last active November 28, 2017 14:32
Execute a block with retries for exceptions
def doubles?
a = rand(1..6)
b = rand(1..6)
puts "#{a} and #{b}"
raise 'Not doubles!' unless a == b
true
end
def with_retries(retries: 2, sleep: 1)
attempt = 1

Keybase proof

I hereby claim:

  • I am atheiman on github.
  • I am austinheiman (https://keybase.io/austinheiman) on keybase.
  • I have a public key ASC2ZiWvCqeAOkMAORKrAfBc6FUubaaHaXHScebkbcth0Ao

To claim this, I am signing this object:

# chef-nodes is useful to share a nodes attributes with other nodes. if you want to share _converged_ node
# data (more than just ip and hostname from chef-nodes) then you can use test-kitchen >= 1.20.0 which adds
# support for downloading files from nodes after converge via .kitchen.yml:
#
# provisioner:
# nodes_path: test/fixtures/nodes
# downloads:
# /tmp/kitchen/nodes: test/fixtures/
#
# this will download node data after converge and drop it into test/fixtures/nodes/node-a.json, node-b.json, etc