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
record Cell, car, cdr
alias List = Nil | (-> Cell)
def inf(x = 0)
inf :: -> Cell
inf = -> { Cell.new(x, inf) }
end
def nat(x = 0)
@asterite
asterite / rename.cr
Created October 31, 2017 12:11
Refactoring in Crystal
class Foo
def foo(x)
# Rename this call from "bar" to "baz":
# What other things change in this file?
#
# According to what's called, Bar#bar needs
# to change. But what about Baz#bar? I can
# also pass Baz.new to Foo.new.foo. There's
# no way to tell if that should be renamed too.
#
require "benchmark"
module Parser(T)
def self.char(a : Char)
CharParser.new(a)
end
def self.int
IntParser.new
end
@asterite
asterite / dependency_sets.cr
Created January 4, 2023 18:01
Compute dependency sets
def affected_files(file, dependencies)
tracked_files = Set(String).new
track(file, dependencies, tracked_files)
tracked_files
end
def track(file, dependencies, tracked_files)
return unless tracked_files.add?(file)
dependencies[file].each do |to|
@asterite
asterite / move_deployed_linear_issues.rb
Last active February 27, 2023 15:45
A Ruby script that moves Linear issues to staging/production columns
# Make sure to configure this script!
# 1. Change `TEAM_LINEAR` properties below to match your Linear team
# 2. Optionally add more teams
# 3. Change the value of `DEPLOYED_TO_STAGING_GIT_TAG` to the tag/branch you use for deploys to staging
# 4. Change the value of `DEPLOYED_TO_PRODUCTION_GIT_TAG` to the tag/branch you use for deploys to production
#
# Usage:
# LINEAR_API_KEY=... GITHUB_API_KEY=... ruby move_deployed_linear_issues.rb
#
# Adding new teams (change "LinearTeam" to your team name):
@asterite
asterite / SExpression parser
Created October 14, 2010 17:40
An S-Expression lexer/parser. Later i found out with regexps it's much faster to code and it actually works faster.
#!/usr/bin/ruby
class Lexer
def initialize(str)
@str = str
@p = 0
end
def next_token
while true
# 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).
# 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
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 January 20, 2021 12:05
Plays "Secret Code" from Clubhouse Games 51 (Spanish only)
require "colorize"
enum Color
Red
Green
Blue
Yellow
Pink
Gray