Skip to content

Instantly share code, notes, and snippets.

View fractalatcarf's full-sized avatar

Vincent fractalatcarf

View GitHub Profile
def frequencies(text)
result = {}
words = text.split(" ")
words.each do |word|
if result.key?(word)
result[word] +=1
else
result[word] = 1
end
end
@fractalatcarf
fractalatcarf / acronymizer.rb
Created April 18, 2019 18:41
live code de ce soir
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"
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.
@fractalatcarf
fractalatcarf / acronimizer.rb
Created July 13, 2018 05:59
acronymizer enhanced
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)
@fractalatcarf
fractalatcarf / livecode.rb
Created July 11, 2018 16:30
yesterday's live code
# # 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)
@fractalatcarf
fractalatcarf / acronimizer.rb
Created July 11, 2018 16:29
this evening's Live code
# 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
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
@fractalatcarf
fractalatcarf / sarenza.rb
Created January 16, 2018 16:46
sarenza live code
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 = []
@fractalatcarf
fractalatcarf / scrapp.rb
Created January 16, 2018 10:52
lecture du cours de scrapping
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}"
@fractalatcarf
fractalatcarf / block.rb
Created January 11, 2018 10:18
morning code
# 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"