Skip to content

Instantly share code, notes, and snippets.

View juliends's full-sized avatar

Julien Da Silva juliends

View GitHub Profile
@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
@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."
# 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 / 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')
@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 / ssn
Created October 23, 2017 16:50
ssn livecode
require "date"
REG = /^(?<gender>[12])(?<year>\d{2})(?<month>\d{2})(?<dept>\d{2})\d{6}(?<key>\d{2})/
DEPARTEMENT = {
"75" => "Paris",
"76" => "Seine Maritime"
}
def ssn_info(ssn)
# TODO => "a man, born in March, 1986 in Paris."
ssn = ssn.gsub(" ","")
result = ssn.match(REG)
@juliends
juliends / scrapper.rb
Created October 24, 2017 08:55
scrapper
require 'open-uri'
require 'nokogiri'
url = 'http://www.letscookfrench.com/recipes/find-recipe.aspx?aqt=chocolate'
html_file = open(url).read
html_doc = Nokogiri::HTML(html_file)
html_doc.search('.m_contenu_resultat').each do |element|
p element.search('.m_titre_resultat a').text
@juliends
juliends / scrapper_imdb.rb
Created October 24, 2017 17:22
scrapper_imdb
require 'open-uri' # Open an url
require 'nokogiri' # HTML ==> Nokogiri Document
url = "http://www.imdb.com/chart/top"
html = open(url).read
html_doc = Nokogiri::HTML(html)
html_doc.search('.titleColumn a').each do |element|
title = element.text
link = element.attribute('href')
@juliends
juliends / employees_repository.rb
Created November 2, 2017 18:23
employees_repo_with_db
require "sqlite3"
require_relative "../models/employee"
class EmployeesRepository
def initialize
@db = SQLite3::Database.new('food_delivery.db')
@db.results_as_hash = true
@employees = []
load_from_db
end
# we use the match method to extract the data from original string
# find the gender
# find the birth year
# find the birth month
# find the dept
# validate the number
require 'date'
DEPT = {
75 => "Paris",
76 => "Seine-Maritime"