Skip to content

Instantly share code, notes, and snippets.

View M0r13n's full-sized avatar
🦔

Leon Morten Richter M0r13n

🦔
View GitHub Profile
@M0r13n
M0r13n / safe_eval.py
Created March 12, 2023 12:45
Safe evaluation of mathematical expressions in Python.
import ast
import operator as op
DEFINED_OPS = {
ast.Add: op.add,
ast.Sub: op.sub,
ast.Mult: op.mul,
ast.Div: op.truediv,
ast.USub: op.neg,
@M0r13n
M0r13n / csr.sh
Created February 11, 2023 14:37
Bash script to create a certificate signing request (CSR).
#!/usr/bin/env bash
set -e
# ------------------------------------------------------------------------------
# This script will generate a new private key and a Certificate Signing Request
# (CSR) using OpenSSL.
# This script is non-interactive. Instead it uses the variables set at the
# beginning of this script.
# ------------------------------------------------------------------------------
@M0r13n
M0r13n / README.md
Created October 22, 2022 12:16
Ansible playbook to download & install VS Code Server on a remote machine (without internet connection / offline)

Ansible playbook to download & install VS Code Server on a remote machine (without internet connection / offline)

By default VS Code installs its server component on a remote server automatically when using the SSH extension. This does not work when working in an air gapped environment or when working offline.

This playbook downloads the VS Code Server on a remote machine. It also extracts the tarball to the correct location. After running this playbook you can connect to the remote machine using the VS Code SSH extension.

How to run

@M0r13n
M0r13n / rsa.py
Created April 12, 2022 11:16
RSA implementation in native Python. This is only a toy implementation used to show how RSA works.
from collections import namedtuple
import typing
KeyPair = namedtuple('KeyPair', ['n', 'e', 'd'])
def inverse(x: int, y: int) -> int:
a, b, u = 0, y, 1
while x > 0:
q = b // x
@M0r13n
M0r13n / capsman.md
Last active April 10, 2022 13:52
Configure Mikrotik CAPsMAN with CHATEAU and Audience

Configure Mikrotik CAPsMAN with CHATEAU and Audience

I am assuming that your Chateau has loaded it's default config. If so:

  • bridge and lte interface are already configured correctly
  • also the DHCP server is already setup (192.168.88.2 - 192.168.88.254)
  • NAT is also already configured

Setup CAPsMAN

@M0r13n
M0r13n / doh
Last active August 25, 2025 17:22
Setup Cloudflare as a DoH (DNS over HTTPS) resolver on Mikrotik devices (RouterOS v7.0.2+)
# Temporarily add a normal upstream DNS resolver
/ip dns set servers=1.1.1.1,1.0.0.1
# CA certificates extracted from Mozilla
/tool fetch url=https://curl.se/ca/cacert.pem
# Import the downloaded ca-store (127 certificates)
/certificate import file-name=cacert.pem passphrase=""
# Set the DoH resolver to cloudflare
@M0r13n
M0r13n / main.py
Created May 17, 2021 10:47
Related mapping examle
#!/usr/bin/python
import json
from enum import Enum
import related
from attr import attrib
from related import to_model, TypedSequence
class Files(Enum):
@M0r13n
M0r13n / bar.py
Created December 7, 2020 08:31
A simple Progress Bar in Python without external dependencies.
"""
Dynamic Progressbar in Python without external dependencies
"""
import sys
import time
from typing import TextIO, Iterable
class ProgressBar(object):
"""
This is a simple context-manager that stores information about already written files on the file system.
The idea is to keep track of files that have already been written and that have not changed.
The benefit is, that we do not need to generate the code for things, that already exist and are up to date.
Because we do not know how the generated code would look like and what files are generated,
we can need to store such information in a separate file.
Basically we check for every generator, if it needs to be generated.
@M0r13n
M0r13n / wsl.md
Created October 21, 2020 09:10
Installation des Windows Subsystems (WSL) ohne den Microsoftstore. Nützlich in Enterprise Umgebungen.

WSL Installation

Das WSL kann ohne den MicrosoftStore installiert werden. Dazu müssen zwei Dinge geschehen. Zum einen muss in Windows die Unterstützung für das WSL aktiviert werden und anschließend muss das WSL installiert werden.

Vorraussetzungen

Die Anleitung richtet sich an die zweite Version (WSL-2) des Subsystems. Daher wird ein Windows 10 Version 1903 oder höher mit Build 18362 oder höher benötigt.

Aktivierung WSL

Bitte folge der offiziellen Anleitung bis ausschließlich Schritt 6:

Installation WSL