Skip to content

Instantly share code, notes, and snippets.

@carlzulauf
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlzulauf/3abbde552db7fe535935 to your computer and use it in GitHub Desktop.
Save carlzulauf/3abbde552db7fe535935 to your computer and use it in GitHub Desktop.
if defined?(ActiveRecord::Base)
class ActiveRecord::Base
def self.sample
s = scoped
c = s.count
s.offset(rand(c)).first
end
end
def __clear_lhm(sure = false)
conn = ActiveRecord::Base.connection
tables = conn.execute("SHOW TABLES").to_a.map(&:first)
tables.grep(/^lhm/).each do |table|
if sure
puts "Dropping #{table}"
conn.execute("DROP TABLE #{table}")
else
puts "Would drop #{table}"
end
end
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment