Skip to content

Instantly share code, notes, and snippets.

@grvm
grvm / server.cr
Created March 24, 2017 09:23
HTTP Server in Crystal
require "http/server"
server = HTTP::Server.new(8080) do |context|
context.response.content_type = "text/plain"
context.response.print "Hello world at #{Time.now}"
end
puts "Listening on http://0.0.0.0:8080"
server.listen
@grvm
grvm / hello.cr
Last active March 24, 2017 05:15
Hello World in Crystal
# The customary Hello World program in Crystal
puts "Hello World!"
@grvm
grvm / flattener.rb
Last active August 21, 2016 12:50
Ruby custom implementation of Array#flatten using Regular Expressions
x = [[1], [2, 3, [4, 5, 6, [7, 8, 9, 10], 11], 12, 13], 14, 15, 16]
class Array
def flattener
matches = self.to_s.scan(/\d+/)
matches.collect(&:to_i)
end
end
puts "Specs"