This file contains hidden or 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
| # No Boom, it was creating the handle first... cause app Boom | |
| # This does however, as you say, "Boom" | |
| Factory.define :product do |p| | |
| p.product_handles do |p| | |
| [Factory.build(:product_handle)] | |
| end | |
| end | |
| # Only issue here is that the product has knowledge of the handle... knowledge it need not have. |
This file contains hidden or 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
| # Example Rails Usage: | |
| # config.middleware.use Rack::LessCss, "/stylesheets", File.join(RAILS_ROOT, "public", "stylesheets") | |
| # | |
| # public/stylesheets/foo.less is now used to render /stylesheets/foo.css | |
| # | |
| require 'less' | |
| module Rack | |
| class LessCss | |
| File = ::File | |
| def initialize(app, css_path, css_dir) |
This file contains hidden or 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 BaseColor | |
| attr_reader :r,:g,:b,:a | |
| def alpha(v) | |
| BaseColor.new(r,g,b,v) | |
| end | |
| def initialize(r, g, b, a = 1.0) | |
| @r, @g, @b, @a = normalize(r), normalize(g), normalize(b), normalize(a, 1.0) | |
| end |
This file contains hidden or 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 "json" | |
| require "httpclient" | |
| # Usage: | |
| # reevoo_hq = LongLat.from_postcode("SE1 0RF") | |
| # reevoo_hq.long # => -0.10276 | |
| # reevoo_hq.lat # => 51.500991 | |
| class LongLat | |
| PostcodeLookupError = Class.new(RuntimeError) |
This file contains hidden or 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 PerRequestCache #THIS IS TOTALLY NOT THREAD SAFE!!!!!!! | |
| class << self | |
| def open_the_cache | |
| @cache = {} | |
| end | |
| def clear_the_cache | |
| @cache = nil | |
| end |
This file contains hidden or 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 Rack::Jsmin | |
| def initialize(app) | |
| @app = app | |
| end | |
| def call(env) | |
| response, headers, body = @app.call(env) | |
| if response == 200 and not env["rack.jsmin.ignore"] and headers["Content-Type"].starts_with? "text/javascript" | |
| payload = "" | |
| body.each{|part| payload << part} |
This file contains hidden or 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 Rack::ProcTitle | |
| F = ::File | |
| PROGNAME = F.basename($0) | |
| def initialize(app) | |
| @app = app | |
| @appname = Dir.pwd.split('/').reverse. | |
| find { |name| name !~ /^(\d+|current|releases)$/ } || PROGNAME | |
| @requests = 0 | |
| $0 = "#{PROGNAME} [#{@appname}] init ..." |
This file contains hidden or 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 "net/http" | |
| require "enumerator" | |
| # Example Usage: | |
| # | |
| # use Rack::Proxy do |req| | |
| # if req.path =~ %r{^/remote/service.php$} | |
| # URI.parse("http://remote-service-provider.com/service-end-point.php?#{req.query}") | |
| # end | |
| # end |
This file contains hidden or 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 "net/http" | |
| # Example Usage: | |
| # | |
| # use Rack::Proxy do |req| | |
| # if req.path =~ %r{^/remote/service.php$} | |
| # URI.parse("http://remote-service-provider.com/service-end-point.php?#{req.query}") | |
| # end | |
| # end | |
| # |
This file contains hidden or 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
| height = 10 | |
| base = [height / 6, 8].max | |
| width = lambda{|r| r * 2 - 1} | |
| to_center = lambda{|s| s.center([height, base].map(&width).max)} | |
| to_stars = '*'.method(:*) | |
| tree = lambda{|v| v.map(&width).map(&to_stars) } | |
| puts ( | |
| tree[1..height] + | |
| tree[[2]*3] + |