This file contains hidden or 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 "big_int" | |
class Enumerator(T) | |
include Enumerable(T) | |
struct Yielder(T) | |
def initialize | |
@channel = Channel(T).new(20) | |
end |
This file contains hidden or 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 Node | |
include Enumerable(self) | |
property left, right, data | |
def initialize(@data) | |
end | |
def each(&block : Node ->) | |
left.try &.each(&block) |
This file contains hidden or 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
struct Block | |
def initialize(str : String) | |
@data = str | |
end | |
def initialize(int : Int32) | |
@data = int | |
end | |
def data |
This file contains hidden or 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 "http/client" | |
def title(x) | |
url = "http://www.wunderground.com/cgi-bin/findweather/hdfForecast?query=#{x}" | |
tag = "<meta property=\"og:title\" content=\"" | |
response = HTTP::Client.get(url).body | |
title1 = response.index(tag).not_nil! | |
title2 = response.index("\" />", title1).not_nil! - 1 | |
result = response[(title1 + tag.length)..title2] | |
result = result.gsub /°/, "°F" |
This file contains hidden or 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 Object | |
def colorize | |
ColorizedObject.new(self) | |
end | |
def colorize(fore) | |
ColorizedObject.new(self).fore(fore) | |
end | |
end |
This file contains hidden or 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
lib LibC | |
fun opendir(name : UInt8*) : Dir* | |
fun find_first_file = FindFirstFile(...) : Dir* | |
end | |
module LibCWrappers | |
def self.opendir(path) | |
ifdef windows | |
LibC.find_first_file(path, ...) | |
else |
This file contains hidden or 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
lib LibC | |
ifdef windows | |
fun find_first_file = FindFirstFile(...) : Dir* | |
fun opendir(name : UInt8) : Dir* | |
find_first_file(name, ...) | |
end | |
else | |
fun opendir(name : UInt8*) : Dir* | |
end | |
end |
This file contains hidden or 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
lib LibC | |
fun opendir(name : UInt8*) : Dir* | |
fun find_first_file = FindFirstFile(...) : Dir* | |
end | |
class Dir | |
def initialize(@path) | |
ifdef windows | |
@dir = LibC.find_first_file(@path, ...) | |
else |
This file contains hidden or 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 "benchmark" | |
require "http/client" | |
def get(url) | |
HTTP::Client.get(url) | |
end | |
Benchmark.bm do |x| | |
x.report("sync") do | |
get("http://www.google.com") |
This file contains hidden or 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
module Enumerable | |
def parallel_map(&block : T -> U) | |
channel = Channel(U).new(20) | |
count = 0 | |
each do |e| | |
spawn parallel_map_task(channel, block, e) | |
count += 1 | |
end |