Skip to content

Instantly share code, notes, and snippets.

@pollingj
pollingj / base.rb
Created September 26, 2012 08:18
Splitting packages in Spree Active Shipping
def packages(order)
split_packages = Array.new
number_of_packages = 1
multiplier = Spree::ActiveShipping::Config[:unit_multiplier]
default_weight = Spree::ActiveShipping::Config[:default_weight]
weight = order.line_items.inject(0) do |weight, line_item|
item_weight = line_item.variant.weight.present? ? line_item.variant.weight : default_weight
weight + (line_item.quantity * item_weight * multiplier)
@pollingj
pollingj / find_cell_link.xpath
Created August 20, 2012 14:28
XPath to find link within a specific table row containing specific text in another cell
@pollingj
pollingj / loop.coffee
Created July 20, 2011 16:47
Odd for loop
for num in [1..starValue]
ENV["WATCHR"] = "1"
system 'clear'
def growl(message)
growlnotify = `which growlnotify`.chomp
title = "Watchr Test Results"
puts message
image = message.match(/\s0\s(errors|failures)/) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
system %(#{growlnotify} #{options} &)
@pollingj
pollingj / sass_config.rb
Created December 21, 2010 16:03
How to get SASS to load in SASS (SCSS) files from plugins (or other folders)
Dir[Rails.root.join("vendor/game_types/**/app/stylesheets")].each do |sass_folder|
Sass::Plugin.add_template_location(
sass_folder,
sass_folder + '/../../public/stylesheets'
)
end
InheritedResources::BaseHelpers.module_eval do
def resource
get_resource_ivar || end_of_association_chain.respond_to?('by_slug') ? set_resource_ivar(end_of_association_chain.by_slug(params[:id])) : set_resource_ivar(end_of_association_chain.find(params[:id]))
end
def collection
get_collection_ivar || set_collection_ivar(end_of_association_chain.all)
end
end
def filter_url_helper(filter_key, filter_value)
product_group_query = params[:product_group_query] != nil ? Array.new(params[:product_group_query]) : nil
if product_group_query == nil
return "/t/#{params[:id].join('/')}/s/#{filter_key}/#{filter_value}"
end
if product_group_query.index(filter_key) == nil
return "/t/#{params[:id].join('/')}/s/#{product_group_query.join('/')}/#{filter_key}/#{filter_value}"
else
product_group_query[product_group_query.index(filter_key)+1] = filter_value
<httpHandlers>
<add verb="*" path="BuiltJS" type="Castle.MonoRail.Framework.MonoRailHttpHandlerFactory, Castle.MonoRail.Framework"/>
</httpHandlers>