Skip to content

Instantly share code, notes, and snippets.

View AdrienHorgnies's full-sized avatar

Adrien Horgnies AdrienHorgnies

View GitHub Profile
@AdrienHorgnies
AdrienHorgnies / README.md
Last active April 12, 2019 23:40
a wrapper around argparse to handle configuration file

confargparse

Extends argparse.ArgumentParser to make it able to take in values from a configuration file.

Beyond the added functionality it doesn't not modify the behaviour of argparse.ArgumentParser and can thus be used as a drop in replacement.

Why

You may want to provide values either to the CLI or by configuration file. And you don't want to check yourself if each value not provided to the CLI is present in the configuration file. And you also don't want the CLI to shout an error because it hasn't been provided an option when it is present in the configuration file.

How

@AdrienHorgnies
AdrienHorgnies / magnets.py
Created March 8, 2019 01:57
find magnets and add them to transmission
import argparse
from selenium import webdriver
import time
from subprocess import run
def get_magnets(url):
browser = webdriver.Chrome()
browser.get(url)
@AdrienHorgnies
AdrienHorgnies / relink.py
Created March 26, 2019 13:42
Script to update symbolic links after republication (no longer used, here for posteriority)
@AdrienHorgnies
AdrienHorgnies / ds.py
Last active April 12, 2019 11:53
compute directory size recursively. Motivated by shell limitation of 1000 arguments.
#!/usr/bin/env python3
import argparse
import logging
import math
import os
from os.path import dirname
def main(directories):
measures = {}
@AdrienHorgnies
AdrienHorgnies / check_anagrams.py
Last active April 23, 2020 18:51
Interviews programming questions
def check(s1, s2):
return sorted(s1.lower()) == sorted(s2.lower())
@AdrienHorgnies
AdrienHorgnies / clear_snapshots.py
Last active May 3, 2019 10:37
get rid of directories which are not referenced by a symbolic link because they're useless in my use case
#!/usr/bin/env python3
import argparse
import logging
import os
import re
from datetime import datetime
from subprocess import call
from tempfile import mkdtemp
@AdrienHorgnies
AdrienHorgnies / metadata.py
Created November 20, 2019 14:17
base to build an etl music tagger
#!/usr/bin/env python3
import argparse
import re
from pathlib import Path
from subprocess import run
DEFAULT_PATTERN = re.compile(r'^(?P<track>\d+)---(?P<title>.+) - (?P<album>.+)---(?P<video_id>.+)\.opus$')
def extract_meta_from_path(full_path, pattern):
tentative_match = pattern.match(full_path.name)
; A set of scenario to record in training mode.
; place focus on button to start record then press shortcut for given scenario
F11::Suspend, Toggle
jump(direction)
{
if (direction = "left")
{
Send, {Left Down}
@AdrienHorgnies
AdrienHorgnies / DynamicCompilationTest.java
Last active May 11, 2020 17:37
A class to run dynamic tests
package be.unamur.info.b314.compiler.main;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
@AdrienHorgnies
AdrienHorgnies / README.md
Last active April 14, 2020 08:54
Playing with Iterable and Iterator

Java Iteration Design Pattern

Some classes to showcase Java Iteratable<T> and Iterator<E>

I've put everything in the same file by simplicity and declared inner classes static but I wouldn't recommend to do that in production code (separation of concerns).