Skip to content

Instantly share code, notes, and snippets.

View doyle's full-sized avatar

Christian Doyle doyle

View GitHub Profile
@doyle
doyle / docker_psql.sh
Created April 2, 2024 17:46
Dump and load a postgres database in a docker container
docker compose exec database pg_dump -U <user> -W <datbase> > database.sql
docker compose exec -T database psql -U <user> <database> < database.sql
@doyle
doyle / remote.js
Created March 6, 2023 14:36
Simulates the remote: true behavior in rails's links
$('.some-class').on('click', function(e){
e.preventDefault();
$.getScript($(this).attr('href'));
});
@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
@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 / 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 / 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
# 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 / 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
@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 / 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'}