Skip to content

Instantly share code, notes, and snippets.

View doyle's full-sized avatar

Christian Doyle doyle

View GitHub Profile
@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
rsync -avzhet ssh user@server:remote_path .
@doyle
doyle / commits.sh
Last active January 31, 2019 18:45
Creates a pretty printed summary of all commits for a year
git log --author="Christian Doyle" --after="2015-1-1" --before="2015-12-31" --date=short --no-merges --pretty=format:'%h was %an, %ad, message: %s' | tail -r > commits.txt
@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 / 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 / rm_bomb.sh
Created May 17, 2018 18:55
Shows how to remove BOM from a file using vim
vim -c "set nobomb" -c wq! foo.txt
@doyle
doyle / import_mysql.sh
Last active February 8, 2018 01:28
Example of how to import a tar file into a mysql database
gzcat foo.gz | mysql -u root database
@doyle
doyle / encoding_fix.rb
Created January 2, 2018 14:25
Converts a csv file in the windows utf 8 encoding to utf 8
require 'csv'
file = ARGV[0]
rows = CSV.read(file, :encoding => 'windows-1251:utf-8')
out = CSV.open("#{file.split('.')[0]}_fixed.csv", 'wb')
rows.each{|row| out << row}
out.close
@doyle
doyle / group.rb
Created December 30, 2017 21:49
Given a sorted array of numbers will group the numbers so long as they are within a given delta of each other. That is to say will group numbers that are close but once a gap is found a new group is started.
times = [1,2,4,5,10,12,14,20,22,23,24]
@group = 0
@delta = 3
def group(times)
times.group_by do |item|
index = times.index(item)
if index <= times.size - 2
a = index + 1
@doyle
doyle / pairs.r
Created April 25, 2017 13:54
Example using ggpairs
library(GGally)
csv = read.csv(file="path", head=TRUE,sep=",")
ggpairs(csv, columns = c(3, 7))