Skip to content

Instantly share code, notes, and snippets.

View rlapz's full-sized avatar
👀

Arthur Lapz rlapz

👀
View GitHub Profile
@rlapz
rlapz / fsconf.h
Last active November 23, 2023 13:22
A f*cking simple, error prone, and slow key-value-based file configuration reader
#ifndef __FSCONF_H__
#define __FSCONF_H__
/* A f*cking simple, error prone, and slow key-value-based file configuration
*
* File name: file.fsconf
* ------------------------
* key0(value)\n
* key1(value)\n
@rlapz
rlapz / build.sh
Last active October 29, 2023 10:53
#!/bin/sh
set -e
cc -g -Wall -Wextra moetr.c $(pkg-config --cflags gtk4 libsoup-3.0 json-glib-1.0)\
$(pkg-config --libs gtk4 libsoup-3.0 json-glib-1.0) -o moetr
@rlapz
rlapz / blog.c
Last active January 8, 2024 13:42
A simple static site generator for blog
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
@rlapz
rlapz / lru.zig
Last active July 26, 2023 14:49
LRU cache
const std = @import("std");
const debug = std.debug;
const mem = std.mem;
const net = std.net;
const time = std.time;
const dprint = debug.print;
const assert = debug.assert;
pub fn Lru(comptime T: type, comptime key_size: u16) type {
const std = @import("std");
const fmt = std.fmt;
const io = std.io;
const mem = std.mem;
const net = std.net;
const os = std.os;
const dprint = std.debug.print;
// caller owns the returned memory
@rlapz
rlapz / fturing.zig
Created April 22, 2023 14:49
fturing: zig implementation
const std = @import("std");
const assert = std.debug.assert;
const fmt = std.fmt;
const heap = std.heap;
const mem = std.mem;
const log = std.log;
const os = std.os;
const io = std.io;
const net = std.net;
"""
I F*CKING HATE THE EXCEPTION!!!
"""
import os
import socket
import signal
import ctypes
import struct
import ctypes
import struct
"""
c-struct
typedef struct {
uint64_t fsize; // offset: 0
uint8_t fname_len; // offset: 8
char fname[255]; // offset: 9
@rlapz
rlapz / thrd_queue.c
Last active December 24, 2023 07:32
Thread queue sync
#include <threads.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
typedef struct _Node {
struct _Node *prev;
struct _Node *next;
} Node;
@rlapz
rlapz / mempool.c
Last active April 7, 2024 17:28
memory pool: fast allocate & deallocate a single item memory
#include <errno.h>
#include "mempool.h"
int
mempool_init(MemPool *m, size_t nmemb, size_t size)
{
m->nmemb = nmemb;
m->head = NULL;