Skip to content

Instantly share code, notes, and snippets.

View kspalaiologos's full-sized avatar
❤️‍🔥

Kamila Szewczyk kspalaiologos

❤️‍🔥
View GitHub Profile
@kspalaiologos
kspalaiologos / autocache
Created June 9, 2025 15:02
Cache autotools configurations.
#!/bin/bash
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <mode> [configure-args...]"
exit 1
fi
SCRIPT="$0"
case "$SCRIPT" in
/*) DIR=$(dirname "$SCRIPT") ;;
*) DIR=$(cd "$(dirname "$SCRIPT")" && pwd) ;;
esac
@kspalaiologos
kspalaiologos / rfsb509.c
Created April 19, 2025 23:29
A high performance (~500MB/s) implementation of "Really fast syndrome-based hashing" (RFSB-509) by D. J. Bernstein, T. Lange, C. Peters, and P. Schwabe.
#include <emmintrin.h>
#include <stdint.h>
#include <stddef.h>
static const uint8_t matrix[16384] = {
0x66, 0xe9, 0x4b, 0xd4, 0xef, 0x8a, 0x2c, 0x3b, 0x88, 0x4c, 0xfa, 0x59, 0xca, 0x34, 0x2b, 0x2e, 0x47, 0x71, 0x18, 0x16, 0xe9, 0x1d, 0x6f, 0xf0, 0x59, 0xbb, 0xbf, 0x2b, 0xf5, 0x8e, 0x0f, 0xd3, 0xbc, 0xf1, 0x76, 0xa7, 0xea, 0xad, 0x80, 0x85, 0xeb, 0xac, 0xea, 0x36, 0x24, 0x62, 0xa2, 0x81, 0x4f, 0xfc, 0x69, 0x77, 0x2e, 0xd5, 0xa3, 0x36, 0xf4, 0x61, 0x5b, 0x45, 0x03, 0xc3, 0x48, 0x14,
0xf8, 0x32, 0x1c, 0xf1, 0x8e, 0xf5, 0xfe, 0x72, 0x7d, 0xd8, 0x2a, 0x5c, 0x1e, 0x94, 0x51, 0x41, 0x2f, 0x16, 0x48, 0xbc, 0x9d, 0x95, 0xc3, 0x7f, 0xee, 0x0f, 0xd7, 0x53, 0x79, 0xfb, 0x7e, 0x59, 0x97, 0x45, 0xd7, 0xb2, 0x19, 0x72, 0xb1, 0x0b, 0x39, 0x93, 0xcc, 0x5d, 0x2f, 0xdd, 0x78, 0x8c, 0xd2, 0x61, 0xfd, 0x7d, 0x57, 0x9b, 0x0d, 0x40, 0x33, 0xba, 0xf0, 0x6d, 0x4e, 0x35, 0xb9, 0x0e,
0x29, 0x2c, 0x02, 0xc5, 0xcb, 0x91, 0x63, 0xc8, 0x0a, 0xc0, 0xf6, 0xcf, 0x1d, 0xd8, 0xe9, 0x2d, 0xef, 0xcd, 0x22, 0x90, 0xb9, 0xae, 0xe1, 0x86, 0
#include <stdio.h>
#include <time.h>
void f(long u) {
char*ms="SunMonTueWedThuFriSatJanFebMarAprMayJunJulAugSepOctNovDec";
int t=u%86400,od=u/86400,y,d=od,m,a,mp;if(d>11016)y=100,d++;y+=(d=(4
*d+2877875)%146097|3)/1461;a=(d=d%1461/4+1)-307;m=((d*=5)-3)/153;if(
(mp=m+2)>11)mp-=12,y++;printf("%02d:%02d:%02d (UTC), %.3s %02d %.3s"
" %d (day %d)",t/3600,(t/60)%60,t%60,ms+3*((od+4)%7),(d+2-153*m)/5-1
,ms+21+3*m,y+1900,(a>=0?a:a+365)+(!(y&3)&&a<0)); }
int main(void) { f(time(NULL)); }
// ---------------------------------------------------------------------------
// KCrypt3 - 3rd iteration of the KCrypt algorithm.
// Written on Sunday, 26th of January 2025 by Kamila Szewczyk.
// ---------------------------------------------------------------------------
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <stdlib.h>
// Feeling overwhelmed by "find the words in a grid" tasks for preschoolers?
// Look no further!
#include <leptonica/allheaders.h>
#include <tesseract/baseapi.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
@kspalaiologos
kspalaiologos / clos.cpp
Created November 15, 2024 00:44
kludge to convert a cpp-style closure into a c pointer, retains data in an external structure
namespace {
template <typename F, int I, typename L, typename R, typename ...A>
inline F convert(L&& l, R (*)(A...) noexcept(noexcept(::std::declval<F>()(::std::declval<A>()...)))) {
static thread_local L l_(::std::forward<L>(l));
static thread_local bool full;
if (full) {
l_.~L();
new (static_cast<void*>(&l_)) L(::std::forward<L>(l));
} else
@kspalaiologos
kspalaiologos / pgn.l
Created November 4, 2024 20:15
Flex scanner for PGN files.
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
enum {
TAG = 0x100, COMMENT, REGULAR_MOVE, PROMOTION_MOVE, SHORT_CASTLE, LONG_CASTLE,
R1_0, R0_1, R12_12, RSTAR, CONTINUATION_MOVE_NUMBER, MOVE_NUMBER
};
@kspalaiologos
kspalaiologos / ccg.c
Last active September 9, 2024 10:45
Compact Cyclic Generator - a fast non-cryptographic random number generator based on polynomial codes.
// Public Domain.
#include <stdint.h>
#include <stdio.h>
uint32_t s, b;
void ccg_seed(uint32_t seed) {
s = (b = seed ^ 0xAAAAAAAA) | 1;
}
uint32_t ccg_next() {
uint32_t b = s >> 31;
s <<= 1, s ^= b * 0xEDB88320;
@kspalaiologos
kspalaiologos / ppm90.c
Last active June 4, 2024 17:13
PPM in 90 lines of code.
#define COPY(dst, src, n) for (int i = 0; i < n; i++) dst = src;
typedef struct {
uint32_t range, FF, cache; uint64_t low; FILE * source;
} rc_t;
void rc_init(rc_t * rc, FILE * source) {
rc->range = 0xFFFFFFFF;
rc->FF = rc->cache = 0; rc->low = 0;
rc->source = source;
}
void rc_init_dec(rc_t * rc, FILE * source) {
@kspalaiologos
kspalaiologos / gist:8845b3e65d82440b37635c6603ae436b
Created May 13, 2024 12:45
the most popular languages of cgcc
106 : ES6
107 : Nim
110 : Keg
114 : Fig
115 : Cubix
116 : Attache
117 : k
122 : Ly
123 : tinylisp
124 : Oracle