Skip to content

Instantly share code, notes, and snippets.

@hholst80
hholst80 / test.py
Last active October 5, 2024 17:44
async generator playground
import asyncio
from asyncio.exceptions import CancelledError
async def gen(nam="gen"):
for x in range(10):
r = range(10*x, 10*(x+1))
print(f"{nam} produced range: [{10*x},{10*(x+1)})")
yield r
await asyncio.sleep(1)
@hholst80
hholst80 / ulockmgr_server.patch
Last active September 28, 2024 16:04
fuse-2.9.9 glibc patch
--- a/util/ulockmgr_server.c 2024-09-28 17:50:36.929276265 +0200
+++ b/util/ulockmgr_server.c 2024-09-28 17:51:12.812268734 +0200
@@ -124,24 +124,6 @@
return res;
}
-static int closefrom(int minfd)
-{
- DIR *dir = opendir("/proc/self/fd");
- if (dir) {
module main
/*
In-memory blob service.
PUT /path/to/file save a blob under the given path
will overwrite any previously stored blob
GET /path/to/file load a blob from the given path
import os
#include <unistd.h> // Necessary for the C.isatty function
fn main() {
// Define ANSI color codes
// mut ansi_codes := map[string]string
mut ansi_codes := {
'reset': '\x1b[0m'
'red': '\x1b[31m'
const std = @import("std");
pub fn main() !void {
// const allocator = std.heap.page_allocator;
const listen_address = try std.net.Address.parseIp4("127.0.0.1", 1337);
var socket = std.net.StreamServer.init(.{});
defer socket.deinit();
// Start listening for connections
@hholst80
hholst80 / diag.v
Last active December 24, 2023 00:59
import strconv
import math { max, min }
// m-by-n matrix of float 64
// assume C storage (row-major)
pub fn diag(m i64, n i64, lda i64, mut arr []f64, k i64) {
// zero the matrix; potentially faster with vmemset if lda=n
assert lda >= n
zero := i64(0)
for i := zero; i < m; i++ {
@hholst80
hholst80 / README.md
Created May 18, 2023 09:09
ChatGPT learned from the finest security cargo cults

Question 1: In Wayland Sway, how do I handle the bootup to login process?

Response 1: Sway is a window manager, not a display manager, and so doesn't handle the login process directly. You can start Sway directly from the console by typing sway, or automate this process by adding the start command to your shell's profile file. Alternatively, you can use a display manager that supports Wayland, such as GDM, SDDM, or Ly, which can be installed and enabled to start at boot using systemctl.


Question 2: Why would I like to use Void Linux?

Response 2: Void Linux is a rolling release, independent distribution. It uses runit as its init system, xbps as its package manager, and LibreSSL instead of OpenSSL. It offers glibc and musl libc variants, has a minimalist base install, supports non-free packages, and offers good documentation.

@hholst80
hholst80 / README.md
Created May 15, 2023 20:03
Cargo cult GTP

why should imports be top level and not in the function body where the functions are used?

ChatGTP 4

There are several reasons why it is typically recommended to place import statements at the top of your Python files:

  1. Readability and maintainability: Placing all imports at the top of the file makes it easy to see all of the file's dependencies in one place. This makes it easier to understand the context in which the code is running.

  2. Performance: Importing a module has some overhead. If you import it inside a function that's called many times, you'll pay that overhead each time the function is called. In contrast, if you import the module at the top level, the import happens just once, no matter how many times functions in the module are called. Note that Python is smart enough not to reload the entire module each time it's imported, but there's still some overhead to checking whether the module needs to be updated.

@hholst80
hholst80 / README.md
Last active August 14, 2022 10:33
crystal dreams 2 - see inside a cube effect

Crystal Dreams 2 - View the inside of a cube through a magic block

The effect

There is a rotating cube on the screen. There is also a magic block that enables us to view inside the Cube. The block is a plane with a thickness that always cuts through the center of the Cube. The two shapes rotates around a fixed center point during the entire effect (although the view frustum movies up and beyond). There are some of the usual pixel dust on screen as well, that interacts with the alpha channel but besides that nothing special. The focus of my analysis is of course on the magic block itself.

# This is how we usually do things.
FROM alpine:latest AS t1
RUN <<EOF
find /var/cache/apk
apk add --no-cache build-base
find /var/cache/apk
EOF
# This won't actually do anything. Cache needs to be enabled.