Skip to content

Instantly share code, notes, and snippets.

View lukaszx0's full-sized avatar

Lukasz Strzalkowski lukaszx0

  • Column
View GitHub Profile
irb(main):001:0> s = 92.chr
=> "\\"
irb(main):002:0> s.size
=> 1
irb(main):003:0> puts s
\
=> nil
irb(main):004:0> s2 = s + s
=> "\\\\"
irb(main):005:0> s2.size
@lukaszx0
lukaszx0 / bind_to_instance_method.rb
Last active August 29, 2015 14:01
Lukasz's Debugging Tricks
class Post < ActiveRecord::Base
has_many :comments
end
class Comments
belongs_to :post
end
Post.first.comments.class # => Array
Kernel.instance_method(:class).bind(Post.first.comments).call # => ActiveRecord::Associations::CollectionProxy
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index a8368b6..abe4d71 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -500,11 +500,11 @@ module ActionDispatch
end
def recognize_path(path, environment = {})
- method = (environment[:method] || "GET").to_s.upcase
+ environment[:method] = (environment[:method] || "GET").to_s.upcase
[43] square » Rails.application.routes.draw do
» get "/foo" => "foo#bar"
» end
=> nil
[44] square » Rails.application.routes.routes
=> [
[0] GET /foo(.:format) {:controller=>"foo", :action=>"bar"}
]
from /Users/lukaszstrzalkowski/Development/rails/actionpack/lib/action_dispatch/routing/route_set.rb:532:in `recognize_path'
[46] square » Rails.application.routes.recognize_path("/foo", :method => :get)
class Foobar
def initialize
@data = {}
@lock = Mutex.new
end
def [](key)
@lock do
@data[key.to_s]
end
class Foobar
def foo
...
end
end
class Barfoo < Foobar
def foo
super
# check from where super comes and print "Foobar"
@lukaszx0
lukaszx0 / 1_README.md
Last active December 21, 2015 10:39
Rails benchmark with and without ActionView

Some quick benchmarks on extracting ActionView from ActionPack. There are performance gains in both development and production envs, but not that significant.

AB Results

Requests per second [#/sec] (mean)
@lukaszx0
lukaszx0 / view_classes_proposal.md
Last active December 21, 2015 06:59
View Classes implementation proposal
@lukaszx0
lukaszx0 / test.geojson
Last active December 21, 2015 00:29
Geojson test
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
class TestController < ActionController::Base
protect_from_forgery
def render_string_hello_world
render "Hello world!"
end
def render_text_hello_world
render :text => "hello world"
end