Skip to content

Instantly share code, notes, and snippets.

@kajott
kajott / onebrc.cpp
Created January 5, 2024 13:00
1BRC in C++
#if 0 // self-compiling code: just 'chmod +x' this file and run it directly!
c++ -std=c++11 -Wall -Wextra -pedantic -Werror -g -O3 -march=native $0 || exit 1
exec ./a.out $*
#endif
// SPDX-FileCopyrightText: 2023 Martin J. Fiedler <keyj@emphy.de>
// SPDX-License-Identifier: MIT
// C++11 implementation for the One Billion Row Challenge
// (https://github.com/gunnarmorling/1brc)
@kajott
kajott / aoc2023_24_math.md
Last active December 26, 2023 10:24
vector math solution of the AoC 2023/24p2 problem

Mathematical Solution of the AoC 2023/24 Part 2 Problem

(originally provided by @chschu, converted to Markdown with LaTeX math by @kajott)

Variables used here:

  • $\overrightarrow{p_i}$ = initial position of hailstone number i [known]
  • $\overrightarrow{v_i}$ = velocity of hailstone number i [known]
  • $t_i$ = time of collision between the rock and hailstone number i [unknown]
  • $\overrightarrow{p_R}$ = initial position of the rock [unknown]
  • $\overrightarrow{v_R}$ = velocity of the rock [unknown]
@kajott
kajott / hellowin32_minimal.asm
Created April 12, 2021 22:36
minimal Win32 GUI application (648 bytes)
; Minimal Win32 application example, inspired by Dave Plummer:
; https://www.youtube.com/watch?v=b0zxIfJJLAY
; Based on initial reseach carried out here:
; https://keyj.emphy.de/win32-pe/
;
; (C) 2021 Martin J. Fiedler <keyj@emphy.de>
; Use at your own risk!
;
; Uses a few tricks to get there:
; - no linker, no sections -> minimal alignment
@kajott
kajott / clock.asm
Created December 6, 2020 16:25
clock screensaver for DOS
; clock screensaver in 670 bytes (DOS, 186+)
;
; features:
; - VGA mode 13h
; - 24-hour clock in pixellated LED clock style
; - animated screen position
; - smooth alpha-blended transition between seconds
; - fade-in on startup, fade-out on exit
; - smoothly changing colors
;
@kajott
kajott / runcalc.asm
Created April 3, 2020 07:17
minimal Win32 application that runs calc.exe (268 bytes)
; A simple Win32 application that runs the Windows calculator.
;
; This version constructs the whole EXE file "from scratch" in the
; assembler -- no linker needed.
; This is a sectionless executable with an "import by hash" loader
; in which as many stuff as possible has been collapsed (overlaid)
; into the headers. In addition, all cleanup code has been removed,
; it's assumed that kernel32.dll is the third loaded image in the
; PE loader's list, that the kernel32.dll image is actually valid,
; and that all required functions are available.
@kajott
kajott / ktxview.c
Last active September 28, 2024 13:01
simple OpenGL-based KTX texture file viewer
#if 0 // self-compiling code
cc -std=c99 -Wall -Wextra -pedantic -Werror -g -O4 $0 -o ktxview `sdl2-config --cflags --libs` -lGL -lm || exit 1
exec ./ktxview $*
#endif
// simple OpenGL-based KTX texture file viewer
//
// features:
// - simple, based on SDL2 and OpenGL Compatibility Profile
// - self-compiling on GNU/Linux and similar platforms
@kajott
kajott / win10repair.bat
Last active May 16, 2024 14:54
Windows 10/11 Setup Script
@echo off
@rem "This little script sets a few useful settings in Windows 10 that most"
@rem "serious users are likely to want; scroll through the script for details"
@rem "and disable sections you don't want."
@rem "Usage:"
@rem "Just save this file as a .bat or .cmd file and run it (with"
@rem "Administrator privileges!). You will need to re-run it after larger"
@rem "updates, as these tend to overwrite some of the settings or re-create"
@kajott
kajott / vaapi_egl_interop_example.c
Last active June 13, 2024 13:45
example code for minimal-overhead hardware-accelerated video decoding and display on Linux using VA-API/EGL interoperability
#if 0 // self-compiling code: chmod +x this file and run it like a script
BINARY=vaapi_egl_interop_example
gcc -std=c99 -Wall -Wextra -pedantic -Werror -g -fsanitize=address -o $BINARY $0 \
`pkg-config libavcodec libavformat libavutil libva gl egl libdrm --cflags --libs` \
-lX11 -lva-x11 -lva-drm || exit 1
test "$1" = "--compile-only" && exit 0
exec env ASAN_OPTIONS=fast_unwind_on_malloc=0 ./$BINARY $*
#endif /*
Minimal example application for hardware video decoding on Linux and display
@kajott
kajott / sortvis.py
Last active August 8, 2019 21:25
visualization of various in-place sorting algorithms
#!/usr/bin/env python3
"""
Visualization of various in-place sorting algorithms.
Can generate a HTML page and video files to browse and display the results.
Note: requires FFmpeg to display and export the visualizations.
The code snippets in the HTML report are syntax highlighted if Pygments
is installed.
@kajott
kajott / variable_randomness.cpp
Last active August 8, 2019 19:51
generate sequences of numbers with variable degree of randomness
#if 0
g++ -std=c++11 -Wall -Wextra -pedantic -Werror $0 || exit 1
exec ./a.out
#endif
// generate sequences of numbers 0..(1-n) with variable degree of randomness:
// r = 0.0 -> perfectly sorted
// r = 0.5 -> fully shuffled
// r = 1.0 -> perfectly reversed