Skip to content

Instantly share code, notes, and snippets.

module MyTweak
def execute(sql, name=nil)
if caller.detect {|x| x =~ /20171010151334/ } && sql !~ /SHOW TIME ZONE/
puts sql
else
super
end
end
end
class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
>> Book.select(:author, :isbn).first
Book Load (0.4ms) SELECT "books"."author", "books"."isbn" FROM "books" ORDER BY "books"."id" ASC LIMIT $1 [["LIMIT", 1]]
=> #<Book id: nil, isbn: "0787967076", author: "Steven B. Sample">
>> Book.select(:id, :author, :isbn).first
Book Load (0.3ms) SELECT "books"."id", "books"."author", "books"."isbn" FROM "books" ORDER BY "books"."id" ASC LIMIT $1 [["LIMIT", 1]]
=> #<Book id: 5, isbn: "0787967076", author: "Steven B. Sample">
>> Book.find(5).update(isbn: nil, author: "heyo")
Book Load (0.5ms) SELECT "books".* FROM "books" WHERE "books"."id" = $1 LIMIT $2 [["id", 5], ["LIMIT", 1]]
(0.1ms) BEGIN
SQL (19.7ms) UPDATE "books" SET "isbn" = $1, "author" = $2, "escaped_author" = $3, "updated_at" = $4 WHERE "books"."id" = $5 [["isbn", nil], ["author", "heyo"], ["escaped_author", "heyo"], ["updated_at", 2017-12-13 20:40:57 UTC], ["id", 5]]
$ cat db/migrate/* app/models/*.rb
class CreatePosts < ActiveRecord::Migration[5.1]
def change
create_table :posts do |t|
t.string :title
t.timestamps
end
end
end
@tcopeland
tcopeland / gist:a9cf33a9162c2289cd873650c9bed599
Last active February 16, 2018 18:23
Block twitter "notification" spam
twitter.com##.ActivityItem:-abp-contains(liked a Tweet from)
twitter.com##.ActivityItem:-abp-contains(liked a video from)
twitter.com##.ActivityItem:-abp-contains(liked a photo from)
twitter.com##.ActivityItem:-abp-contains(Retweeted a video from)
twitter.com##.ActivityItem:-abp-contains(Retweeted a photo from)
@tcopeland
tcopeland / gist:22040ee4230bc531c04718aefdc64abe
Created February 12, 2018 05:25
increment decrement matcher
module IncDec
# Mostly copied from RSpec::Matchers::BuiltIn
class ChangeDetails
attr_reader :actual_before, :actual_after
def initialize(matcher_name, receiver=nil, message=nil, &block)
if receiver && !message
raise(
ArgumentError,
"`#{matcher_name}` requires either an object and message " \