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 frequencies(text) | |
result = {} | |
words = text.split(" ") | |
words.each do |word| | |
if result.key?(word) | |
result[word] +=1 | |
else | |
result[word] = 1 | |
end | |
end |
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 acronymizer(string) | |
words = string.split(" ") | |
words.map{ |word| word[0].upcase}.join | |
end | |
# p acronymizer("What the fuck") #=> "WTF" | |
# p acronymizer("save our soul") #=> "SOS" | |
# p acronymizer("read the f**** manual") #=> "RTFM" | |
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
Flore | |
Quittez, quittez vos troupeaux, | |
Venez, bergers, venez, bergères, | |
Accourez, accourez sous ces tendres ormeaux ; | |
Je viens vous annoncer des nouvelles bien chères | |
Et réjouir tous ces hameaux. | |
Quittez, quittez vos troupeaux, | |
Venez, bergers, venez, bergères, | |
Accourez, accourez sous ces tendres ormeaux. |
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 acronimize(sentence) | |
return "" unless sentence.is_a? String | |
trash = %w(de des) | |
# split sentence into array | |
words = sentence.split(" ") | |
words.select! do |word| | |
!trash.include?(word) |
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
# # on demande rien | |
# # affectation ddj dans une variable 'today' | |
# # affectation date du prochain noel dans 'xmas' | |
# # affiche xmas - today | |
# require 'date' | |
# today = Date.today | |
# xmas = Date.new(today.year, 12, 25) | |
# if today > xmas | |
# xmas = Date.new(today.year + 1, 12, 25) |
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 acronimize(sentence) | |
# return "" unless sentence.is_a? String | |
# acronyme = "" | |
# # split sentence into array | |
# words = sentence.split(" ") | |
# # for each item in my array, push 1st letter into result | |
# words.each do |word| | |
# acronyme = acronyme + word[0] | |
# end | |
# # upcase the stuff |
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 'date' | |
def days_until_xmas(now = Date.today) | |
xmas = Date.new(now.year, 12, 25) | |
days = (xmas - now).to_i | |
if days < 0 | |
xmas = Date.new(now.year + 1, 12, 25) | |
days = (xmas - now).to_i | |
end | |
return days |
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 'open-uri' | |
require 'nokogiri' | |
require 'json' | |
url = "http://www.sarenza.com/store/product/gender-luxe/list/view?gender=1&luxe=1&index=0&count=2000" | |
html_file = open(url).read | |
html_doc = Nokogiri::HTML(html_file) | |
scrap = [] |
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 'open-uri' | |
require 'nokogiri' | |
require 'csv' | |
ingredient = 'chocolate' | |
compter = 0 | |
array = [] | |
10.times do | |
puts "page #{compter}" | |
url = "http://www.letscookfrench.com/recipes/find-recipe.aspx?s=#{ingredient}&start=#{compter}" |
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 timer | |
# start_time = Time.now | |
# yield | |
# puts "Elapsed time: #{Time.now - start_time}s" | |
# end | |
# # def timer2 | |
# # start_time = Time.now | |
# # (1..8000000).to_a.each {|n|} | |
# # puts "Elapsed time: #{Time.now - start_time}s" |
NewerOlder