Skip to content

Instantly share code, notes, and snippets.

View asterite's full-sized avatar

Ary Borenszweig asterite

  • NoRedInk
  • Buenos Aires, Argentina
View GitHub Profile
require "big_int"
class Enumerator(T)
include Enumerable(T)
struct Yielder(T)
def initialize
@channel = Channel(T).new(20)
end
class Node
include Enumerable(self)
property left, right, data
def initialize(@data)
end
def each(&block : Node ->)
left.try &.each(&block)
struct Block
def initialize(str : String)
@data = str
end
def initialize(int : Int32)
@data = int
end
def data
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 /&deg;/, "°F"
class Object
def colorize
ColorizedObject.new(self)
end
def colorize(fore)
ColorizedObject.new(self).fore(fore)
end
end
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
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
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
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")
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