Skip to content

Instantly share code, notes, and snippets.

View kany's full-sized avatar

Frank Kany kany

  • Rickman, TN
View GitHub Profile
@kany
kany / Reset MySQL 'root' user password
Last active December 11, 2015 20:58
Reset MySQL 'root' user password
This method only works if currently logged in as root. Sometimes when working with older ruby 'mysql' gems, after the 'mysql' gem is installed, the previous password doesn't work.
1) Already logged into Mysql
2) gem jacked up your mysql password
3) mysql > use mysql;
4) mysql > UPDATE user SET Password=PASSWORD('') WHERE User='root'; FLUSH PRIVILEGES;
@kany
kany / Look for items hogging disk space on Mac
Last active December 11, 2015 20:59
Look for items hogging disk space on Mac
Change to root directory
1) cd /
See size of each file/folder in directory with sorting
2) sudo du -sh * | sort -gr
If /SomeFolder is over 1gb
3) cd SomeFolder && sudo du -sh *
@kany
kany / foreign_keys
Created March 4, 2013 18:51
Find Foreign Keys - Mysql
select
concat(table_name, '.', column_name) as 'foreign key',
concat(referenced_table_name, '.', referenced_column_name) as 'references'
from
information_schema.key_column_usage
where
referenced_table_name is not null AND
referenced_table_name = 'org_units';
@kany
kany / Using GDB to inspect a running Ruby process.md
Last active June 22, 2020 12:37
Using GDB to inspect a running Ruby process

http://robots.thoughtbot.com/post/47202759358/using-gdb-to-inspect-a-running-ruby-process

That’s not a great thing to have to say, is it? However, I bet you’ve said it before and may not have immediately know why.

With liberal use of puts and maybe pry, you can figure out what a problem might be next time you run it, but sometimes you need to figure out what that problem is right now.

As it turns out, and I know this is a shocker, Ruby processes are just regular processes. They can be debugged with gdb.

Having recently had the need to find out why a job of mine was running particularly slowly, I found out about this lovely tool the hard way: frantic googling. I found some very useful functions for gdb in a blog post by Rasmus on Ruby callstacks.

mkdir -p ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/CoffeeScript
cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/CoffeeScript
curl -O https://raw.github.com/jashkenas/coffee-script-tmbundle/master/Syntaxes/CoffeeScript.tmLanguage
curl -O https://raw.github.com/jashkenas/coffee-script-tmbundle/master/Preferences/CoffeeScript.tmPreferences
@kany
kany / resque.rake
Created September 11, 2013 18:14 — forked from denmarkin/resque.rake
# see http://stackoverflow.com/questions/5880962/how-to-destroy-jobs-enqueued-by-resque-workers - old version
# see https://github.com/defunkt/resque/issues/49
# see http://redis.io/commands - new commands
namespace :resque do
desc "Clear pending tasks"
task :clear => :environment do
queues = Resque.queues
queues.each do |queue_name|
puts "Clearing #{queue_name}..."
@kany
kany / sudo_crontab_e
Last active August 29, 2015 13:56
Cronjob to reboot server 1 minute past every hour
# To Edit Root Cron Jobs
#sudo crontab -e
# Reboot 1 minute past every hour, log errors if any generate
01 * * * * /sbin/reboot > /home/calvin2/miner_cron_job_log.txt 2>&1
# Reboot every 30 minutes, log errors if any generate
*/30 * * * * /sbin/reboot > /home/calvin2/miner_cron_job_log.txt 2>&1
@kany
kany / active_record_outside_of_rails.rb
Created March 27, 2014 15:11
Using ActiveRecord outside of a Rails app
require 'active_record'
require 'mysql2'
# Database Connection
ActiveRecord::Base.establish_connection(
adapter: 'mysql2', # or 'postgresql' or 'sqlite3'
host: 'localhost',
database: 'chc_user_auth_direct_login',
username: 'root',
password: ''
@kany
kany / redis-resque-stuff.md
Last active June 28, 2022 05:33
Clearing dead/stuck/zombie Resque workers redis resque delayed_job

$ rails c

Loading development environment (Rails 3.1.3)
1.9.3p0 :002 > Resque::Worker.working.each{|w| w.done_working}

$ redis-cli

# Removes data from your connection's CURRENT database.
@kany
kany / cropper.rb
Created September 24, 2014 01:59
Cropping images with paperclip
# lib/paperclip_processors/cropper.rb
module Paperclip
class Cropper < Thumbnail
def transformation_command
if crop_command
puts "CROP: #{crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')}"
crop_command + super.join(' ').sub(/ -crop \S+/, '').split(' ')
else
super
end