This file contains hidden or 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
slip() { | |
sleep 1 | |
} | |
rm -rf contents | |
mkdir contents | |
cd contents | |
git init |
This file contains hidden or 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 Fixnum | |
def to_roman | |
[].tap do |res| | |
a, b = self.divmod(10) ; res << ([''] + %w(I II III IV V VI VII VIII IX))[b] | |
a, b = a.divmod(10) ; res << ([''] + %w(X XX XXX XL L LX LXX LXXX XC))[b] | |
a, b = a.divmod(10) ; res << ([''] + %w(C CC CCC CD D DC DCC DCCC CM))[b] | |
a, b = a.divmod(10) ; res << ([''] + %w(M MM MMM Mv v vM vMM vMMM Mx))[b] | |
a, b = a.divmod(10) ; res << ([''] + %w(x xx xxx xl l lx lxx lxxx xc))[b] | |
a, b = a.divmod(10) ; res << ([''] + %w(c cc ccc cd d dc dcc dccc cm))[b] | |
end.reverse.join |
This file contains hidden or 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
# what: a Regexp-based parser. alainravet - 2016 jan | |
SYNTAX_RULES = { | |
/^PRINT\b/ => { | |
/^PRINT\s*\z/ => :new_line_command, | |
/^PRINT (.*)/ => :print_command, | |
}, | |
/HELP/i => :help_command, | |
} |
This file contains hidden or 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 Hash | |
def diff(other) | |
(self.keys + other.keys).uniq.inject({}) do |memo, key| | |
unless self[key] == other[key] | |
if self[key].kind_of?(Hash) && other[key].kind_of?(Hash) | |
memo[key] = self[key].diff(other[key]) | |
else | |
memo[key] = [self[key], other[key]] | |
end | |
end |
This file contains hidden or 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
def RPN(*data) | |
stack = [] | |
data.each do |el| | |
case el | |
when :+, :-, :*, :/, :&, :|, :<< # 1,2,3,:*,:+ == 1 + 2 $ 3 | |
a, b = stack.pop(2) | |
stack.push a.send(el.to_sym, b) | |
when Class # 3,Float == Float(3) | |
stack.push send(el.name, stack.pop) | |
when Symbol # '1+2',:eval == eval('1+2') |
This file contains hidden or 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
#---------------------- | |
# Library code: | |
class BasicServiceObject | |
attr_reader :object | |
def initialize(o) | |
@object = o | |
end | |
end |
This file contains hidden or 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 'active_record' | |
require 'database_cleaner' | |
connection_info = YAML.load_file("config/database.yml")["test"] | |
ActiveRecord::Base.establish_connection(connection_info) | |
RSpec.configure do |config| | |
config.before(:suite) do | |
DatabaseCleaner.strategy = :transaction | |
DatabaseCleaner.clean_with(:truncation) |
This file contains hidden or 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
module DefaultValues | |
def has_default_values(default_values = {}) | |
cattr_accessor :default_values | |
self.default_values = default_values | |
after_initialize :assign_default_values | |
include InstanceMethods |
This file contains hidden or 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
# TODO : | |
# 1 : return the attributes that are missing | |
# 2 : in views, also test presence of documents | |
# | |
require_relative 'completeness_measure' | |
require 'minitest/spec' | |
require 'minitest/autorun' | |
describe CompletenessMeasure do |
This file contains hidden or 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
# Usage : | |
# EnvVarsChecker.new do | |
# env_includes 'USER' | |
# env_includes 'USER', in: -> { `echo $USER`.chomp} | |
# env_includes 'USER', in: %w(deployer deploy rails) | |
# end | |
class EnvVarsChecker | |
class Error < RuntimeError ; end | |
NewerOlder