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 './sky_skraper.rb' | |
require 'pry' | |
describe SkySkraper do | |
describe '#area' do | |
subject { SkySkraper.area(coords) } | |
context 'two coords with overlap' do | |
let(:coords) { [[11, 14, 2], [12, 13, 5]] } |
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
Code.load_file("sky_skraper.exs", __DIR__) | |
ExUnit.start | |
defmodule SkySkraperTest do | |
use ExUnit.Case | |
test "two coords with overlap" do | |
assert SkySkraper.area([[11, 14, 2], [12, 13, 5]]) == 9 | |
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 SkySkraper | |
def self.area(coords) | |
area_total = 0 | |
height_at = {} | |
coords.each do |set| | |
(x1, x2, height) = set | |
range_exclude_last(x1, x2).each do |x| | |
height_at[x] ||= 0 |
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
func ParseRedistogoUrl() (string, string) { | |
redisUrl := os.Getenv("REDISTOGO_URL") | |
redisInfo, _ := url.Parse(redisUrl) | |
server := redisInfo.Host | |
password := "" | |
if redisInfo.User != nil { | |
password, _ = redisInfo.User.Password() | |
} | |
return server, password | |
} |
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
WITH topic_scores as ( | |
SELECT t.id as id, 1 as score | |
FROM topics t, posts p | |
WHERE t.messageboard_id = 1 | |
AND t.id = p.topic_id | |
AND to_tsvector('english', p.content) @@ plainto_tsquery('english', 'mortified') | |
UNION | |
SELECT t.id as id, 3 as score | |
FROM topics t | |
WHERE t.messageboard_id = 1 |