Skip to content

Instantly share code, notes, and snippets.

View SebDeclercq's full-sized avatar

Sébastien Declercq SebDeclercq

View GitHub Profile
@SebDeclercq
SebDeclercq / dict2obj.py
Created June 6, 2018 11:17
Essai pour voir si c'est faisable pour CHBO
#!/usr/bin/env python3
class Struct(): pass
def toObject(dictionnaire):
object = Struct()
for nom, element in dictionnaire.items():
if isinstance(element, dict):
setattr(object, nom, toObject(element))
else:
setattr(object, nom, element)
@SebDeclercq
SebDeclercq / ex11.py
Created July 24, 2018 12:57
Exercice 11 PAIR LEARNING
#!/usr/bin/env python3
import random
class Carte():
couleurs = {'carreau': '♦', 'coeur': '♥', 'pique': '♠', 'trefle': '♣'}
noms = {"2" : 1, "3" : 2, "4" : 3, "5" : 4, "6" : 5, "7" : 6,
"8" : 7, "9" : 8, "10" : 9, "valet" : 10, "dame" : 11,
"roi" : 12, "as" : 13}
def __init__(self, nom, couleur):
@SebDeclercq
SebDeclercq / creeTocMarkDown.py
Last active August 28, 2018 09:14
Crée une table des matières sur base d'un fichier markdown
#!/usr/bin/env python3
import os
import re
entree = os.path.join('chemin', 'vers le', '.md')
sortie = os.path.join('chemin', 'vers le', '.toc.md')
with open(entree) as md, open(sortie, 'w') as out:
for ligne in md:
if ligne[0] == '#':
#!/usr/bin/env python3
"""
Brangelina
The task of combining first names of celebrities into
a short catchy name for media consumption turns out
to be surprisingly simple to automate. Start by counting
how many groups of consecutive vowels (aeiou) there are
inside the first name. For example, "brad" and "ben" have
#!/usr/bin/env python3
from typing import NoReturn, Dict, Any, Optional, List
import requests
import json
class QwantData:
def __init__(self, json_str: bytes, wished_data: str) -> NoReturn:
parsed_json: Dict = json.loads(json_str)
if wished_data == 'artist':
@SebDeclercq
SebDeclercq / OCP6.sql
Last active December 7, 2018 19:41
Script populating an OCP6 Database with fake data
-- ENTITIES
CREATE TABLE address (
id SERIAL PRIMARY KEY,
street_name TEXT NOT NULL,
home_number TEXT NOT NULL,
zip_code TEXT NOT NULL,
country TEXT
);
CREATE TABLE role (
id SERIAL PRIMARY KEY,
#!/usr/bin/env python3
import time
import pytest
from app.Simple import Simple
@pytest.fixture()
def var() -> None:
return Simple(azerty=1, uiop=2)
@SebDeclercq
SebDeclercq / Pipfile
Last active March 1, 2019 12:40
Django Pipenv Basic Config w/ Linters
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
mypy = "*"
flake8 = "*"
ipython = "*"
django-stubs = "*"
document.querySelector('form.save').addEventListener('submit', () => {
let data = FormData();
data.append('substitute', this.querySelector('input[name=substitute]'));
data.append('substituted', this.querySelector('input[name=substituted]'));
let xhr = new XmlHttpRequest();
xhr.open('POST', '{% url "favorite:save" %}');
xhr.addEventListener('load', () => {
const answer = JSON.parse(xhr.responseText);
if (xhr.status == 200) {
let status = answer.status;
#!/usr/bin/env python3
from typing import Callable
class Converter:
def __init__(self, lang: str = 'en') -> None:
self.lang: str = lang
if self.lang == 'fr':
self.part: str = 'vers'
elif self.lang == 'en':