Skip to content

Instantly share code, notes, and snippets.

View NetguruGist's full-sized avatar

Netguru NetguruGist

View GitHub Profile
package main
import (
"fmt"
"image/color"
"time"
"github.com/szeliga/goray/engine"
)
func (s *Scene) Save(filename string) {
f, err := os.Create(filename)
if err != nil {
panic(err)
}
defer f.Close()
png.Encode(f, s.Img)
}
func (s *Scene) EachPixel(colorFunction func(int, int) color.RGBA) {
for x := 0; x < s.Width; x++ {
for y := 0; y < s.Height; y++ {
s.setPixel(x, y, colorFunction(x, y))
}
}
}
func TestSceneEachPixelSetsEachPixelToTheProvidedFunctionReturn(t *testing.T) {
scene := NewScene(4, 4)
func generateImage(w, h int, pixelColor color.RGBA) *image.RGBA {
img := image.NewRGBA(image.Rect(0, 0, 4, 4))
for x := 0; x < 4; x++ {
for y := 0; y < 4; y++ {
img.Set(x, y, pixelColor)
}
}
return img
}
func TestNewSceneReturnsANewScene(t *testing.T) {
scene := NewScene(4, 4)
rect := image.Rect(0, 0, 4, 4)
assert.Equal(t, 4, scene.Width, "sets width of the scene")
assert.Equal(t, 4, scene.Height, "sets height of the scene")
assert.True(t, assert.ObjectsAreEqualValues(rect, scene.Img.Bounds()),
"creates an image.RGBA with proper bounds")
}
func NewScene(width int, height int) *Scene {
type Scene struct {
Width, Height int
Img *image.RGBA
}
test:
override:
- COVERAGE=true node_modules/ember-cli/bin/ember test
post:
- codeclimate-test-reporter < ‘coverage/lcov.info'
@NetguruGist
NetguruGist / performance_post_9.bash
Created October 11, 2016 12:57
performance_post_9.bash
Post Load (0.5ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC LIMIT $1 [["LIMIT", 1]]
(0.1ms) BEGIN
SQL (0.4ms) DELETE FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 15]]
SQL (1.1ms) DELETE FROM "posts" WHERE "posts"."id" = $1 [["id", 15]]
@NetguruGist
NetguruGist / performance_post_8.bash
Created October 11, 2016 12:57
performance_post_8.bash
Post Load (0.5ms) SELECT "posts".* FROM "posts" WHERE "posts"."id" = $1 [["id", 1]]
(0.1ms) BEGIN
Comment Load (0.5ms) SELECT "comments".* FROM "comments" WHERE "comments"."post_id" = $1 [["post_id", 16]]
SQL (0.5ms) DELETE FROM "comments" WHERE "comments"."id" = $1 [["id", 1]]
SQL (0.3ms) DELETE FROM "comments" WHERE "comments"."id" = $1 [["id", 2]]
SQL (0.2ms) DELETE FROM "comments" WHERE "comments"."id" = $1 [["id", 3]]
SQL (0.3ms) DELETE FROM "comments" WHERE "comments"."id" = $1 [["id", 4]]
SQL (0.5ms) DELETE FROM "posts" WHERE "posts"."id" = $1 [["id", 16]]
@NetguruGist
NetguruGist / performance_post_7.rb
Created October 11, 2016 12:55
performance_post_7.rb
class PostsController < ApplicationController
def destroy
@post = Post.find(params[:id]).destroy
...
end
end