Skip to content

Instantly share code, notes, and snippets.

@lbvf50mobile
lbvf50mobile / Rakefle
Created November 17, 2017 15:42
Get CSS from TEST branch
desc "Get test"
task :get_test do
sh "git fetch"
sh "git checkout test" # (0) This swithes current dir and brings problems.
sh "git pull"
end
task :get_web do
sh "git checkout test -- web"
sh "git reset HEAD web" # (1) Need to do this to avoid STAGE web dir.
@lbvf50mobile
lbvf50mobile / isomorph.rb
Created November 22, 2017 18:20
isomorph
# https://www.codewars.com/kata/reviews/5a1554137ef16335fc00366e/groups/5a15592839caeb68ca001184
def isomorph(a, b)
sa, sb = a.each_char.to_set, b.each_char.to_set
sa.size == sb.size && sa.size == a.each_char.zip(b.each_char).to_set.size
end
@lbvf50mobile
lbvf50mobile / trololosha.rb
Created November 23, 2017 08:45
Power of ruby
class Trolotron
def initialize(name)
@name = name
end
def is_troll?
true
end
def to_s
@lbvf50mobile
lbvf50mobile / prime.rb
Last active November 24, 2017 12:35
prime
# https://www.codewars.com/kata/stone-bridge-primes/train/ruby
def solve(x,y)
a = []
for itr in 0..2
p "iteration #{itr}"
i_fora = 2
for i in itr..itr+i_fora
a << calc(i,itr)
end
end
@lbvf50mobile
lbvf50mobile / prime.rb
Last active November 24, 2017 13:16
prime simple
# https://www.codewars.com/kata/stone-bridge-primes/train/ruby
require "prime"
def solve(x,y)
a = []
for m in 0..10
for n in 0..10
a << calc(m,n)
end
end
@lbvf50mobile
lbvf50mobile / bridge.rb
Created November 24, 2017 13:27
"Stone bridge primes" decision that shows that KATA is incorrect.
# https://www.codewars.com/kata/stone-bridge-primes/train/ruby
# this Decission past test but fails submit.
require "prime"
def solve(x,y)
@a ||= calc_all
@a.select{|e| e >= x and e < y }.size
end
@lbvf50mobile
lbvf50mobile / code.rb
Created November 26, 2017 10:12
Why Expected: "Baguette baguette baguette Encore!", instead got: "Baguette baguette baguette Encore!"
def i_speak_french(sentence)
p sentence
sentence.split(".").map{|i| send i}.join("")
end
def send s
s.gsub(/\b[[:alnum:]]+\b/,"baguette").gsub(/(^\s*)(\b[[:alnum:]]+\b)/,'\1Baguette') + " Encore!"
end
@lbvf50mobile
lbvf50mobile / aEXPLANATION.md
Last active November 29, 2017 08:50
Compare JS and RUBY

Compare JS and Ruby REEGEX

Example #1 /!+|\?+/g

RUBY s.scan(/!+|\?+/).inspect == JS s.match(/!+|\?+/g)

INPUT: "!!!??"

RUBY [\"!!!\", \"??\"] == JS [ '!!!', '??' ]

@lbvf50mobile
lbvf50mobile / the_helper.rb
Created December 9, 2017 17:01
seeking for problem
# https://stackoverflow.com/a/3236342/8574922
class Rand
set_trace_func proc { |event, file, line, id, binding, classname|
# only interested in events of type 'call' (Ruby method calls)
# see the docs for set_trace_func for other supported event types
puts "#{classname} #{id} called" if event == 'call'
}
end
@lbvf50mobile
lbvf50mobile / simple.rb
Created December 12, 2017 08:18
test what is more simple
# v1:
response = Namespace::Abstract::Service.new(
param1: val1,
param2: val2,
).perform
track_errors(response)
response
# v2:
Namespace::Abstract::Service.new(