Skip to content

Instantly share code, notes, and snippets.

View imustardsoft's full-sized avatar

iMustardSoft imustardsoft

View GitHub Profile
"include_users": false,
// "include_users": ["user1", "user2"],
// Show the authors of Gists
"show_authors": false,
// Proxy server
// Format: "http://user:pass@proxy:port"
"https_proxy": "",
require 'benchmark'
result = Benchmark.measure do
"a"*1_000_000_000
end
puts result.total
@imustardsoft
imustardsoft / test1.rb
Created May 13, 2013 15:24
module initialize
require 'active_support/concern'
module MyModule
def my_val
@my_val ||= 2
end
# def self.included(receiver)
# receiver.instance_variable_set('@my_val',2)
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCpC35S4+PUe8vbraqdRX76aQq8+yhumx7EdQlAaoPUJwqrX/EaY1SBJnkIRczQEpMcxCl66kIpWV1PywIm8zlaVAbUj9xwdtlcG5dHn6hBtpzWBY1B3PbN4nsO/cXOx5yJn0beqo71iJDKq9YRkmQlLU6qEeEx0CRNR/ulx9XsFqOx8tB/5idkQ5algxDLhnyOojKsEWkByr7NOJLNaeeOjm5ivsIzsK7mL+WQPzeJhi2t6q0UWb44YdVTT7GJD9isRNpAnhC19rK6Oj3MD4EEppMGN6inMpZuPhpeIECsAv6Ahc86Jj7MTrGxBx7E1Kp3EiqU62Y3oskCP99QKnHT
@imustardsoft
imustardsoft / gist:1347759
Created November 8, 2011 13:38
Spree Order.rb
# total amount of the order, only considering item cost
def amount
self.line_items.map(&:amount).sum
end
@imustardsoft
imustardsoft / gist:1347754
Created November 8, 2011 13:37
price_bucket.rb
class Calculator::PriceBucket < Calculator
preference :minimal_amount, :decimal, :default => 0
preference :normal_amount, :decimal, :default => 0
preference :discount_amount, :decimal, :default => 0
def self.description
I18n.t("price_bucket")
end
# as object we always get line items, as calculable we have Coupon, ShippingMethod
@imustardsoft
imustardsoft / gist:1347631
Created November 8, 2011 12:28
spree error msg
ActionView::Template::Error (undefined method `to_d' for #<Order:0x82cce98>):
14: <h3>Shipping Method:</h3>
15: <div class="method">
16: <% i = 1 %>
17: <% @order.rate_hash.each do |shipping_method| %>
18: <%= radio_button(:order, :shipping_method_id, shipping_method[:id], :class => "radio#{i}", :id => shipping_method[:cost]) %>
19: <label><%= shipping_method[:name] %> <%= number_to_currency shipping_method[:cost] %></label>
20: <div class="clear"></div>
app/views/checkout/_payment.html.erb:17:in `_app_views_checkout__payment_html_erb___481978343_67756860_4938188'
app/views/checkout/edit.html.erb:7:in `_app_views_checkout_edit_html_erb__453920959_66761340_0'
@imustardsoft
imustardsoft / rails select tag
Created October 15, 2011 15:27
examples from rails doc
select_tag "people", options_from_collection_for_select(@people, "id", "name"), :prompt => "Select something"
# => <select id="people" name="people"><option value="">Select something</option><option value="1">David</option></select>
@imustardsoft
imustardsoft / form_tag_helper.rb
Created October 13, 2011 20:11
actionpack-3.0.6/lib/action_view/helpers/form_tag_helper.rb
def select_tag(name, option_tags = nil, options = {})
if Array === option_tags
ActiveSupport::Deprecation.warn 'Passing an array of option_tags to select_tag implicitly joins them without marking them as HTML-safe. Pass option_tags.join.html_safe instead.', caller
end
html_name = (options[:multiple] == true && !name.to_s.ends_with?("[]")) ? "#{name}[]" : name
if blank = options.delete(:include_blank)
if blank.kind_of?(String)
option_tags = "<option value=\"\">#{blank}</option>".html_safe + option_tags
else
set :gateway, 'YOUR GATEWAY SERVER IP'
role :web, "web1", "web2"