Skip to content

Instantly share code, notes, and snippets.

Avatar

Ary Borenszweig asterite

View GitHub Profile
View parser_combinators.cr
require "benchmark"
module Parser(T)
def self.char(a : Char)
CharParser.new(a)
end
def self.int
IntParser.new
end
View gc_peek.cr
time = Time.monotonic
gcfile = File.new("chry_multiplied.fa")
at = 0
gc = 0
while true
# Peek the IO's buffer
peek = gcfile.peek
@asterite
asterite / secret_code.cr
Created Jan 20, 2021
Plays "Secret Code" from Clubhouse Games 51 (Spanish only)
View secret_code.cr
require "colorize"
enum Color
Red
Green
Blue
Yellow
Pink
Gray
View constants_vs_inline.cr
require "benchmark"
RANGE = 3..7
a = 1
v = ARGV[0].to_i
Benchmark.ips do |x|
x.report("constant") do
case v
View maybe_faster.cr
# This Crystal source file is a multiple threaded implementation to perform an
# extremely fast Segmented Sieve of Zakiya (SSoZ) to find Twin Primes <= N.
# Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
# Output is the number of twin primes <= N, or in range N1 to N2; the last
# twin prime value for the range; and the total time of execution.
# This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
# 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
# probably needed to optimize for other hardware systems (ARM, PowerPC, etc).
View foo.cr
# This Crystal source file is a multiple threaded implementation to perform an
# extremely fast Segmented Sieve of Zakiya (SSoZ) to find Twin Primes <= N.
# Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
# Output is the number of twin primes <= N, or in range N1 to N2; the last
# twin prime value for the range; and the total time of execution.
# This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
# 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
# probably needed to optimize for other hardware systems (ARM, PowerPC, etc).
View twinprimes.cr
# This Crystal source file is a multiple threaded implementation to perform an
# extremely fast Segmented Sieve of Zakiya (SSoZ) to find Twin Primes <= N.
# Inputs are single values N, or ranges N1 and N2, of 64-bits, 0 -- 2^64 - 1.
# Output is the number of twin primes <= N, or in range N1 to N2; the last
# twin prime value for the range; and the total time of execution.
# This code was developed on a System76 laptop with an Intel I7 6700HQ cpu,
# 2.6-3.5 GHz clock, with 8 threads, and 16GB of memory. Parameter tuning
# probably needed to optimize for other hardware systems (ARM, PowerPC, etc).
View interfaces.cr
# One can write a class that wraps a Proc and calls it:
class Handler
def initialize(&@proc : -> String)
end
def call
@proc.call
end
end
View steps_no_flaws.cr
require "benchmark"
struct Foo
def initialize(@size : Int32, @stride : Int32)
end
def step_from_class
0.step(to: @size, by: @stride) do |i|
yield i
end
View steps.cr
require "benchmark"
struct Foo
def initialize(@size : Int32, @stride : Int32)
end
def step_from_class
0.step(to: @size, by: @stride) do |i|
yield i
end