Skip to content

Instantly share code, notes, and snippets.

View rthbound's full-sized avatar

Ryan T. Hosford rthbound

View GitHub Profile
@rthbound
rthbound / sitemap.rb
Created December 2, 2011 23:14
Glitch
Customer.find(:all, :include => :posts).each do |customer|
if !customer.posts.blank?
add customer_posts_path(customer.id)
customer.posts.each do |post|
x = post.id
#add customer_posts_path(:customer_id => customer.id, :id => post.id)
add customer_posts_path(customer.id, x)
end
end
end
@rthbound
rthbound / gist:1425307
Created December 2, 2011 23:19
Glitch result
<url>
<loc>
http://www.autopartstomorrow.com/customers/5/posts.1
</loc>
<lastmod>2011-12-02T23:10:26+00:00</lastmod>
<changefreq>weekly</changefreq>
<priority>0.5</priority>
</url>
@rthbound
rthbound / stuff.js
Created December 6, 2011 19:21
stuff to do
$(document).ready(function() {
var options = {
target: '#div_effect',
type: 'post',
};
$("#post_comment_button").click(function() {
$('#new-comment-form').submit(function() {
// please don't redirect me
// instead inject my new comment into the list
def special_signup
@newsletter_member = NewsletterMember.new(params[:newsletter_member])
@newsletter_member.active = true
@newsletter_member.signup_date = Time.now
@category = PnCategory.find(params[:pn_category_id])
if NewsletterMember.find_by_email(params[:newsletter_member][:email])
session[:newsletter] = true
flash[:newsletter_modal] = 'You have already signed up for our newsletter.'
elsif @newsletter_member.save
session[:newsletter] = true
STATUSES = Order.all.collect{|x| x.status}.uniq
# Currently : STATUSES = ["SHIPPED", "PROCESSING", "RECEIVED", "INCOMPLETE", "VOIDED", "REFUNDED", "FRAUDULENT", "ON HOLD"]
validates_inclusion_of :status, :in => STATUSES
STATUSES.map{|x| x.downcase.gsub(" ", "_")}.each_with_index { |s,index| named_scope s, :conditions => { :status => STATUSES[index] } }
named_scope :cart_products_not_empty,
:joins => :cart_products,
:group => 'cart_products.cart_id',
:having => "count(cart_products.cart_id) >= 1"
named_scope :cart_components_not_empty,
:joins => :cart_components,
:group => 'cart_components.cart_id',
:having => "count(cart_components.cart_id) >= 1"
# If the cart already has this product in it,
if existing_cart_product = cart.cart_products.find_by_part_number_id(@cart_product.part_number_id)
# And if the current quantity in cart exceeds or equals the available quantity
if existing_cart_product.quantity >= available_quantity
# Set the quantity in cart to the available quantity, and add 0 of the requested quantity to the cart.
existing_cart_product.update_attributes(:quantity => available_quantity)
@addl_msg << "Quantity has been depleted for this item. There are #{existing_cart_product.quantity} units in your cart. "
@cart_product.quantity = 0
end
end
@rthbound
rthbound / work.rb
Created January 12, 2012 17:19
Hot products
#To load in-stock parts ordered within last 30 or 7 days:
#For PartNumbers I have:
named_scope :with_id, lambda {|id| { :conditions => { :id => id } } }
named_scope :stocked, :conditions => ['quantity > ?', 0]
#For Orders I have:
named_scope :within_days, lambda { |number| {:conditions => ["created_at > ? AND transaction_id IS NOT NULL", Time.now - number.days] } }
PartNumber.with_id(Order.within_days(7).map{|o| o.order_products.map{|op| op.part_number_id}}.flatten.uniq).stocked.count
def hot_parts
# initialize some empties
hps = []
hp = false
# get 6 random parts
while(hps.length < 6 )
# Set flag variable to ensure entry into inner loop first time around
first = true
# Validate uniqueness and non nillishness
#greetings {
width: 100%;
height: auto;
color: #999999;
background: #4f4f4f;
background: -moz-linear-gradient(top, #4f4f4f 0%, #666666 43%, #7f7f7f 100%);
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#4f4f4f), color-stop(43%,#666666), color-stop(100%,#7f7f7f));
background: -webkit-linear-gradient(top, #4f4f4f 0%,#666666 43%,#7f7f7f 100%);
background: -o-linear-gradient(top, #4f4f4f 0%,#666666 43%,#7f7f7f 100%);
background: -ms-linear-gradient(top, #4f4f4f 0%,#666666 43%,#7f7f7f 100%);