Skip to content

Instantly share code, notes, and snippets.

View kjlape's full-sized avatar
🤝
nice to meet you

Kaleb Lape kjlape

🤝
nice to meet you
View GitHub Profile
def doit
yield
end
def do_retry
doit do
begin
puts 'doing'
yield
puts 'done'
@kjlape
kjlape / expand_ebs_instance.sh
Created July 7, 2016 21:31
Expand the size of an EBS volume attached to a linux EC2 instance.
# Setup
# 1) create a new volume based on a snapshot of your old volume
# 2) attach the new volume to your ec2 instance
# look at attached volumes
fdisk -l
# resize the volume
resize2fs /dev/xvdf
@kjlape
kjlape / bad_model_finder.rb
Created May 25, 2016 17:18
If for some crazy reason you need to find all ActiveRecord models with off-server hosted, carrierwave uploaded files, this is just the thing for you.
bad_models = FlakyImage.select do |image|
uri = URI.parse image.file.url
Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
response = http.head uri.path
response.code != "200"
end
end
bad_models.count
@kjlape
kjlape / inderpolation-finder.rb
Last active May 17, 2016 00:45
Finds your inderpolations... 🤦
finder = /"#\{([^}]+)\}"/
'"#{derp}"'.gsub finder, '\1' #=> derp
# EL FIN
@kjlape
kjlape / mergablerga.sh
Last active July 12, 2016 14:29
Useful directory merging commands.
# METHOD 1:
# use this when there's a reasonable number of subdirectories
mv dir1/* dir2/* dir3/* ... DESTINATION
# Then if there are conflicts...
cp -Rn dir2/* DESTINATION
cp -Rn dir3/* DESTINATION
#METHOD 2:
# use this when there are too many subdirectories for mv to handle as args at once
@kjlape
kjlape / .bash_aliases
Last active January 20, 2016 20:19
Useful bash shtuff...
alias docker-rails-console="docker-compose run --service-ports web rails console"
alias docker-run-web="docker-compose run --service-ports web"
alias heroku-rails-console="heroku run rails console --app"
findDockerInstanceExposedPort() {
docker-compose ps $1 | grep $1 | sed -E 's/.*:([0-9]+)->.*/\1/g'
}
lesscsv() {
OPTIND=1
@kjlape
kjlape / lesscsv.sh
Last active December 15, 2015 22:54
WIP - Performant CSV viewer for terminal.
lesscsv() {
OPTIND=1
delimiter=","
theFile=""
while getopts "d:f:" opt; do
case $opt in
"d") delimiter=$OPTARG;;
"f") theFile=$OPTARG;;
esac
@kjlape
kjlape / runsql.rake
Last active October 22, 2015 19:10
Rails rake task to run arbitrary sql scripts in repo.
namespace :dbrun do
namespace :functions do
app_root = Rails.application.config.root
sql_functions_path = File.join(app_root, "db", "functions")
sql_functions_glob_path = File.join(sql_functions_path, "*.sql")
ActiveRecord::Base.configurations = YAML.load(File.read(File.join(app_root, 'config', 'database.yml')))
ActiveRecord::Base.establish_connection (ENV['ENV'] || 'development').to_sym
Dir.glob(sql_functions_glob_path) do |file|
@kjlape
kjlape / docker-compose-ps-port.sh
Created October 7, 2015 16:33
Find the port number of a docker compose instance.
docker-compose ps $1 | grep $1 | sed -E 's/.*:([0-9]+)->.*/\1/g'
@kjlape
kjlape / variadic.js
Last active August 29, 2015 14:20
Variadic js...
Function.prototype.variadic = function () {
var self = this
return function () {
return self.apply(self,
self.length == 1 ?
[arguments] :