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
Artist.select(:id, :name).naked.all | |
# => [{:id=>1, :name=>"mrbrdo"}] |
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
artists = Artist.eager(songs: ->(q) { q.where{year > 1990} }).all | |
# example to illustrate the results | |
artists.each do |artist| | |
puts "Artist: #{artist.name}" | |
puts "Songs since 1990: " + artist.songs.map(&:title).join(", ") | |
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
def x: Int = { println("x()"); 1 } | |
def a(byName1: => Int, byName2: => Int): Unit = { | |
println("a()") | |
println(byName1 + byName2) | |
} | |
a(x * 2, x * 3) | |
// output (note when x is actually called): |
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
# /config/application.rb | |
config.middleware.insert_before ActionDispatch::ParamsParser, "SelectiveStack" | |
# /config/initializers/omniauth.rb | |
::OmniAuthConfig = Proc.new do | |
provider :github, # ... | |
end | |
# /app/middleware | |
class SelectiveStack |
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
BlogsDatasource.new(Blog.all) | |
.select(:id, posts: { scope: Post.all, select: [:id, :author_name] }).results | |
# (0.1ms) SELECT blogs.id FROM "blogs" | |
# (0.2ms) SELECT posts.id, posts.blog_id, (posts.author_first_name || ' ' || posts.author_last_name) as author_name FROM "posts" WHERE (posts.blog_id IN (1)) | |
PostsDatasource.new(Post.all) | |
.select(:id, :title, :author, :author_name).results | |
# (0.1ms) SELECT posts.id, posts.title, posts.author_first_name, posts.author_last_name, (posts.author_first_name || ' ' || posts.author_last_name) as author_name FROM "posts" |
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
➜ ams_vs_jbuilder git:(master) ✗ rake benchmarks:single_object_with_render | |
Calculating ------------------------------------- | |
jbuilder 12 i/100ms | |
active_model_serializers | |
50 i/100ms | |
thin_serializer 53 i/100ms | |
------------------------------------------------- | |
jbuilder 132.1 (±6.8%) i/s - 660 in 5.028041s | |
active_model_serializers | |
524.8 (±13.7%) i/s - 2600 in 5.088049s |
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 Object | |
def test1 # instance method! | |
end | |
end | |
Object.test1 # OK | |
class SomeClass | |
def test2 | |
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
struct mrb_jmpbuf buf; | |
MRB_TRY(&buf) { | |
mrb->jmp = &buf; | |
} | |
MRB_CATCH(&buf) { | |
// handle error | |
} | |
MRB_END_EXC(&buf); |
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
struct mrb_jmpbuf buf; | |
int stoff = mrb->c->stack - mrb->c->stbase; | |
int cioff = mrb->c->ci - mrb->c->cibase; | |
MRB_TRY(&buf) { | |
mrb->jmp = &buf; | |
} | |
MRB_CATCH(&buf) { | |
// if rescued from method that was called from this method | |
// and didn't have its own rescue |
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
$ gem list | grep sequel | |
sequel (4.10.0) | |
$ irb | |
jruby-1.7.12 :001 > require 'sequel' | |
=> true | |
jruby-1.7.12 :002 > Sequel.connect("jdbc:postgresql://localhost/mydb") | |
=> #<Sequel::JDBC::Database: "jdbc:postgresql://localhost/mydb"> | |
jruby-1.7.12 :003 > class ContentMetric < Sequel::Model | |
jruby-1.7.12 :004?> end |