This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// if we have | |
function do() { | |
// thing that takes 100ms - 2s depending on browser | |
} | |
// Instead of: | |
setInterval(do, 500) // pray it doesn't lock the browser | |
// Do this: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Merging Scopes | |
# ============== | |
# The goal is to join two tables to get all the records where a scope on both | |
# side of the join is used. I used to do this with a `where()` in which I | |
# added some sql on the joined table. But, I wanted to use the existing scopes | |
# from the joining table. Turns out there's a `merge` method on a scope where | |
# you can merge with another scope without having to chain! | |
class Car < ActiveRecord::Base | |
has_and_belongs_to_many :people |
NewerOlder