Skip to content

Instantly share code, notes, and snippets.

Ary Borenszweig asterite

Block or report user

Report or block asterite

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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
View bail_out.cr
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
View stream_json_to_yaml_and_yaml_to_json.cr
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
View compiler_union_types_with_a_struct.txt
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]
View 1.txt
+13
+19
+11
+15
+1
+7
+17
+14
-16
+15
View instances_count.diff
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
How JSON serialization would look like if Crystal had user-defined annotations like Java/C#
View json_with_annotations.txt
require "spec"
require "json"
require "uuid"
require "uuid/json"
require "big/json"
module JSON
annotation Field
end
View utf16.cr
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 Oct 31, 2017
Refactoring in Crystal
View rename.cr
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.
#
You can’t perform that action at this time.