This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# delay the GC - usage as below | |
# Spec::Runner.configure do |config| | |
..... | |
# config.before(:each) do | |
# begin_gc_deferment | |
# end | |
# config.after(:each) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
class JsonFormatter | |
METHODS = %w[start close stop start_dump dump_pending dump_failures dump_summary] | |
METHODS.each { |m| define_method(m) { |*a| } } | |
def initialize(out) | |
@output = out | |
@event_id = 0 | |
@passed = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SimpleLinearRegression | |
def initialize(xs, ys) | |
@xs, @ys = xs, ys | |
if @xs.length != @ys.length | |
raise "Unbalanced data. xs need to be same length as ys" | |
end | |
end | |
def y_intercept | |
mean(@ys) - (slope * mean(@xs)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestDSL < Regexp | |
def initialize(&block) | |
instance_eval &block | |
super('/some_regex/') | |
end | |
def some_method(value) | |
puts "Output: #{value}" | |
end | |
end |
Constatize a string without ActiveSupport (commonly come by default in rails) isn't friendly and in some case include AS is overkill. So, with this snipe you can constatize a String.
require 'net/http'
cls = "Net::HTTP".split('::').inject(Object) { |host,name| memo.const_get(name) }
# now you can use cls like normal constant
cls.new
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
:verbose: false | |
install: --no-document --env-shebang | |
:sources: | |
- https://rubygems.org | |
:benchmark: false | |
:backtrace: false | |
update: --no-document --env-shebang | |
:update_sources: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'irb/completion' | |
ARGV.concat [ "--readline", "--prompt-mode", "simple" ] | |
IRB.conf[:EVAL_HISTORY] = 1000 | |
IRB.conf[:SAVE_HISTORY] = 1000 | |
IRB.conf[:HISTORY_FILE] = File::expand_path("~/.irbhistory") | |
#begin | |
# require 'pry' | |
# Pry.start | |
#rescue LoadError | |
# puts "you need run 'gem install pry'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
const ( | |
GOROTUNIES = 2 | |
) |