Skip to content

Instantly share code, notes, and snippets.

View M0r13n's full-sized avatar
🦔

Leon Morten Richter M0r13n

🦔
View GitHub Profile
@M0r13n
M0r13n / doh
Last active April 15, 2024 10:35
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 / 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 / index.py
Last active February 1, 2024 10:13
llama_index local model
import torch
from llama_index.llms import HuggingFaceLLM
from llama_index.prompts import PromptTemplate
selected_model = 'mistralai/Mixtral-8x7B-Instruct-v0.1'
SYSTEM_PROMPT = """You are an AI assistant that answers questions in a friendly manner, based on the given source documents. Here are some rules you always follow:
- Generate human readable output, avoid creating output with gibberish text.
- Generate only the requested output, don't include any other language before or after the requested output.
- Never say thank you, that you are happy to help, that you are an AI agent, etc. Just answer directly.
@M0r13n
M0r13n / README.md
Last active January 30, 2024 19:35
Logging with Loguru in Flask

This is a simple example of how to use loguru in your flask application

Just create a new InterceptHandler and add it to your app. Different settings should be configured in your config file, so that it is easy to change settings.

Logging is then as easy as:

from loguru import logger

logger.info("I am logging from loguru!")

@M0r13n
M0r13n / aoc_day5.py
Created January 1, 2024 11:32
Python solution for Advent of Code 2023 (AOC) day 5 part 2 based on iterative transformation of ranges
import itertools
def row2int(row: str) -> list[int]:
return list(map(int, row.strip().split(' ')))
def rows2list(fd):
l = []
for row in fd:
@M0r13n
M0r13n / gil_demo.py
Created December 30, 2023 11:41
GIL demo for Python3 using hashcash as a computational challenge
"""An example demonstrating the limitations of the GIL (CPython). This example
increments a counter for a given challenge so that the first N bits of the SHA1
hash of the challenge are all zeros (0). The computational effort increases
exponentially with the number of bits required to be zero.
This demo illustrates that this task cannot be sped up by parallelizing the
computation."""
import base64
import hashlib
import threading
@M0r13n
M0r13n / hashcash.py
Last active December 30, 2023 11:28
Yet anonther Hascash implementation in modern Python 3
import base64
import datetime
import hashlib
import string
import random
YYMMDDhhmm = '%y%m%d%H%M'
YYMMDDhhmmss = '%y%m%d%H%M%S'
ASCII_LETTERS = string.ascii_letters
@M0r13n
M0r13n / render.html
Last active October 6, 2023 06:32
A sample Wtforms field for creating a list of tags with custom separators, e.g. "," or " ".
<form action="" method="POST" role="form" class="form">
{{ form.hidden_tag() }}
<!--Other fields-->
{{ wtf.form_field(form.tags, placeholder='audio, hardware, chip') }}
<button class="btn btn-success" type="submit">submit</button>
</form>
@M0r13n
M0r13n / missing_positive.py
Created August 12, 2023 09:43
Eif sein Problem
from typing import List
class Solution:
def firstMissingPositive(self, nums: List[int]) -> int:
return 0
if __name__ == '__main__':
assert Solution().firstMissingPositive([2,1,0]) == 3
@M0r13n
M0r13n / eval.py
Last active July 16, 2023 12:40
Read Sparx Enterprise Architect files (.qea) using SQLite and SQLAlchemy
"""
Requires sqlalchemy and sqlalchemy_mixins. Install via pip
"""
import pathlib
import typing
from sqlalchemy import ForeignKey, Text, create_engine, Column, Integer, String
from sqlalchemy.orm import create_session, relationship, declarative_base
from sqlalchemy_mixins import ReprMixin