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
#!/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 |
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
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com | |
# 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") |
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
{ | |
"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, | |
"file_exclude_patterns": | |
[ | |
".DS_Store", | |
".tags*", | |
"*.pyc", |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>name</key> | |
<string>Monokai</string> | |
<key>settings</key> | |
<array> | |
<dict> | |
<key>settings</key> |
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