This file contains 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 Result{ | |
constructor(public title: string, public imagePath: string) { } | |
} | |
class Sentence{ | |
base: string; | |
values: string[]; | |
results: { [id: string]: Result }; | |
constructor(base: string, values: string[], results: { [id: string]: Result }) { |
This file contains 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
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'rspec' | |
end | |
require 'rspec/autorun' | |
class Car |
This file contains 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
require 'rspec/autorun' | |
class Parent | |
def self.descendants | |
ObjectSpace.each_object(Class).select { |klass| klass < self } | |
end | |
def foo | |
fail NotImplementedError | |
end |
This file contains 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
set number | |
set ruler | |
set hidden | |
set hlsearch " highlight search terms | |
set incsearch " show search matches as you type | |
set history=1000 " remember more commands and search history | |
set undolevels=1000 " use many muchos levels of undo | |
set wildignore=*.swp,*.bak,*.pyc,*.class | |
set title " change the terminal's title | |
set visualbell " don't beep |
This file contains 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
Benchmark.bm do |x| | |
x.report(:naive) { BikesReport::NaiveApproach.new.to_a } | |
x.report(:ar_and_sql) { BikesReport::ActiveRecordSqlApproach.new.to_a } | |
x.report(:view) { BikesReport::ViewApproach.new.to_a } | |
end | |
# user system total real | |
# 9.430000 0.650000 10.080000 ( 10.306346) | |
# 0.020000 0.000000 0.020000 ( 0.125085) | |
# 0.010000 0.000000 0.010000 ( 0.011208) |
This file contains 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 BikesReport::ViewApproach | |
def to_a | |
BikesReport | |
.all | |
.as_json | |
.map { |r| r.symbolize_keys!.merge!(model: MODELS.fetch(r[:model])) } | |
end | |
private |
This file contains 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 BikesReport < ActiveRecord::Base | |
def self.refresh | |
Scenic | |
.database | |
.refresh_materialized_view(table_name, concurrently: false) | |
end | |
def readonly? | |
true | |
end |
This file contains 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 CreateBikesReports < ActiveRecord::Migration | |
def change | |
create_view :bikes_reports, materialized: true | |
end | |
end |
This file contains 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 CreateBikesReportView < ActiveRecord::Migration | |
def change | |
reversible do |dir| | |
dir.up do | |
execute( | |
<<-QUERY | |
CREATE MATERIALIZED VIEW bikes_reports AS | |
SELECT | |
bikes.name, bikes.model, | |
count(rentals.id) as times_rented, |
This file contains 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
Benchmark.bm do |x| | |
x.report(:naive) { BikesReport::NaiveApproach.new.to_a } | |
x.report(:ar_and_sql) { BikesReport::ActiveRecordSqlApproach.new.to_a } | |
end | |
# user system total real | |
# 9.600000 0.790000 10.390000 ( 10.639153) | |
# 0.020000 0.000000 0.020000 ( 0.137610) |
NewerOlder