Skip to content

Instantly share code, notes, and snippets.

View Abdelkrim's full-sized avatar

Abdelkrim from Brussels Abdelkrim

View GitHub Profile
@Abdelkrim
Abdelkrim / reverse_a_string.py
Created January 8, 2020 22:46
Python : Reverse a string
language = "python"
reversed_language = language[::-1]
print(reversed_language) # nohtyp
@Abdelkrim
Abdelkrim / time_taken_to_execute_code.py
Created January 8, 2020 22:48
Python : Calculate time taken to execute a piece of code
# Python : Calculate time taken to execute a piece of code
import time
start_time = time.time()
a,b = 5,10
c = a+b
end_time = time.time()
time_taken = (end_time- start_time)*(10**6)
print("Time taken in micro_seconds:", time_taken) # Time taken in micro_seconds: 39.577484130859375
@Abdelkrim
Abdelkrim / debugging_using_aspect_oriented_programming_aop.py
Last active January 29, 2020 00:16
debug methods like you would do it using Aspect Oriented Programming (AOP)
# python 3
def enter_exit_info(func):
def wrapper(*arg, **kw):
print(f'-- entering {func.__name__}')
res = func(*arg, **kw)
print(f'-- exiting {func.__name__}')
return res
return wrapper
@Abdelkrim
Abdelkrim / latex-styling.tex
Created February 15, 2020 15:59
sphinx, latex, resize figures that are too wide for the page and ensure they take the full width of the page
% Made by ALT-F1 SPRL, Abdelkrim Boujraf
%\usepackage{bookmark}
%\usepackage{charter}
%\usepackage[defaultsans]{lato}
%\usepackage{inconsolata}
% \usepackage{pbsi}
% \usepackage[T1]{fontenc}
@Abdelkrim
Abdelkrim / conf.py
Created February 15, 2020 16:01
sphinx, conf.py, generate nice looking PDF file and reading the PREAMBLE latex-styling.tex
# -- Options for LaTeX output ------------------------------------------------
f = open('latex-styling.tex', 'r+')
PREAMBLE = f.read()
latex_elements = {
# https://www.sphinx-doc.org/en/master/latex.html
# 'classoptions': ',openany,twoside',
'classoptions': ',openany',
# 'babel' : '\\usepackage[french]{babel}',
@Abdelkrim
Abdelkrim / .git_hooks_commit-msg
Created February 20, 2020 13:20
standard-version :
#!/bin/sh
# INSTALLATION
#
# COPY THE FILE commit-msg INTO .git/hooks/commit-msg
# COPY THE FILE package.json INTO THE ROOT OF YOUR PROJECT
# MODIFY THE FILE package.json TO MATCH PROJECT DESCRIPTION
# RUN npm install to install standard-version locally
# CODE, COMMIT YOUR CODE
# RUN 'npm run patch', 'npm run minor' or 'npm run major' TO GENERATE THE VERSION NUMBER and THE CHANGELOG FILE
@Abdelkrim
Abdelkrim / standard-version_package.json
Last active February 20, 2020 13:24
standard-version : add the package.json configuration including the scripts to manage the semver of your project AND generate the CHANGELOG
{
"name": "altf1bemanagesemver",
"description": "ALT-F1 SPRL: Empty package.json including the management of the semver",
"authors": "Abdelkrim Boujraf, ALT-F1 SPRL",
"version": "1.0.1",
"main": "build/html/index.html",
"scripts": {
"release": "standard-version",
"patch": "npm run release -- --release-as patch",
"minor": "npm run release -- --release-as minor",
@Abdelkrim
Abdelkrim / LICENSE
Created February 20, 2020 13:25
ALT-F1.BE : template for a closed licensing of the software
Copyright (c) 2010-2020 Abdelkrim Boujraf ([email protected]), ALT-F1 SPRL
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
@Abdelkrim
Abdelkrim / conf.py
Last active April 26, 2020 17:23
Sphinx: Read The Docs: git-lfs support. Add this piece of code at the beginning of the conf.py to support resources stored in git-lfs in readthedocs.org
# correct the issue : pdf generation fails after a 'libpng error: Not a PNG file'
# See https://github.com/readthedocs/readthedocs.org/issues/6770
# gist source: https://gist.github.com/Abdelkrim/c1d7005feccbcfa66b198151dc1c4abd
# -- manage git-lfs ----------------------------------------------------------
import os
if not os.path.exists('./git-lfs'):
os.system('wget https://github.com/git-lfs/git-lfs/releases/download/v2.7.1/git-lfs-linux-amd64-v2.7.1.tar.gz')
@Abdelkrim
Abdelkrim / requirements.txt
Created April 26, 2020 17:17
Sphinx: required libraries
# store the file in the root of your sphinx repository
unidecode
Sphinx
sphinx-rtd-theme
sphinxcontrib-plantuml
# Docs
sphinxcontrib-httpdomain==1.4.0
# git lfs