Skip to content

Instantly share code, notes, and snippets.

View NetguruGist's full-sized avatar

Netguru NetguruGist

View GitHub Profile
@NetguruGist
NetguruGist / performance_post_6.rb
Created October 11, 2016 12:54
performance_post_6.rb
class User < ApplicationRecord
has_many :comments, dependent: :destroy
end
@NetguruGist
NetguruGist / performance_post_5.rb
Created October 11, 2016 12:51
performance_post_5.rb
class PostsController < ApplicationController
def show
@post = Post.includes(:comments).find(params[:id])
end
end
@NetguruGist
NetguruGist / performance_post_4.bash
Created October 11, 2016 12:49
performance_post_4.bash
Post Load (0.4ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" ASC LIMIT $1 [["LIMIT", 1]]
Comment Load (0.3ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = 1
@NetguruGist
NetguruGist / performance_post_3.bash
Created October 11, 2016 12:44
performance_post_3.bash
Post Load (0.4ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 [["id", 1]]
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 1]]
Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 2]]
Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 3]]
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 4]]
....
@NetguruGist
NetguruGist / performance_post_2.erb
Created October 11, 2016 12:42
performance_post_2.erb
...
<ul>
<% @post.comments.each do |comment| %>
<li><%= comment.content %></li>
...
@NetguruGist
NetguruGist / performance_post_1.rb
Last active October 11, 2016 12:40
performance_post_1.rb
class PostsController < ApplicationController
def show
@post = Post.find(params[:id])
end
end
Post Load (0.4ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 [["id", 1]]
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 1]]
Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 2]]
Comment Load (0.1ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 3]]
Comment Load (0.2ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 4]]
app/controllers/posts_controller.rb
class PostsController < ApplicationController
def show
@post = Post.find(params[:id])
end
end
```
```ruby
app/views/posts/index.html.erb
import React from 'react';
import { imagePath } from 'rwr-view-helpers';
import { facebookIcon } from 'constants/icon-urls';
export default ({ alt }) => (
<img alt={alt} src={imagePath(facebookIcon)} />
);
go
func (a Vector) Normalize() Vector {
return a.MultiplyByScalar(1. / a.Length())
}
func TestNormalize(t *testing.T) {
assert.Equal(t, Vector{1., 0., 0.}, Vector{10., 0., 0.}.Normalize(),
"returns a unit vector (versor) from the given vector")
assert.Equal(t, Vector{0., 1., 0.}, Vector{0., 10., 0.}.Normalize(),
"returns a unit vector (versor) from the given vector")