Skip to content

Instantly share code, notes, and snippets.

Avatar

Frank Kany kany

  • Rickman, TN
View GitHub Profile
@kany
kany / Reset MySQL 'root' user password
Last active Dec 11, 2015
Reset MySQL 'root' user password
View 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 Dec 11, 2015
Look for items hogging disk space on Mac
View 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 Mar 4, 2013
Find Foreign Keys - Mysql
View foreign_keys
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 Jun 22, 2020
Using GDB to inspect a running Ruby process
View Using GDB to inspect a running Ruby process.md

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.

View coffeescript_bundle_for_sublime.sh
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
View 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 Aug 29, 2015
Cronjob to reboot server 1 minute past every hour
View sudo_crontab_e
# 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 Mar 27, 2014
Using ActiveRecord outside of a Rails app
View active_record_outside_of_rails.rb
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 Nov 19, 2020
Clearing dead/stuck/zombie Resque workers redis resque delayed_job
View redis-resque-stuff.md

$ 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 Sep 24, 2014
Cropping images with paperclip
View cropper.rb
# 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