Skip to content

Instantly share code, notes, and snippets.

View TheDudeWithTheThing's full-sized avatar
🎯
Focusing

Shaun Butler TheDudeWithTheThing

🎯
Focusing
View GitHub Profile
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]] }
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
@TheDudeWithTheThing
TheDudeWithTheThing / sky_line.rb
Last active December 5, 2016 16:03
My SkyLine solution
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
@TheDudeWithTheThing
TheDudeWithTheThing / ParseRedistogoUrl
Created September 6, 2013 19:29
A simple function for Go (golang) projects on Heroku using Redis To Go. It pulls the environment var REDISTOGO_URL and returns the server:port and password part of it for use with redis clients. Used in my project to learn Go at https://github.com/TheDudeWithTheThing/quotient-quotables
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
}
@TheDudeWithTheThing
TheDudeWithTheThing / Search with scores
Created March 24, 2013 22:07
For thredded. Search for posts using scores where topics weigh more than posts
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