Skip to content

Instantly share code, notes, and snippets.

@jrab89
jrab89 / my_class_spec.rb
Last active January 4, 2016 01:29
Is there a way I can write the second context more concisely by referencing the first?
describe MyClass
let(:instance){MyClass.new}
describe '#myMethod' do
let(:input){ [1] }
context 'with input' do
it 'does stuff' do
instance.should_receive(:foo)
instance.should_receive(:bar)
@jrab89
jrab89 / example.rb
Last active August 29, 2015 13:58
Change values in a hash without modifying the origional?
arr = [{num: 1}, {num: 2}, {num: 3}]
arr.map{|h| h[:num] += 1; h} # [{:num=>2}, {:num=>3}, {:num=>4}]
arr # [{:num=>2}, {:num=>3}, {:num=>4}]
# is there a better way to do this?
arr = [{num: 1}, {num: 2}, {num: 3}]
arr.map{|h| clone = h.clone; clone[:num] += 1; clone} # [{:num=>2}, {:num=>3}, {:num=>4}]
arr # [{num: 1}, {num: 2}, {num: 3}]
@jrab89
jrab89 / gist:aa78383d9e1cd0bc623e
Created August 8, 2014 20:31
How do you get this to not output 'foo' ?
class Foo
attr_reader :number
def initialize
puts 'foo'
@number = 1
end
end
describe Foo do
@jrab89
jrab89 / Rakefile
Created August 21, 2014 16:00
Is there a cleaner way to do this?
desc "Run cucumber tests on each feature file in parallel, exits 0 if they all succeed and 1 otherwise"
task :test, :exclude do |task, args|
features_to_exclude = args.has_key?(:exclude) ? args[:exclude].split(' ') : []
# actually task here
end
@jrab89
jrab89 / find_largest_files.sh
Created February 1, 2017 18:42
find the largest files on disk (prints number of kilobytes for each file)
sudo find / -type f -printf '%k %p\n' | sort -h | tail
@jrab89
jrab89 / download_and_search_cloudtrail.sh
Last active February 2, 2017 20:21
Digging through CloudTrail logs
aws s3 sync \
s3://your-cloudtrail/AWSLogs/222222bbbbbb/CloudTrail/us-east-1/YYYY/MM/DD/ \
~/s3/your-cloudtrail/AWSLogs/222222bbbbbb/CloudTrail/us-east-1/YYYY/MM/DD/
ag -lz \
c11db0a3-7309-4089-9750-3835fb522e9d \
~/s3/your-cloudtrail/AWSLogs/222222bbbbbb/CloudTrail/us-east-1/YYYY/MM/DD/