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 "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
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
def reset
user = current_user
return unless user
user_id = user.id
return unless user_id
server = VirtualMachine.find_by(user_id: user_id, id: params[:server_id])
return unless server
require "spec"
require "json"
require "yaml"
class JSON::Builder
def next_is_object_key?
state = @state.last
state.is_a?(ObjectState) && state.name
end
end
9 - [Bool, Int32, Int64, Slice(UInt8), String, UInt16, UInt32, UInt64, UInt8]
2 - [Crystal::Formatter::HeredocInfo, Crystal::StringInterpolation]
5 - [JSON::Builder::ArrayState, JSON::Builder::DocumentEndState, JSON::Builder::DocumentStartState, JSON::Builder::ObjectState, JSON::Builder::StartState]
3 - [Bool, Crystal::Compiler::Result, Nil]
2 - [Tuple(Int32), Tuple(Int32, Int32)]
2 - [Tuple(Char), Tuple(Char, Char)]
2 - [Pointer(Pointer(Void)), Pointer(Void)]
2 - [Bool, Slice(UInt8)]
3 - [Colorize::Color256, Colorize::ColorANSI, Colorize::ColorRGB]
2 - [HTTP::Headers::Key, String]
+13
+19
+11
+15
+1
+7
+17
+14
-16
+15
diff --git a/src/compiler/crystal/semantic/cleanup_transformer.cr b/src/compiler/crystal/semantic/cleanup_transformer.cr
index e108c12f1..59a21ef07 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_types_and_methods(self)
@asterite
asterite / json_with_annotations.txt
Last active May 5, 2018 11:49
How JSON serialization would look like if Crystal had user-defined annotations like Java/C#
require "spec"
require "json"
require "uuid"
require "uuid/json"
require "big/json"
module JSON
annotation Field
end
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.
#