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
class Time | |
def is_after?(timestamp) | |
self.to_i - self.at_beginning_of_day.to_i > timestamp | |
end | |
def is_after_430_pm? | |
# 4:30 == 16:30 | |
# 16*3600 (sec/hr) | |
#+30*60 (sec/min) | |
#=59400 |
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
SELECT u.id, u.first_name, u.last_name, u.email, so.shipto_postal_code, so.placed_at | |
FROM users u LEFT JOIN sales_orders so | |
ON so.user_id = u.id | |
AND so.state != 'pending' | |
WHERE u.contact_me = 1 | |
ORDER BY u.id, so.placed_at DESC | |
---------------------------------- | |
SELECT u.id, u.first_name, u.last_name, u.email, so1.shipto_postal_code, so1.placed_at |
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
def check_for_bid_items | |
return if user.bids.empty? | |
@bids_and_items = user.bids.inject({}) do |hsh, bid| | |
items_for_bid = hsh[bid] || [] | |
items_for_bid += line_items.select{|li| li.product.bids.include?(bid) } | |
hsh.update(bid => items_for_bid) unless items_for_bid.empty? | |
end | |
end |
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
return if user.bids.empty? | |
@bids_and_items = user.bids.inject({}) do |hsh, bid| | |
items_for_bid = hsh[bid] || [] | |
items_for_bid += line_items.select{|li| li.product.bids.include?(bid) } | |
hsh = hsh.update(bid => items_for_bid) unless items_for_bid.empty? | |
hsh | |
end | |
# send an email with items from each bid.. |
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
# hack searchlogic to work with date_select / datetime_select in search form | |
module Searchlogic | |
class Search | |
# Accepts a hash of conditions. | |
def conditions=(values) | |
values.each do |condition, value| | |
if condition =~ /(.*)\(1i\)$/ | |
date_scope_name = $1 | |
date_parts = (1..6).to_a.map do |idx| | |
values.delete("#{ date_scope_name }(#{ idx }i)") |
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
class Discount | |
# name | |
# code | |
# effective_at | |
# ends_at | |
# type # (DollarOff, PercentOff, FreeShipping..) | |
# promotion? | |
# customer_exclusive? | |
# amount | |
# minimum_total_requirement |
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
def add_discount(promo_code) | |
discount = Discount.find_by_code(promo_code) | |
if discount && discount.applicable?(self) | |
if discount.customer_exclusive? | |
discount_assignment = discount.assignments.find_by_user_id(user.id) | |
discount_assignment.update_attributes(:sales_order_id => self.id) | |
else | |
discount_assignments.create(:discount => discount) | |
end | |
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
# USAGE: Hash.from_xml:(YOUR_XML_STRING) | |
require 'nokogiri' | |
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297 | |
class Hash | |
class << self | |
def from_xml(xml_io) | |
begin | |
result = Nokogiri::XML(xml_io) | |
return { result.root.name.to_sym => xml_node_to_hash(result.root)} |
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
pry(main):4> blame_for(Pry.instance_method(:repl)).display | |
John Mair def repl(target=TOPLEVEL_BINDING) | |
John Mair target = Pry.binding_for(target) | |
John Mair target_self = target.eval('self') | |
John Mair | |
John Mair repl_prologue(target) | |
Mon ouïe | |
John Mair # cannot rely on nesting.level as | |
John Mair # nesting.level changes with new sessions | |
John Mair nesting_level = nesting.size |
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
require "rubygems" | |
require "appscript" | |
class AppResizer | |
include Appscript | |
# Full screen bounds for all modes. | |
HOME_FULL_SCREEN = [0, 0, 2560, 1440] | |
LAPTOP_FULL_SCREEN = [0, 0, 1440, 900] |
OlderNewer