Skip to content

Instantly share code, notes, and snippets.

View juliends's full-sized avatar

Julien Da Silva juliends

View GitHub Profile
@juliends
juliends / github.rb
Created October 21, 2017 10:16
user_from_githuv
require "open-uri"
require "json"
puts "What is your Github nickname ?"
print "> "
username = gets.chomp
url = "https://api.github.com/users/#{username}"
# calls the api
@juliends
juliends / scrapper.rb
Created July 11, 2017 16:22
imdb_scrapper
require 'open-uri' # Open an url
require 'nokogiri' # HTML ==> Nokogiri Document
url = "http://www.imdb.com/chart/top"
base_url = "http://www.imdb.com"
html_file = open(url)
html_doc = Nokogiri::HTML(html_file)
movies_doc = html_doc.search('.titleColumn a')
# Rubular regexp pour créer des groupes de matching
# Appeller la methode match afin de constituer les groupes
# branche afin de déterminer le genre
# Mois en lettres, hash => clé mois, valeur => mois en lettres
require"date"
SSN_FORMAT = /^(?<sexe>1|2)(?<year>\d{2})(?<month>\d{2})(?<state>\d{2})(\d{6})(?<key>\d{2})$/
DPT = {
@juliends
juliends / ssn.rb
Created April 17, 2017 17:04
Livecode_social_security_number
require "date"
REGEXP = /^(?<gender>[12])(?<year>\d{2})(?<month>\d{2})(?<zip>\d{2})(\d{6})(?<key>\d{2})/
DEPARTMENTS = {
"75" => "Paris",
"76" => "Seine Maritime"
}
def ssn_info(ssn)
# TODO "a man, born in March, 1986 in Paris."
@juliends
juliends / update_or_create_category.rb
Created February 6, 2017 11:16
Some refacto for new_catgory_integration
def update_or_create_expert_category(category_ids)
categories = Category.find(category_ids.reject {|x| x.empty?})
@expert.categories.each do |category|
unless categories.include? category
expert_category.destroy
end
unless @expert.categories.include? category
ExpertCategory.create(expert: @expert, category: category)
end