Skip to content

Instantly share code, notes, and snippets.

View doyle's full-sized avatar

Christian Doyle doyle

View GitHub Profile
@doyle
doyle / read_headers.rb
Created July 5, 2018 20:34
How to read the headers of a CSV file without reading the whole file
header_string = File.open(file_path, 'r:bom|utf-8', &:readline)
headers = CSV.parse(header_string).first
@doyle
doyle / ruby_prof.rb
Last active May 17, 2019 19:29
ruby-prof example
require 'ruby-prof'
RubyProf.start
# code...
result = RubyProf.stop
printer = RubyProf::CallStackPrinter.new(result)
printer.print(File.open('call_stack.html', 'w'))
@doyle
doyle / sidekiq_queue.rb
Created December 10, 2018 20:32
Finding sidekiq jobs
# Find jobs by class
Sidekiq::Queue.new('queue').select{|j| j.display_class == 'Foo'}
# Find jobs by argument (foo is the name of the argument and bar is the value in this case)
Sidekiq::Queue.new('queue').select{|j| j['args'][0]['foo'] == 'bar'}
@doyle
doyle / strftime_example.rb
Last active June 12, 2019 19:35
Shows common ways of formatting dates as strings
# 2019-10-14 14:32:55 -0400
Time.now.strftime('%Y-%m-%d %H:%M:%S %z')
# 2019-10-14 14:35:18.969 -0400
Time.now.strftime('%Y-%m-%d %H:%M:%S.%L %z')
@doyle
doyle / gh-push.sh
Created May 7, 2019 18:16
Pushes the current branch to git hub and opens the PR in your browser
#!/bin/sh
# pushes the current branch to git hub and opens your browser to the
# pull request page for the current branch
OUTPUT=`(git push origin HEAD) 2>&1`
URL=`echo $OUTPUT | sed -e 's/.*visiting: remote: \(https:\/\/github.com[A-Za-z0-9%\/_-]*\).*/\1/'`
echo opening $URL
open $URL
# decrypts messages in the Futurama AL2 language: https://theinfosphere.org/Alien_languages
encrypted_message = %w(19 0 4 21 25 17 4 18 10 4 6 13 6 13 21 8 14 14 6 25 21 9).map(&:to_i)
decrypted_message = ''
encrypted_message.each_with_index do |value, index|
if index > 0
value = value - encrypted_message[index - 1]
value = value >= 0 ? value : 26 + value
end
@doyle
doyle / s3_sync.sh
Last active September 20, 2022 15:01
Example of copying files from s3 to local
aws s3 cp s3://path/to/bucket . --recursive
@doyle
doyle / rename_files_recursive.sh
Last active March 3, 2022 20:47
Recursively rename many files in a directory
find . -name *_foo.rb -exec rename 's/(.*)_foo.rb/\1_bar.rb/g' *.rb {} \;
@doyle
doyle / install_xcode_command_line_tools.sh
Created June 9, 2022 13:53
Always run this after updating OSX
xcode-select --install
@doyle
doyle / gh_stats.rb
Last active December 1, 2022 16:50
Pulls a list of an author's contributions to a GitHub organization
require 'octokit'
def gh_stats(org, author)
repos = repos(org, 'private')
repos += repos(org, 'public')
total_additions = 0
total_deletions = 0
total_commits = 0