Skip to content

Instantly share code, notes, and snippets.

View atheiman's full-sized avatar
😬

Austin Heiman atheiman

😬
View GitHub Profile
a = b
a.b = B
c.e = true
1234=1234
@atheiman
atheiman / erb_example.rb
Created April 17, 2017 19:48
simple ERB example
~ $ cat tmp/erb_example.rb
#!/usr/bin/env ruby
require 'erb'
template = "number: <%= @number %>\nstring: <%= @string %>"
@number = 3.4
@string = 'blue'
puts ERB.new(template).result
# given a list of hashes:
foo = [
{ a: whatever, b: whatever, c: whatever },
{ a: whatever, b: whatever, c: whatever },
# ...
]
bar = { b: whatever, y: whatever, z: whatever }
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
^\w+(\.\w+)*@(\w+\.)*\w+\.\w+$
# 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
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 / 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