Skip to content

Instantly share code, notes, and snippets.

View MawKKe's full-sized avatar

Markus H MawKKe

View GitHub Profile
@MawKKe
MawKKe / ffplay-generated-tone.ipynb
Last active October 15, 2024 16:55
Demo - Playback of generated audio stream with ffplay (ffmpeg) in real time
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@MawKKe
MawKKe / terminal-flow-ctrl-demo.py
Last active October 12, 2024 12:31
Terminal/Console flow control demo
"""
Terminal/Console flow control demo
Most terminals support ctrl+S/ctrl-Q for pausing and unpausing
writing to it, which can be useful in some situations.
However, note that the terminal pause does _not_ pause the whole process,
how terminal job control (ctrl-z) does. Instead, only the thread that
attempts to write to stdout will block, while other threads are free to
continue processing. Only way other threads would block is they, too,
@MawKKe
MawKKe / zip-dir.py
Last active August 14, 2024 18:06
zip-dir - A little CLI utility for creating a .zip from directory tree. Because the usability of "zip" command is pure ass.
#!/usr/bin/env python3
"""
Usage:
$ zip-dir -i path/to/directory -o myarchive.zip --level 0
or more verbosely:
$ zip-dir --input-dir path/to/directory --output-zip myarchive.zip --level 0
Install:
@MawKKe
MawKKe / 01-voronoi.py
Last active August 14, 2024 18:00
Voronoi diagram in terminal
import math
M = 80
points = [(10, 20), (40, 30), (40, 35), (65, 25), (55, 60), (20,60), (75,75)]
def dist(p1, p2):
dx = abs(p1[0] - p2[0])
dy = abs(p1[1] - p2[1])
return math.sqrt(dx*dx + dy*dy)
@MawKKe
MawKKe / nanobind-notes.md
Last active July 21, 2024 14:19
My notes and observations about python nanobind + scikit-build-core usage

My notes and observations about python nanobind + scikit-build-core usage

nanobind is a tool and a library for implementing native C/C++ extensions for python. You can implement such extensions in many ways, but nanobind makes life a bit more easier, especially if you write C++ and use CMake to build your native code.

nanobind recommends using the scikit-build-core as the build backend; it handles the heavy lifting of building stuff through CMake during python package build process. It even supports using Ninja. And as a cherry on top, it is able to download CMake and Ninja from pypi if they are not available locally.

@MawKKe
MawKKe / nullptr-shenanigans.c
Last active July 7, 2024 11:01
Got a segmentation fault due to null pointer dereferencing? No worry, just skip over it #yolo
// build and run with:
// $ gcc nullptr-shenanigans.c -Wall -Wextra -pedantic -std=c99 -O0 -o lol
// $ ./lol
// expected output:
// Got SIGSEGV at address: 0x0 (REG_RIP = 93937079497465)
// This should not print: p = (nil)?
// Allright then, we are done!
#define _GNU_SOURCE 1 /* To pick up REG_RIP */
@MawKKe
MawKKe / fix-telegram-stuck-draft-message.md
Last active May 7, 2024 19:21
Fix Telegram stuck draft message

Problem with Telegram and stuck Draft message

2024-05-06: I was using telegram to send a message in one of the group chats I'm in.

2024-05-07: I noticed that a copy of my sent message was left as draft in the same chat (which is indicated by a red Draft: prefix in the chat list). If I opened the chat group, the draft message would indeed be entered in the message preparation box.

However, I could not erase the draft message; if I tried, it would simply return in a few seconds. I tried several times.

I noticed I could erase parts of the draft or add more. All those changes would be reflected between my phone and laptop.

@MawKKe
MawKKe / float-indexing.py
Last active April 26, 2024 10:18
Are you tired of plain old integer-based indexing? Use floats instead!
"""
Are you tired of plain old integer-based indexing?
Use floats instead!
"""
# Author: Markus H (MawKKe) 2024-04 https://github.com/MawKKe
import math
import typing as t
@MawKKe
MawKKe / 2024-02-05-atoms.md
Last active February 5, 2024 21:28
Atoms? It was already like that when I found it...

Background

Most programming languages have basic types such as booleans, bytes, shorts, integers, floating point numbers, strings, lists, etc. If you squint your eyes a bit, you'll notice all of these are just a bunch of bytes with varying sizes and shapes.

Strings (arrays) are (possibly unbounded) sequence of bytes. Integers and floating point types are often represented as fixed number of bytes or bits. Booleans semantically means "one bit", but often are implemented as a single byte (for performance reasons).

Now, think how many different values or states can each of these represent. Well, obviously the answer if 2**(number of bits in the type), duh!

  • Strings (arrays) can encode billions, trillions, gazillions ... of different states.
  • Integers can represent quite many, but considerably less (~4 billion for 32 bits)
@MawKKe
MawKKe / cmake-cxx-mold-linking-howto.md
Last active February 4, 2025 19:11
How to try out the new "mold" linker with your CMake C/C++ project

How to try out the new mold linker with your CMake C/C++ project

Here is a quick how-to if you want to try out the new (supposedly fast) C/C++ linker https://github.com/rui314/mold

In this document I used Ubuntu-22.04 docker container with

  • GCC version 11.2.0
  • Clang version 14.0.0

1. Install mold :