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
macro ruby_class(name)
_class = Ruby::Class.new({{name.id.stringify}})
{{yield}}
end
macro ruby_def(name, &block)
_class.def {{name}}, {{block.args.length}},
->(self : LibRuby::VALUE, {{*block.args.map { |arg| "#{arg} : LibRuby::VALUE".id } }}) do
{{yield}}
end
class StringPool
getter length
def initialize
@buckets = Array(Array(String)?).new(11, nil)
@length = 0
end
def get(str : UInt8*, len)
rehash if @length > 5 * @buckets.length
module Crystal
module Config
PATH = {{ env("CRYSTAL_CONFIG_PATH") || "" }}
VERSION = {{ env("CRYSTAL_CONFIG_VERSION") || `(git describe --tags --long 2>/dev/null)` }}
end
end
@asterite
asterite / 0.5.0
Created September 30, 2014 17:42
We are very happy to announce the release of version 0.5.0 of Crystal!
For those of you who couldn't install Crystal so far, or had troubles installing it, we have good news: we now provide .deb, .rpm and .tar.gz packages for 64 bits linux architectures directly on the releases pages. We tries those in a very old Centos version, as well as in ArchLinux and Debian. The executable has all the necessaries libraries statically linked so there won't be any more problems with incompatible or missing shared libraries [*]. And it also has LLVM statically linked: the only executable you need to have in your system is cc.
For Mac users the install procedure is the same as before:
brew tap manastech/crystal
brew update
brew install crystal
class StopIteration < Exception
def initialize
super("StopIteration")
end
end
module Iterator(T)
include Enumerable(T)
def map(&func : T -> U)
def self.read_keypress
case C.getchar
when 'a'
:left
when 's'
:down
when 'd'
:right
when 'w'
:up
; ModuleID = 'foo.ll'
target triple = "x86_64-apple-darwin12.5.0"
%String = type { i32, i32, i8 }
%"{Int32, Int32, Int32}" = type { i32, i32, i32 }
@symbol_table = global [0 x %String*] zeroinitializer
; Function Attrs: nounwind readnone
define i32 @__crystal_main(i32 %argc, i8** nocapture %argv) #0 {
@asterite
asterite / initialize_overload.cr
Created May 15, 2014 19:19
initialize overload
class Foo
def initialize(x : Number)
puts "#{x} is a number!"
end
def initialize(x : String)
puts "#{x} is a string!"
end
end
type = :info
time = Time.now
2_000_000.times do
msg = case type
when :success then 'alert-success'
when :error then 'alert-danger'
when :warn then 'alert-warning'
when :info then 'alert-info'
end
class Foo
property x
property y
property z
property w
def initialize
end
def dup