Skip to content

Instantly share code, notes, and snippets.

View doyle's full-sized avatar

Christian Doyle doyle

View GitHub Profile
@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 / 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
rsync -avzhet ssh user@server:remote_path .
@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))
@doyle
doyle / find_replace.sh
Created October 21, 2016 19:56
Find and replaces all instances in a directory
find . -type f -exec sed -i '' -e 's/foo/bar/g' {} \;
@doyle
doyle / gist:92b0b34cd4804d237ed9661e20e33e5d
Created October 17, 2016 19:51
Use curl to upload a file to a S3 pre-signed url
curl -X PUT -T test_s3.txt -L "https://your-bucket.s3.amazonaws.com/url-stuff"