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
#!/usr/bin/env ruby | |
require "net/http" | |
require "uri" | |
require "json" | |
require "base64" | |
class Imgur | |
API_KEY = "15a6efd29935f62ea87579a8325d945a" | |
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
def raise_error(error_name, superclass = Exception) | |
raise self.class.const_get error_name | |
rescue NameError | |
self.class.const_set error_name, Class.new(superclass) | |
retry | |
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
data Protocol | |
= Hybi00 | |
| Hybi01 | |
sendMessage :: Protocol -> Message -> IO () | |
sendMessage HybiOO (Text text) = putStrLn $ "[Hybi00] " ++ text | |
sendMessage HybiOO (Binary _) = error "LOL" | |
sendMessage Hybi01 (Text text) = .. |
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 'rest_client' | |
require 'nori' | |
Nori.configure do |config| | |
config.strip_namespaces = true | |
config.convert_tags_to { |tag| tag.snakecase.to_sym } | |
end | |
module W3C |
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
{-# LANGUAGE GADTs, FlexibleInstances, MultiParamTypeClasses #-} | |
import Control.Monad.State.Class | |
import Control.Monad.Trans.Class | |
data StateD s m a where | |
Get :: StateD s m s | |
Put :: s -> StateD s m () | |
Return :: a -> StateD s m a | |
Bind :: StateD s m a -> (a -> StateD s m b) -> StateD s m b | |
Lift :: m a -> StateD s m a |
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
{-# LANGUAGE GADTs, FlexibleInstances, MultiParamTypeClasses #-} | |
import Control.Monad.State.Class | |
import Control.Monad.Trans.Class | |
data StateD s m a where | |
Get :: StateD s m s | |
Put :: s -> StateD s m () | |
Return :: a -> StateD s m a | |
Bind :: StateD s m a -> (a -> StateD s m b) -> StateD s m b | |
Lift :: m a -> StateD s m a |
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
{:ABS_URI=>/\A\s* | |
([a-zA-Z][\-+.a-zA-Z\d]*): (?# 1: scheme) | |
(?: | |
((?:[\-_.!~*'()a-zA-Z\d;?:@&=+$,]|%[a-fA-F\d]{2})(?:[\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]]|%[a-fA-F\d]{2})*) (?# 2: opaque) | |
| | |
(?:(?: | |
\/\/(?: | |
(?:(?:((?:[\-_.!~*'()a-zA-Z\d;:&=+$,]|%[a-fA-F\d]{2})*)@)? (?# 3: userinfo) | |
(?:((?:(?:[a-zA-Z0-9\-.]|%\h\h)+|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|\[(?:(?:[a-fA-F\d]{1,4}:)*(?:[a-fA-F\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|(?:(?:[a-fA-F\d]{1,4}:)*[a-fA-F\d]{1,4})?::(?:(?:[a-fA-F\d]{1,4}:)*(?:[a-fA-F\d]{1,4}|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}))?)\]))(?::(\d*))?))? (?# 4: host, 5: port) | |
| |
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
MOVE_ARRAY = [[0,1],[-1,0],[0,-1],[1,0]] | |
ODD_SQUARES = (1..10000).select(&:odd?).map {|i| i * i} | |
# move the pointer in the spiral to the next position | |
def move(counter, x, y) | |
# we should go right if we are a square number | |
sqrt_counter = Math.sqrt(counter).to_i | |
sqrt_counter = sqrt_counter.odd? ? sqrt_counter : sqrt_counter - 1 | |
return [x+1, y] if ODD_SQUARES.include? counter | |
lowest_right_corner = sqrt_counter * sqrt_counter | |
move_array_index = (1..4).detect do |i| |
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
input = File.readlines("inputs/day5.in") | |
stack = input.map &:to_i | |
def move(array, position) | |
offset = array[position] | |
if offset >=3 | |
array[position] -= 1 | |
else | |
array[position] += 1 | |
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
input = File.readlines("inputs/day7.in") | |
DISCS = {} | |
class Disc < Struct.new(:name, :weight, :children, :parent) | |
def subtree_weight | |
return weight unless children | |
children.map {|c| DISCS[c].subtree_weight}.inject(0) {|a,b| a+b} + weight | |
end | |
end |
OlderNewer