Skip to content

Instantly share code, notes, and snippets.

View M0r13n's full-sized avatar
🦔

Leon Morten Richter M0r13n

🦔
View GitHub Profile
@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 / 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 / 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
@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