Skip to content

Instantly share code, notes, and snippets.


Deivinson Tejeda deivinsontejeda

View GitHub Profile
View cachipulis.rb
#!/usr/bin/env ruby
param = ARGV.first
class Fixnum
def is_cachipulis?
length = self.to_s.length
digits = self.to_s.split('').map(&:to_i)
return false if digits.inject(&:+) != length
deivinsontejeda / rspec-syntax-cheat-sheet.rb
Created Sep 3, 2012 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
View rspec-syntax-cheat-sheet.rb
# RSpec 2.0 syntax Cheet Sheet by
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
deivinsontejeda / gist:3722320
Created Sep 14, 2012
Setting Subline Text Edit
View gist:3722320
"auto_complete_commit_on_tab": true,
"bold_folder_labels": true,
"color_scheme": "Packages/Color Scheme - Default/Blackboard.tmTheme",
"ensure_newline_at_eof_on_save": true,
View gist:3797604
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
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"
def y_intercept
mean(@ys) - (slope * mean(@xs))
View DSL_jruby
class TestDSL < Regexp
def initialize(&block)
instance_eval &block
def some_method(value)
puts "Output: #{value}"
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