Skip to content

Instantly share code, notes, and snippets.

View haileys's full-sized avatar

Hailey Somerville haileys

View GitHub Profile
if defined? ActiveRecord
def explain(query)
query = query.to_sql if query.respond_to? :to_sql
ActiveRecord::Base.connection
.execute("EXPLAIN ANALYZE #{query}")
.to_a
.each { |hash| puts hash["QUERY PLAN"] }
nil
#!/usr/bin/env ruby
# Changes file extension, e.g:
# $ cext some/file/deeply/nested/file.png .jpg
# $ ls some/file/deeply/nested
# file.jpg
nametokens = ARGV.first.split '.'
newext = ARGV[1].split '.'
File.rename ARGV.first, (nametokens[-newext.length, newext.length] + newext).join '.'