Skip to content

Instantly share code, notes, and snippets.

View doyle's full-sized avatar

Christian Doyle doyle

View GitHub Profile
@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 / port_sniff.rb
Created August 30, 2016 17:41
Searches all of the ip addresses in a range and prints out a message if a machine is found
(0..255).each do |i|
ip = "192.168.1.#{i}"
result = `ping -c 1 -W 5 #{ip}`
if result.match(/1 packets received/)
puts "something on #{ip}"
end
end
@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"
@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 / 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 / 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 / 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
rsync -avzhet ssh user@server:remote_path .
@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 / 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