Skip to content

Instantly share code, notes, and snippets.

Avatar

Deivinson Tejeda deivinsontejeda

View GitHub Profile
View rspec_optmization_2.rb
# delay the GC - usage as below
# Spec::Runner.configure do |config|
.....
# config.before(:each) do
# begin_gc_deferment
# end
# config.after(:each) do
View json_formatter.rb
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
View simple-linear-regression.rb
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))
View DSL_jruby
class TestDSL < Regexp
def initialize(&block)
instance_eval &block
super('/some_regex/')
end
def some_method(value)
puts "Output: #{value}"
end
end
@deivinsontejeda
deivinsontejeda / gist:6919226
Created Oct 10, 2013
Constantize without ActiveSupport
View gist:6919226

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

View gist:7721060
---
:verbose: false
install: --no-document --env-shebang
:sources:
- https://rubygems.org
:benchmark: false
:backtrace: false
update: --no-document --env-shebang
:update_sources: true
View gist:cdd4a27b6a0164a1f1af
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'"
View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
View gothreads.go
package main
import (
"fmt"
)
const (
GOROTUNIES = 2
)