This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # frozen_string_literal: true | |
| source "https://rubygems.org" | |
| gem "rack" | |
| gem "pry" | |
| gem "rackup" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'sequel' | |
| require 'logger' | |
| DB = Sequel.sqlite(loggers: [Logger.new(STDOUT)]) | |
| DB.create_table :authors do | |
| primary_key :id | |
| String :name | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Example of how to convert CSV data on read, in this case parsing | |
| # some JSON in a CSV. | |
| # | |
| require 'csv' | |
| require 'json' | |
| csv = <<EOT | |
| id,json_stuff | |
| 1,"{""foo"":""bar""}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| echo -n "3pm Christmas Day in LA in local timezone: " | |
| date --date 'TZ="America/Los_Angeles" 2016-12-25T15:00' | |
| echo -n "3pm Christmas Day in LA in London: " | |
| TZ="Europe/London" date --date 'TZ="America/Los_Angeles" 2016-12-25T15:00' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Example integration spec for a Rake task in Rails | |
| # | |
| # cat <<EOT > lib/tasks/myapp.rake | |
| # namespace :myapp do | |
| # task :mytask => :environment do | |
| # puts "Hello" | |
| # end | |
| # end | |
| # EOT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| usage() { | |
| cat <<EOT | |
| Usage: PAPERTRAIL_API_TOKEN=abc123 $0 directory | |
| Save all papertrail archives to outdir. Existing files will not be | |
| overwritten if they have the correct filesize. | |
| PAPERTRAIL_API_TOKEN can be found under the 'Me -> Profile' in Papertrail, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Animal | |
| @@noise = nil | |
| def speak | |
| @@noise | |
| end | |
| end | |
| class Dog < Animal | |
| @@noise = 'Woof' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'delegate' | |
| class CaseInsensitiveHashWriter < SimpleDelegator | |
| def []=(key, value) | |
| return __getobj__[key] unless key.respond_to?(:downcase) | |
| matched_key = keys.detect do |k| | |
| k.respond_to?(:downcase) && k.downcase == key.downcase | |
| end | |
| if matched_key | |
| __getobj__[matched_key] = value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Log an exception with the backtrace cleaned as per the 'Application Trace' | |
| # in the development mode browser exception view. | |
| logger.error( | |
| "some_tag: exception = %s: %s" % [ | |
| exception.inspect, | |
| Rails.backtrace_cleaner.clean(exception.backtrace) | |
| ] | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def value_of_first_matching_key_in_hash(hash, array_of_keys) | |
| end | |
| describe do | |
| it 'searches a hash for an array of keys and returns the value of the first found' do | |
| keys = [:a, :b, :c] | |
| hash = {:c => 3, :b => 2, :a => 1} | |
| expect(value_of_first_matching_key_in_hash(hash, keys)).to eql 1 |
NewerOlder