Skip to content

Instantly share code, notes, and snippets.

View michaelortmann's full-sized avatar

Michael Ortmann michaelortmann

View GitHub Profile
@michaelortmann
michaelortmann / pefero.py
Last active October 31, 2025 14:46
pefero eggdrop telnet client - screenshot: https://imgur.com/a/JTRTRkS - looking for someone to take over maintainership of this quick hack and turn it into a proper application
#!/usr/bin/python
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Michael Ortmann
# We use ruff as a code formatter to keep the code style consistent (and to
# avoid off-topic discussions)
import hashlib
import socket
import ssl
import sys
import tkinter as tk
@michaelortmann
michaelortmann / check_version.py
Last active October 30, 2025 10:57
Eggdrop version check python script using only python core modules
# SPDX-License-Identifier: MIT
# Copyright (c) 2025 Michael Ortmann
# We use ruff as a code formatter to keep the code style consistent (and to
# avoid off-topic discussions)
import eggdrop
from eggdrop.tcl import putlog
import json
import threading
import urllib.request
@michaelortmann
michaelortmann / comptime.base64.decode.zig
Last active March 21, 2025 17:08
Compile time base64 decode in Zig - isn't that nice?
// tested with zig 0.14.0
const std = @import("std");
test "comptime base64 decode" {
const decoded = comptime blk: {
const encoded = "Y29tcHRpbWUgdmliZQ=="; // base64 encoded "comptime vibe"
const len = std.base64.standard.Decoder.calcSizeForSlice(encoded) catch unreachable;
var buf: [len]u8 = undefined;
std.base64.standard.Decoder.decode(&buf, encoded) catch unreachable;
// SPDX-License-Identifier: MIT
// Copyright (c) 2024 Michael Ortmann
// Get user home directory without libc getpwuid()
// Fallback if environment variable HOME (std.posix.getenv("HOME")) aint set
// Get user id and parse /etc/passwd
// std.process.posixGetUserInfo() only returns uid and gid
// There is no std.posix.getuid(), so the following code is linux only
var password_store_dir: []const u8 = undefined;
@michaelortmann
michaelortmann / phi.zig
Last active October 9, 2024 00:59
Calculate phi / golden ratio / std.math.phi with 64 digits
// SPDX-License-Identifier: MIT
// Copyright (c) 2024 Michael Ortmann
// $ zig test phi.zig
// All 1 tests passed.
const std = @import("std");
// Calculate phi / golden ratio / std.math.phi with 64 digits
// https://en.wikipedia.org/wiki/Golden_ratio
// phi = sqrt(1.25) + 0.5
@michaelortmann
michaelortmann / zig.std.mem.sort.cmp.md
Last active February 23, 2025 03:39
std.mem.sort cmp performance in Zig

Inside cmp() the following code:

return std.mem.order(u8, word1, word2).compare(std.math.CompareOperator.lt);

is much faster than the following 2 alternatives (that will be compiled to the same machine code):

return std.mem.order(u8, word1, word2) == .lt;

return std.mem.lessThan(u8, word1, word2);

@michaelortmann
michaelortmann / zig.alias.simd.vector.md
Last active September 30, 2024 16:55
A little reminder to use noalias with Zig

A little reminder to use noalias with Zig

Converting an array from one type to another is a common and good example for using fast SIMD code. But for the compiler to optimize, it must know that the 2 arrays dont alias. The following example converts an array of int16 to float32.

C compiler clang defaults to strict aliasing and creates optimized SIMD code:

https://godbolt.org/z/b7EfTW5KM

Zig, since version 0.4.0, no longer plans to have Type Based Alias Analysis, see https://ziglang.org/download/0.4.0/release-notes.html#Type-Based-Alias-Analysis-Status