Skip to content

Instantly share code, notes, and snippets.

@mje113
mje113 / gist:6769883
Created September 30, 2013 20:36
Jruby error...
NoMethodError (super: no superclass method `request_parameters'):
gems/gems/actionpack-3.2.13/lib/action_dispatch/http/request.rb:237:in `POST'
gems/gems/actionpack-3.2.13/lib/action_dispatch/http/parameters.rb:10:in `parameters'
@mje113
mje113 / ruby-2.1.rb
Last active December 21, 2015 07:48 — forked from haileys/ruby-2.1.rb
class Foo
public def my_public_method
1 + 2
end
protected def my_protected_method
3 + 4
end
def my_private_method
@mje113
mje113 / gist:5859525
Created June 25, 2013 15:41
Performance improvement for ActionController::Responder#to_format
# Orignal
module ActionController
class Responder
def to_format
if get? || !has_errors? || response_overridden?
default_render
else
display_errors
end
def self.tree(path = nil)
Rails.cache.fetch("folder-tree-#{path}", expires_in: 0) do
folders = Folder.where('path LIKE ?', "#{path}%").all
path_parts = path.to_s.count('/')
local_root = root
local_first_tier = []
folders.each do |folder|
folder.children = folders.select { |f| f.parent_id == folder.id }.sort { |a, b| a.position <=> b.position }
local_root = folder if path == folder.path
puts "hello joe"
module Rack
class Request
def subdomains(tld_len=1) # we set tld_len to 1, use 2 for co.uk or similar
# cache the result so we only compute it once.
@env['rack.env.subdomains'] ||= lambda {
# check if the current host is an IP address, if so return an empty array
return [] if (host.nil? ||
/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host))
host.split('.')[0...(1 - tld_len - 2)] # pull everything except the TLD
}.call