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 "spec"
module UTF16
def self.encode(string : String) : Slice(UInt16)
size = 0
string.each_char do |char|
size += char.ord < 0x10000 ? 1 : 2
end
slice = Slice(UInt16).new(size)
@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 "csv"
class CSV
macro mapping(mappings)
{% for key, value in mappings %}
{% mappings[key] = {type: value} unless value.is_a?(HashLiteral) %}
{% end %}
{% for key, mapping in mappings %}
property {{key}} : {{mapping[:type]}}
diff --git a/src/compiler/crystal/semantic/cleanup_transformer.cr b/src/compiler/crystal/semantic/cleanup_transformer.cr
index 40693c55a..bd90f1c3e 100644
--- a/src/compiler/crystal/semantic/cleanup_transformer.cr
+++ b/src/compiler/crystal/semantic/cleanup_transformer.cr
@@ -23,6 +23,8 @@ module Crystal
initializer.node = initializer.node.transform(transformer)
end
end
+
+ TypesAndMethodsPrinter.new.print_type_with_methods(self)
@asterite
asterite / crystal_compiler_types_and_methods.txt
Created August 21, 2017 01:47
All types and methods instantiated when compiling the Crystal compiler
This file has been truncated, but you can view the full file.
|=== <Program> ===|
#__crystal_get_exception(Pointer(LibUnwind::Exception))
#__crystal_malloc(UInt32)
#__crystal_malloc_atomic(UInt32)
#__crystal_personality(Int32, LibUnwind::Action, UInt64, Pointer(LibUnwind::Exception), Pointer(Void))
#__crystal_raise(Pointer(LibUnwind::Exception))
#__crystal_raise_string(Pointer(UInt8))
#__crystal_realloc(Pointer(Void), UInt32)
#__crystal_sigfault_handler(Int32, Pointer(Void))
#_fiber_get_stack_top()
def sozcore2(num, start_num, mod)
residues, rescnt = make_residues_rescnt(mod) # parameters for the PG
maxprms, x = pcs_to_num(num, mod, rescnt, residues, true) # num pcs <= end_num
# for start_num pc, find num pcs <, residue index, and resgroup mod value
pcs2start, rs, modks = pcs_to_num(start_num, mod, rescnt, residues, false)
sqrtN = Math.sqrt(num).to_i # sqrt of end_num (end of range)
pcs2sqrtN, y = pcs_to_num(sqrtN, mod, rescnt, residues, true) # num pcs <= sqrt
require "big_int"
require "benchmark"
lib LibGMP
fun sizeinbase = __gmpz_sizeinbase(op : MPZ*, base : Int32) : Int32
fun export = __gmpz_export(rop : Void*, countp : Int32*, order : Int32, size : Int32, endian : Int32, nails : Int32, op : MPZ*) : UInt8*
end
struct BigInt
def size
require "http/client"
require "yaml"
record PosRange, start : Int32, end : Int32
repo = ARGV[0]?
unless repo
abort "missing repo"
end
@asterite
asterite / lmdb.cr
Last active November 26, 2016 21:56
@[Link("lmdb")]
lib LibLMDB
alias Int = LibC::Int
alias UInt = LibC::UInt
alias Char = LibC::Char
alias SizeT = LibC::SizeT
type Env = Void*
type Txn = Void*
type Cursor = Void*
# ### References
#
# * [Christian Lindig, Strictly Pretty, March 2000](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.34.2200)
# * [Philip Wadler, A prettier printer, March 1998](http://homepages.inf.ed.ac.uk/wadler/topics/language-design.html#prettier)
class PrettyPrinter
# :nodoc:
private alias Element = Break | Text | Group
# :nodoc:
private record Break, string : String do