Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Fedorov waterlink

View GitHub Profile
@waterlink
waterlink / struct_dsl.rb
Created Nov 7, 2014
Struct implementation as a module to extend
View struct_dsl.rb
require 'rspec'
module StructDsl
def with_attributes(*args)
include Enumerable
args.map!(&:to_sym)
args.freeze
args.each { |p| attr_accessor p }
@waterlink
waterlink / example.rb
Created Dec 29, 2014
Hello World example in ruby2cpp annotated ruby. Ready to be converted to c++.
View example.rb
# @ruby2cpp: std
class Hello
# @ruby2cpp: annotate(String -> void)
def initialize(greeting)
# @ruby2cpp: annotate(String)
@greeting = greeting
end
# @ruby2cpp: annotate(String -> void)
View rspec.log
1) RSpec::Expectations behaves like a library that issues no warnings when loaded issues no warnings when the spec files are loaded
Failure/Error: expect(stderr).to eq("")
expected: ""
got: "/Users/waterlink/.rvm/gems/ruby-2.2.0@global/gems/bundler-1.7.9/lib/bundler/source/rubygems.rb:191: warning: shadowing outer local variable - spec\n"
(compared using ==)
Diff:
@@ -1 +1,2 @@
View matcher_wrapper.rb
class MatcherWrapper
def initialize(matcher)
@matcher = matcher
end
def diffable?
with_default(false) { @matcher.diffable? }
end
def description
@waterlink
waterlink / x.rb
Created Mar 10, 2015
contracts.ruby :: Non-type checking example
View x.rb
# Classical defensive programming
def do_something_useful(active_user)
return unless active_user.last_action_date < 2.weeks.ago
# do something useful with active user
end
# ----
# With contracts:
Contract ActiveUser => Any
@waterlink
waterlink / log.txt
Created Mar 23, 2015
crystal-lang compiler error
View log.txt
; ModuleID = 'Hash((Int:Class | Float:Class), (MySQL::Types::Integer:Class | MySQL::Types::Float:Class))'
%String = type { i32, i32, i32, i8 }
%"Array(Int32)" = type { i32, i32, i32, i32* }
%"Hash((Int:Class | Float:Class), (MySQL::Types::Integer:Class | MySQL::Types::Float:Class))" = type { i32, i32, %"Hash(K, V)::Entry((Int:Class | Float:Class), (MySQL::Types::Integer:Class | MySQL::Types::Float:Class))"**, i32, i32, i1, %"Hash(K, V)::Entry((Int:Class | Float:Class), (MySQL::Types::Integer:Class | MySQL::Types::Float:Class))"*, %"Hash(K, V)::Entry((Int:Class | Float:Class), (MySQL::Types::Integer:Class | MySQL::Types::Float:Class))"* }
%"Hash(K, V)::Entry((Int:Class | Float:Class), (MySQL::Types::Integer:Class | MySQL::Types::Float:Class))" = type { i32, %"(Int:Class | Float:Class)", %"(MySQL::Types::Integer:Class | MySQL::Types::Float:Class)", %"Hash(K, V)::Entry((Int:Class | Float:Class), (MySQL::Types::Integer:Class | MySQL::Types::Float:Class))"*, %"Hash(K, V)::Entry((Int:Class | Float:Class), (MySQL::
@waterlink
waterlink / x.rb
Created Mar 26, 2015
Draft implementation for Rec
View x.rb
class DatatypeBase
def initialize(blk)
@blk = blk
end
def _resolve!
@raw_contract = instance_eval(&@blk)
end
def Rec(name, &blk)
@waterlink
waterlink / error.log
Created Mar 29, 2015
travis error log
View error.log
PUT https://api.travis-ci.org/hooks/4362171
generate-cr:1 XMLHttpRequest cannot load https://api.travis-ci.org/hooks/4362171. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://travis-ci.org' is therefore not allowed access. The response had HTTP status code 500.
undefined
vendor-203bc1bf399e89b6815a49be7adde6a7.js:10 undefinedvendor-203bc1bf399e89b6815a49be7adde6a7.js:10 c.onerrorDefaultvendor-203bc1bf399e89b6815a49be7adde6a7.js:15 e.default.triggervendor-203bc1bf399e89b6815a49be7adde6a7.js:15 h._onerrorvendor-203bc1bf399e89b6815a49be7adde6a7.js:14 dvendor-203bc1bf399e89b6815a49be7adde6a7.js:10 (anonymous function)vendor-203bc1bf399e89b6815a49be7adde6a7.js:4 r.invokevendor-203bc1bf399e89b6815a49be7adde6a7.js:4 r.flushvendor-203bc1bf399e89b6815a49be7adde6a7.js:4 n.flushvendor-203bc1bf399e89b6815a49be7adde6a7.js:4 o.endvendor-203bc1bf399e89b6815a49be7adde6a7.js:4 o.runvendor-203bc1bf399e89b6815a49be7adde6a7.js:8 uvendor-203bc1bf399e89b6815a49be7adde6a7.js:16 a.erro
@waterlink
waterlink / example.rb
Created Apr 12, 2015
Override default raise behavior
View example.rb
class MyStandardError < StandardError; end
module Kernel
alias_method :__raise__, :raise
def raise(*args)
return __raise__(MyStandardError) if args.empty?
__raise__(*args)
end
end
@waterlink
waterlink / log.txt
Created Apr 12, 2015
crystal docs error
View log.txt
➜ crystal git:(add_be_including_expectation) ✗ make doc
./bin/crystal doc docs/main.cr
Using compiled compiler at .build/crystal
Nil assertion failed
*Exception#initialize<Exception, String, Nil>:Array(String) +21 [61463232]
*Exception::new<String>:Exception +125 [61463232]
*raise<String>:NoReturn +6 [61463232]
*Nil#!<Nil>:Bool +0 [61463232]
*Crystal::Doc::Generator#compute_repository<Crystal::Doc::Generator>:Array(String)? +534 [61463232]
*Crystal::Doc::Generator#initialize<Crystal::Doc::Generator, Crystal::Program, Array(String), String>:Array(String)? +131 [61463232]