Skip to content

Instantly share code, notes, and snippets.

View kcdragon's full-sized avatar
🏠
Working from home

Mike Dalton kcdragon

🏠
Working from home
View GitHub Profile
@kcdragon
kcdragon / gist:48a0b3edcd617b01b7c8
Created August 27, 2014 21:22
Send HipChat message if there are multiple Sidekiq processes running
namespace :sidekiq do
detect_duplicate_processes = ->(context, server) do
number_of_sidekiq_processes = context.capture('ps aux | grep "[s]idekiq" | wc -l').to_i
rails_env = context.fetch(:rails_env, nil)
hipchat_token = context.fetch(:hipchat_token, nil)
hipchat_room_name = context.fetch(:hipchat_room_name, nil)
client = HipChat::Client.new(hipchat_token, {})
@kcdragon
kcdragon / gist:a18a1d9af003c261ea62
Created August 31, 2014 23:36
During deploy:rollback, only rollback migration if the migration was created in the previous deploy
before :deploy do
# Get the topmost migration that has been run:
run "rake db:current_version > migration_version.txt"
end
after 'deploy:rollback' do
run "rake db:migrate VERSION=`cat migration_version.txt`"
end
after :deploy do
### Keybase proof
I hereby claim:
* I am kcdragon on github.
* I am kcdragon (https://keybase.io/kcdragon) on keybase.
* I have a public key whose fingerprint is 9BCD 0964 3B79 0BAA 2A47 20DA C4E9 439D 4D72 483A
To claim this, I am signing this object:
@kcdragon
kcdragon / join_rails_logs.rb
Created August 29, 2016 14:33
Joins Rails logs produced on different app servers
require 'pp'
by_ip = {}
DATA.each_line do |line|
request = line.split(' ')
url = request[1] + ' ' + request[2].gsub('"', '')
ip = request[4]
by_ip[ip] ||= []
@kcdragon
kcdragon / Guardfile
Last active September 15, 2016 21:31
exercism.io Ruby downloader
guard :minitest, test_folders: '.' do
# with Minitest::Unit
watch(%r{^(.+)_test\.rb}) { |m| "./#{m[1]}_test.rb" }
watch(%r{^(.+)\.rb}) { |m| "./#{m[1]}_test.rb" }
end
@kcdragon
kcdragon / find-and-replace.sh
Created September 23, 2016 15:13
Find and Replace Directory Recursively (Mac OS X)
find src/ -type f -exec sed -i '' 's/foo/bar/g' {} +
@kcdragon
kcdragon / bundle.bat
Created December 3, 2016 00:58
Windows RailsInstaller bin/bundle.bat
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"C:\RailsInstaller\Ruby2.2.0\bin\ruby.exe" "C:/RailsInstaller/Ruby2.2.0/bin/bundle" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"C:\RailsInstaller\Ruby2.2.0\bin\ruby.exe" "%~dpn0" %*
@kcdragon
kcdragon / readme.txt
Last active February 10, 2017 15:58
Dev Computer Setup
http://recordit.co/
http://beyondgrep.com/install/
https://itunes.apple.com/us/app/status-clock/id552792489?mt=12
@kcdragon
kcdragon / did_you_mean.rb
Created September 13, 2016 01:14
ElasticSearch "Did You Mean...?" example
require 'elasticsearch'
require 'pp'
require 'hashie'
@count = 1
INDEX = 'didyoumean-test'
TYPE = 'test'
CLIENT = Elasticsearch::Client.new(log: true, send_get_body_as: 'POST')
@kcdragon
kcdragon / gist:d9a31224fddd3200fced2bfc02c213e2
Created July 28, 2017 18:10
Syscalls of a running process
# see https://8thlight.com/blog/colin-jones/2015/11/06/dtrace-even-better-than-strace-for-osx.html
sudo dtruss -p PID