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
| #!/usr/bin/env bash | |
| set -eu | |
| # Helper script for controlling laptop screen brightness WITHOUT sudo/root privileges. | |
| # | |
| # Tested on Lenovo Thinkpad x240 running Ubuntu 18.04. | |
| # | |
| # Author: Markus H (MawKKe) [email protected] |
| #!/usr/bin/env sh | |
| # A utility/wrapper script for launching go (golang) help topics | |
| # Author: Markus H (MawKKe) <[email protected]> | |
| # What is this? | |
| # ------------- | |
| # It annoys me greatly that none of the go subcommands have a help switch (-h | |
| # or --help), requiring me to use "go help <subcommand>" instead. This is just |
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
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!
| """ | |
| 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 |
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.
| // 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 */ |
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.
| 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) |
| #!/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: |