Skip to content

Instantly share code, notes, and snippets.

View dkgndianko's full-sized avatar

Mouhamad Ndiankho THIAM dkgndianko

View GitHub Profile
@dkgndianko
dkgndianko / gist:015494a165c9166ad95083e02b933e89
Created August 24, 2019 10:44 — forked from lonnen/gist:3101795
git grep and git blame. two great tastes that taste great together
# from i8ramin - http://getintothis.com/blog/2012/04/02/git-grep-and-blame-bash-function/
# runs git grep on a pattern, and then uses git blame to who did it
ggb() {
git grep -n $1 | while IFS=: read i j k; do git blame -L $j,$j $i | cat; done
}
# small modification for git egrep bash
geb() {
git grep -E -n $1 | while IFS=: read i j k; do git blame -L $j,$j $i | cat; done
}
@dkgndianko
dkgndianko / sub_element_list_updater.py
Created October 24, 2019 18:17
This is a method for updating a list of elements.
def updator(initial_list: Set[T], new_list: Set[T], creator: Callable[T, U], getter: Callable[T, U], deleter: Callable[T]) -> List[U]:
result = []
for e in new_list:
element = getter(e)
if not element:
element = creator(e)
result.append(element)
to_delete = initial_list.difference(new_list)
for e in to_delete:
deleter(e)
@dkgndianko
dkgndianko / repository_method_generator.py
Created October 28, 2019 11:46
Dynamically generate getter methods for a repository based on the name of fields
from typing import List, Callable, Iterator, Tuple
LOGICAL_SEPARATORS = ["and", "or"]
OPERATORS = ["lt", "gt", "not", "in", "none"]
OPERATORS_MAPPING = {"=": "=", "lt": "<", "gt": ">", "lte": "<=", "gte": ">=", "not": "!=", "none": "is None",
"is": "is"}
def _generate_method(method_name: str) -> Callable:
zip_iterator = _process_getter(method_name.split("_"))
@dkgndianko
dkgndianko / repository_method_generator.py
Last active October 28, 2019 12:01
Dynamically generate getter methods for a repository based on the name of fields
from typing import List, Callable, Iterator, Tuple
LOGICAL_SEPARATORS = ["and", "or"]
OPERATORS = ["lt", "gt", "not", "in", "none"]
OPERATORS_MAPPING = {"=": "=", "lt": "<", "gt": ">", "lte": "<=", "gte": ">=", "not": "!=", "none": "is None",
"is": "is"}
# TODO: Add docstrings
# After first generation, add method to the repository class for further calling.
def _generate_method(method_name: str) -> Callable:
@dkgndianko
dkgndianko / pagination_type_generator.py
Last active December 19, 2019 13:47
A type for pydantic paginated elements in response
from pydantic import BaseModel
class _Pagination:
def __init__(self):
self.cache = []
def __getitem__(self, klass):
target_class = None
key = str(klass)
try:
target_class = self.cache[key]
@dkgndianko
dkgndianko / docker_tips.md
Last active September 30, 2020 10:39
Tips about docker

1. Install Docker on Debian

To install Docker Engine, visit here

sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
@dkgndianko
dkgndianko / asw_ecr_config.md
Last active September 30, 2020 15:10
Confiure AWS Elastic Container Registry
  1. Install AWS CLI if not. On Debian you can use:
sudo apt install awscli
pip install awscli
  1. Configure AWS. For that you will need secret key and access key.
aws configure
@dkgndianko
dkgndianko / ntp_on_debian.md
Created September 30, 2020 15:15
Configure system to automatically set date and time by using NTP server
  1. Install needed NTP packages
sudo apt install ntp
sudo apt install ntpdate
  1. Configure the NTP server to follow
sudo ntpdate pool.ntp.org
@dkgndianko
dkgndianko / deb_to_rpm.md
Created October 5, 2020 16:37
Build .rpm package from .deb

I recently moved from Debian-basd distributions to RHEEL world. I'm actually using Fedora. At some point, I wanted to install frantz. But I only have two possibilities: .deb and .AppImage and I choosed the .deb. After downloading the .deb file, I use alien to transform it to .rpm.

  1. Install alien (if not)
sudo dnf install alien
  1. transform .deb to .rpm
@dkgndianko
dkgndianko / openvpn_cli.md
Last active October 22, 2020 12:22
Connect to VPN with openvpn

situation

When trying to connect to a VPN via command. And you receive config files like .ovpn client .crt and .key or .p12.

Procedure

  1. First gather config files in a same directory. For this tuto, we assume that every config file is in the directory ~/Config/VPN/myVPN.
  2. Install openvpn package from official repositories.

on Ubuntu

sudo apt-get install openvpn