Skip to content

Instantly share code, notes, and snippets.

View Mikael-Lovqvist's full-sized avatar

Mikael Lövqvist Mikael-Lovqvist

View GitHub Profile
@Mikael-Lovqvist
Mikael-Lovqvist / Code128-Terminal.py
Created May 12, 2025 22:42
Example of using https://github.com/WhyNotHugo/python-barcode for terminals (tested on dark background with FedEx app)
import sys
from io import BytesIO
from barcode import Code128
from barcode.writer import BaseWriter
class TerminalWriter(BaseWriter):
def __init__(self, dark_background=True, padding=16, height=8):
blocks = ' ', '▐', '▌', '█'
@Mikael-Lovqvist
Mikael-Lovqvist / BeamMP.md
Last active May 4, 2025 15:07
Setting up BeamMP on Linux

Setting up BeamMP on Linux

Prerequisites

Steam settings

  • Set Launch Options in the Properties... for the game to

Garlic-Parsley Spicy Sauce Recipe

Ingredients

  • 1 large wedge of garlic
  • Tabasco sauce (to cover garlic)
  • White pepper (to taste)
  • Salt (to taste)
  • Frozen parsley (amount roughly equal to garlic)
  • Smoked bell pepper spice (generous amount)
@Mikael-Lovqvist
Mikael-Lovqvist / dstar_fnmatch.py
Created September 17, 2024 09:41
fnmatch translate function that support doublestar expressions
import re
def translate(pat, double_star=False):
"""Translate a shell PATTERN to a regular expression.
There is no way to quote meta-characters.
"""
STAR = object()
DOUBLE_STAR = object()
@Mikael-Lovqvist
Mikael-Lovqvist / minecrack-log-peek.py
Created September 19, 2023 08:44
Example script for opening large file
#Python script for having a peek in a large file
#Tested in python 3.11
#Script character encoding: utf-8 (this is mostly important for the current place_holder for unprintables which you can replace if needed)
#File to open
filename = '/srv/storage/Artifacts/Wiki Data Dumps/enwiktionary-20200220-pages-articles-multistream.xml'
#Start position
offset = 2 << 30 # 2 gigabytes in
@Mikael-Lovqvist
Mikael-Lovqvist / chatgpt-cat-hours.log
Created March 23, 2023 22:21
chatgpt.. I give up!
gpt-3.5-turbo> How many cat powers is there to one horse power?
I'm sorry, but cats and horses are two different animals and it's not possible to compare their powers in a one-to-one ratio. Additionally, there are different types of "cat powers" and "horse powers" that could make the comparison even more complex. Is there anything else you need help with?
gpt-3.5-turbo> It is mostly for fun though. Maybe one could compare the energy consumption of a typical horse to a typical house cat?
Sure, we could make a comparison based on energy consumption. However, it's important to keep in mind that energy consumption doesn't necessarily translate to "power." That being said, according to the US Department of Energy, an average house cat consumes about 100 kilowatt-hours (kWh) of electricity per year. In comparison, an average horse consumes about 11,000 kilowatt-hours (kWh) of energy per year. Therefore, we could say that it takes about 110 house cats to equal the energy consumption of one horse.
gpt-3.5
@Mikael-Lovqvist
Mikael-Lovqvist / secret_santa.py
Created December 14, 2022 16:30
Secret Santa matching script
import random
participants = '''
Curie
Einstein
Faraday
Maxwell
Newton
Tesla
@Mikael-Lovqvist
Mikael-Lovqvist / mvln.sh
Last active September 23, 2022 02:15
Move files to a target location and then symlink them back. If there is a lot of files and expansion would be too long for the command line you can use single quotes such as: mvln '*.json' /path/to/target
#!/bin/bash
#The file system may of course change during these operations but at least the stage test is likely to prevent a half run but not guaranteed
#Out of laziness we may not add flags here and instead make a python script for more advanced use
# https://stackoverflow.com/a/33271194/19961748
target=${@:$#}
files=${*%${!#}}
function stage_file {
@Mikael-Lovqvist
Mikael-Lovqvist / mount_qcow2.md
Created August 27, 2022 20:00 — forked from shamil/mount_qcow2.md
How to mount a qcow2 disk image

How to mount a qcow2 disk image

This is a quick guide to mounting a qcow2 disk images on your host server. This is useful to reset passwords, edit files, or recover something without the virtual machine running.

Step 1 - Enable NBD on the Host

modprobe nbd max_part=8
@Mikael-Lovqvist
Mikael-Lovqvist / dict_filter.py
Created June 1, 2022 08:59
A simple class for filtering mappings
class dict_filter:
def __init__(self, key=None, value=None, key_condition=None, value_condition=None):
self.key = key
self.value = value
self.key_condition = key_condition
self.value_condition = value_condition
def __call__(self, source):
K, V, KC, VC = self.key, self.value, self.key_condition, self.value_condition