View gist:269576
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
module MongoMapper | |
module Associations | |
class InArrayProxy < Collection | |
def set_parent(parent, options={}) | |
self.each do |k| | |
k.set_parent(parent) | |
if (!options.has_key?(:recursive) or options[:recursive] == true) and k.send( reflection.name ).size > 0 | |
k.send( reflection.name ).set_parent(k, options) | |
end | |
end |
View gist:277348
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
# in lib/asset_tag_helper_ext.rb | |
module ActionView | |
module Helpers | |
module AssetTagHelper | |
alias :orig_javascript_include_tag :javascript_include_tag | |
def javascript_include_tag(*sources) | |
options = sources.extract_options!.stringify_keys | |
rkey = '__scripts' | |
request[rkey] ||= [] |
View gist:302930
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 Car | |
include MongoMapper::Document | |
key :make, String | |
key :_type, String | |
end | |
class Honda < Car | |
key :honda_thing, String | |
end |
View foo_helper.rb
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
module FooHelper | |
include PartialMethods | |
end |
View watchr.rb
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
gem 'ruby-terminfo' | |
require 'terminfo' | |
def syst(cmd) | |
sym = '-' | |
dist = ((TermInfo.screen_size[1].to_f/2.to_f) - ((cmd.length.to_f + 2.to_f) / 2.to_f)).floor.to_i | |
mid = cmd | |
#color = "7;93" | |
color = "93" | |
newlines = 4 |
View upc.rb
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
# based on http://code.activestate.com/recipes/528911-barcodes-convert-upc-e-to-upc-a/ | |
class Upc | |
def self.convert_upc_e_to_upc_a(upce=nil) | |
return upce if upce.nil? or upce.length < 6 or upce.length > 8 # not a UPC-E | |
upce = case upce.length | |
when 6 | |
upce | |
when 7 | |
upce[0,6] |
View gist:491285
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
# manifest-entry-field => [ search-method, product-data-source, link-weight ] | |
# search-method: is the name of a function [fuzzy_search | manufacturer_search | exact] | |
# OR a lambda which receives ( the value of manifest-entry-field, the value of product-data-source ) | |
# and returns the matching product or nil | |
LINKING_COLUMNS = { | |
:title => [:fuzzy_search, | |
:title, | |
5], | |
#:description => [:fuzzy_search, :description, 10], |
View gist:492704
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
$('#bidding .editable').editable('/loads/<%=@load.id%>/manifest_entries/edit_in_place.ajax', { | |
'id': 'elementid', | |
'name': 'elementname', | |
'callback': function(result,settings){ | |
var field = $(this).attr('class').split(/ /).pop(); | |
if(field.match(/_cents$/)){ | |
$(this).html(result.manifest_entry.manifest_entry[field]/100).formatCurrency(); | |
} else { | |
$(this).html(result.manifest_entry.manifest_entry[field]); | |
} |
View bar_spec.rb
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 'spec_helper' | |
describe "Bar" do | |
it "should not bar" do | |
lambda { | |
"foo".bar | |
}.should raise_exception | |
end | |
end |
View test_http_clients.rb
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 'httparty' | |
require 'curb' | |
require 'net/http' | |
require 'benchmark' | |
include Benchmark | |
RUNS = 1000 | |
url = 'http://localhost:4567/' |
OlderNewer