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
def quick_sort(array): | |
value = random.choice(array) | |
l = [] | |
r = [] | |
c = [] | |
for i in array: | |
if i < value: | |
l.append(i) | |
elif i > value: | |
r.append(i) |
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
def misterio(array) | |
value = array.sample | |
l,r,c = array.select{|e| e < value}, array.select{|e| e > value}, [] | |
l = misterio(l) if l.size > 1 | |
r = misterio(r) if r.size > 1 | |
c << value | |
(l + c + r).compact | |
end | |
def misterio_a(array) |
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 FooCollectionPresenter < SimpleDelegator | |
include Enumerable | |
def iterate_with_index | |
self.each_with_index do |foo, index| | |
yield(FooPresenter.new(foo), index) | |
end | |
end | |
def iterate | |
self.map do |foo| |
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
-gem mongo_kerberos-example | |
ruby data types (18) ruby core objects | |
t_nil | |
t_object | |
t_class | |
t_string -> RString(c data type) <- RSTRING(functions) | |
t_array -> RArrray <- RARRAY | |
t_false | |
t_symbol |
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
Regexp.new('\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})(\z|\s<\w+(?:>\z|\s\w+>\z))', true) |~ | |
Regexp.new('(?:\A|,{1})(?:<{0,1})([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})(?:>{0,1})', true) |~ | |
Regexp.new('(?:\s<|w+\s)([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})(?:>|,{0,1}\z)', true) |~ | |
Regexp.new('(?:^([^<@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})|^(?:\w+\s)+<{1}([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})(?:>{1}$))', true) | |
Regexp.new('(?:^([^<@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z|^(?:\w+\s)+<{1}([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})(?:>{1}$))', 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
def self.fib(quantity) | |
start = [0,1] | |
quantity.times do | |
two_numbers = start.last(2) | |
start << two_numbers.inject{|sum, n| sum +n} | |
end | |
start | |
end | |
def self.fibonacci(quantity) |
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
(ActiveRecord::Base.send :subclasses).inject(0) do |sum, m| | |
begin | |
sum + m.all.size | |
rescue ActiveRecord::StatementInvalid | |
"no existe" | |
end | |
end | |
ActiveRecord::Base.each_model_class.inject .. add each model class method to active record module on base class |
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
<ol> | |
<li><p class="P13" style="margin-left:0cm;"><span style="display:block;float:left;min-width:0.635cm;">1.</span>Probando listas numeradas<span class="odfLiEnd"/> </p> | |
</li> | |
<li><p class="P1" style="margin-left:0cm;"><span style="display:block;float:left;min-width:0.635cm;">2.</span>con 3 elementos<span class="odfLiEnd"/> </p></li> | |
<li><p class="P1" style="margin-left:0cm;"><span style="display:block;float:left;min-width:0.635cm;">3.</span>ultimo<span class="odfLiEnd"/> </p></li> | |
</ol> | |
<p class="Standard"> </p> | |
<ul> | |
<li><p class="P2" style="margin-left:0cm;"><span class="ListLabel_20_1" style="display:block;float:left;min-width:0.635cm;"></span>Probando listas con bullets<span class="odfLiEnd"/> </p> |
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
First version 3 loops / every one populate one column | |
r = Peasant.new(1233, 3000) | |
r2 = Peasant.new(1344718,9539271) | |
r3 = Peasant.new(2345642233123, 1234567890987) | |
Benchmark.bm do |x| | |
x.report("4dig: "){ r.multiply } | |
x.report("7dig: "){ r2.multiply } | |
x.report("13dig: ") {r3.multiply} |
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
def anagram(first_word, second_word) | |
anagrams = [] | |
first_word.each_with_index do |element, index| | |
anagrams << {"#{element.downcase}" => "#{second_word[index].downcase}" } if element.downcase.sum == second_word[index].downcase.sum | |
end | |
anagrams | |
end |
NewerOlder