Skip to content

Instantly share code, notes, and snippets.

@djburdick
djburdick / rails_db_migrate_multiple_databases.rb
Created May 22, 2013 17:16
make schema_migrations work over multiple databases. #rails
module ActiveRecord
class Migrator
class << self
def get_all_versions
table = Arel::Table.new(schema_migrations_table_name)
# must not be Base.establish_connection b/c that'll drop the mysql2
# adapter connection and blow up rake db:schema:dump
SchemaMigration.establish_connection(ActiveRecord::Base.configurations['cluster'][Rails.env])
cluster_migrations = SchemaMigration.connection.select_values(table.project(table['version'])).map{ |v| v.to_i }
@djburdick
djburdick / view_header_info
Created May 16, 2013 17:28
easy way to view header info. #linux
curl -i http://example.com
@djburdick
djburdick / rails_mysql_insertion
Last active December 17, 2015 01:10
direct faster rails insertion (outside of active record models). #mysql #rails
ar = User.connection.execute("select id, uid from users order by id asc")
ar.each do |user|
user[1] = 0 if user[1].nil?
UserGlobal.connection.execute("insert into user_globals (id, cluster_id, uid, created_at, updated_at) values (#{user[0]}, 1, #{user[1]}, NOW(),NOW());")
end
@djburdick
djburdick / mysql_drop_specific_tables
Last active December 16, 2015 20:10
mysql drop tables that begin with. #mysql
mysql -u user -p[password] -Nse "show tables like 'tmp%'" database -h host.colo | while read table; do mysql -u user -p[password] -e "drop table $table" database -h host.colo; done
@djburdick
djburdick / mysql_select_by_probability
Created April 22, 2013 20:09
mysql select table by probability. #mysql
SELECT * FROM `table` ORDER BY RAND()*probability desc LIMIT 1;
probability is a number from 0 to 1
@djburdick
djburdick / tcp_dump_port
Created April 2, 2013 20:55
show all tcp activity on a port. #linux
sudo tcpdump -i eth0 'port 8125'
@djburdick
djburdick / merge_conflicts_take_your_changes
Created March 20, 2013 17:58
merge conflict; take your changes for a specific file. #git
git checkout HEAD -- db/schema.rb
@djburdick
djburdick / multiple_local_rails_servers
Created March 19, 2013 20:43
running multiple local rails servers. #rails
terminal 1: bundle exec rails s
terminal 2: bundle exec rails s -p 3001 -P tmp/pids/server2.pid
@djburdick
djburdick / add_subdomains_to_localhost
Created March 12, 2013 18:03
adding subdomains to localhost. #linux #mac
vim /etc/hosts
127.0.0.1 c1.localhost
@djburdick
djburdick / find_and_replace_all
Created March 11, 2013 19:45
find and replace all instances in a project. #linux #vim
ack -l 'pattern' | xargs perl -pi -E 's/pattern/replacement/g'