Skip to content

Instantly share code, notes, and snippets.

@skull-squadron
skull-squadron / main.cpp
Created March 8, 2024 08:41
C++ specialization of stack adapter for forward_list
// Specialize stack to work with forward_list (STL singly-linked lists)
// Notes:
// - This is a proof-of-concept as an exercise for template specialization. Don't use in production!
// - Not cache-efficient.
// - Use stack<T, vector<T>> most of the time instead.
// Output
// ======
// t:
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
typedef uint64_t n;
n sqrt_n(n x) {
if (x <= 1) return x;
@skull-squadron
skull-squadron / PAGEDEMO.C
Created November 30, 2023 02:18
Mode X 320x400 256 color VGA mode
/* */
/* PAGEDEMO.C */
/* */
/* There is a nonstandard 320x400 256 color VGA mode which has two pages. */
/* This program demonstrates its use by setting up the mode, drawing to */
/* the two pages, and flipping the pages for instanteous appearance of */
/* of the graphics. */
/* */
/* A scanline function is included which shows how to take advantage of */
/* memory plane masking to draw four pixels simutaneously. */
@skull-squadron
skull-squadron / 0026-glibc-2.33.patch
Created November 28, 2023 23:22
checkinstall glibc 2.33+ fix
diff --git a/installwatch/installwatch.c b/installwatch/installwatch.c
index 15cb75c..77189dc 100644
--- a/installwatch/installwatch.c
+++ b/installwatch/installwatch.c
@@ -157,6 +157,20 @@ static int (*true_unlinkat)(int, const char *, int);
#define inline
#endif
+#ifndef _STAT_VER
+ #if defined (__aarch64__)
@skull-squadron
skull-squadron / README.md
Last active November 7, 2023 07:54
How to correctly use a hardware random number generator (hwrng, trng) on Linux 5+ (Debian 12+)

How to correctly use a hardware random number generator (hwrng, trng) on Linux 5+ (Debian 12+)

Problem

  1. Linux entropy pool doesn't know about external, non-default, non-driver entropy sources.
  2. Modern Linux usually reports 256 for cat /proc/sys/kernel/random/entropy_avail. This has to do with the entropy pool rewrite sometime ago that prevented blocking of /dev/random.
  3. There is presently no userland entropy pool seeding "pull" mechanism.

Solution

@skull-squadron
skull-squadron / dhparam.pem
Created May 22, 2023 18:34
8192-bit group 5 dhparam.pem, such as for use with DH TLS
-----BEGIN DH PARAMETERS-----
MIIECAKCBAEAjC/0pr9r1mcAiODdJ2hXfokDUPHamlfsA3vuTRTWjX4eewu5Xxj5
tuWy8YiA3Hyijud91jI6PpaDnsw7Y1v/0o4lMQyYeFGr6sYrSbD8KqfFbuggge4A
1X7dA4fXGd5pHwFvId5EJx0Niky50qsG5hImbqSkkXTDv1MCu3YKPnU1MaTk+ALO
mnjQ7sLLsSwgl0Jl9RuM22i556PyQLRNDqkkcu4JEtBL3r9TADA1QQ+86CrlsekT
AFRfu2gaOA5lx2kms8hD25PrnDN6wdme8l9aeWfVkIDwj6bwJ82cVBQ201TAQZLn
MCpXbMicY+xJqWyq0GhLnRxK/G76Qu1sBKuiKuB1TZ0D+qmSwlpqt0IUkk7LWF7N
DjGdzll0s4QFtJfMGF1CAGoySe7en21CiUKbW0N40ObK88KWEHXYq5EWeqvdL1/2
Sh7VuNnvJwMVIf7j7sRzJehy3xxOujMHVUHjfNUdUoMMZVYtHXMX+UO/bG9kuiJc
+ShFwhswOkQPmTvP/brvfC6SFXWnrJOa9O7MWVB6DH+K9FclDEZqgowVP4ZFsO4g
@skull-squadron
skull-squadron / megamaid.cr
Created May 22, 2023 06:06
1 M fibers running in Crystal
NUM_FIBERS = 1_000_000 # no. of Fibers
UPDATE_INTERVAL = 10_000 # show starting progress every these many fibers
PRINTERS = 100 # at most these no. of fibers will print dots
PRINT_INTERVAL = 10 # every increments of x
PRINT_NTH_FIBER = NUM_FIBERS//PRINTERS
MINI_NAP = Time::Span.new(nanoseconds: 1_000_000)
GC_STATS_PERIOD = Time::Span.new(seconds: 10)
start = Time.utc
@skull-squadron
skull-squadron / captive-portal-detection-and-internet-presence.md
Created May 16, 2023 20:30
Captive portal detection and internet presence URLs by vendor
@skull-squadron
skull-squadron / gpgme.patch
Created April 21, 2023 01:32
gpgme for Mailvelope
diff --git a/Formula/gpgme.rb b/Formula/gpgme.rb
index 45abd0b45ca..cbb56d52864 100644
--- a/Formula/gpgme.rb
+++ b/Formula/gpgme.rb
@@ -49,6 +49,7 @@ class Gpgme < Formula
"\\0 --install-lib=#{site_packages}"
system "./configure", *std_configure_args,
+ "--enable-fixed-path=#{Formula["gnupg"].opt_bin}",
"--disable-silent-rules",
@skull-squadron
skull-squadron / list.md
Created April 18, 2023 21:40
Way more than awesome OS development references

I would learn C and x86/arm assembly first enough to bootstrap.

It's usually good to learn how to write ld linker scripts and how to make something bootable from grub.

Then, I would look Rust because it's easier to create correct no_std kernels.

https://os.phil-opp.com/

arm architecture and instruction (ISA) reference