Skip to content

Instantly share code, notes, and snippets.

View sweatpantsninja's full-sized avatar

Josh Singer sweatpantsninja

View GitHub Profile
@sweatpantsninja
sweatpantsninja / gist:5400379
Last active December 16, 2015 07:39
How to remove :hover styles from your stylesheets without messing up complex, useful rules like: .ok, .not-ok:hover, .also-ok { ... } FYI relies on UnderscoreJS to user _.reject(), but that's clearly a writable function
if 'createTouch' of document
ignore = /:hover\b/
try
for stylesheet in document.styleSheets
idxsToDelete = []
# detect hover rules
for rule, idx in stylesheet.cssRules
if rule.type is CSSRule.STYLE_RULE and ignore.test(rule.selectorText)
newSelector = _.reject rule.selectorText.split(","), (s) -> ignore.test s
if newSelector.length > 0
defaults: &defaults
cloudant:
url: <%= ENV["CLOUDANT_URL"] %>
facebook_database: "facebook_data"
development:
<<: *defaults
cloudant:
url: "some url"
class OrderItem < ActiveRecord::Base
belongs_to :item
after_update :adjust_inventory, :if => lambda {
(size_changed? || item_id_changed?) && !returned?
}
def adjust_inventory
if item_id_changed?
Item.find(item_id_was).increment_stock(size_was)
item.reload.decrement_stock(size)
belongs_to :order
belongs_to :item
validate :item_has_not_been_sent?
def user
self.order.user
end
def item_has_not_been_sent?
@sweatpantsninja
sweatpantsninja / user.rb
Created August 21, 2012 22:33
stubbing sum vs reduce
class User < ActiveRecord::Base
has_many :orders
has_many :order_items, :through => :orders
def revenue
#TODO: stubbing OrderItem#price means I can't use .sum(:price). Is there a better way to use stubs AND sql?
#order_items.kept.sum(:price)
order_items.kept.reduce(0) { |sum, n| sum + n.price }
end
@sweatpantsninja
sweatpantsninja / gist:2963178
Created June 21, 2012 00:40
undefined local variable or method 'browser'
it "marks order_items as returned", :driver => :webkit do
browser.authenticate(username, password)
visit some_path
end