Skip to content

Instantly share code, notes, and snippets.

View m1lkweed's full-sized avatar

m1lkweed

View GitHub Profile
struct arc {
int32_t rc;
uv_mutex_t mutex;
};
typedef void* moonbit_reference_t;
struct arc_ref {
@mattiasgustavsson
mattiasgustavsson / bass_and_treble.h
Created January 30, 2025 13:06
Audio filters for a stereo widening effect and for simple bass/treble eq
/*
------------------------------------------------------------------------------
Licensing information can be found at the end of the file.
------------------------------------------------------------------------------
bass_and_treble.h - v1.0 - Simple audio filter to boost bass and treble.
Do this:
#define BASS_AND_TREBLE_IMPLEMENTATION
before you include this file in *one* C/C++ file to create the implementation.
bl_info = {"name": "Zoetrope", "category": "Animation"}
import bpy
class Zoetrope(bpy.types.Operator):
bl_idname = "anim.zoetrope"
bl_label = "Zoetrope"
def execute(self, context):
@harieamjari
harieamjari / rgb2vga.c
Created June 13, 2023 17:22
Converts RGB values to VGA 256
/* rgb2vga.c - converts rgb values to vga 256. */
/* Copyright (c) 2023 Al-buharie Amjari */
/* Released under MIT License */
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#define F(x) ((float)x)
@imaami
imaami / typeof_unqual.c
Created April 15, 2023 13:17
Backport of C23's typeof_unqual in plain C18
#define typeof_unqual(x) __typeof__(((void)1, *(__typeof__(x) *)(void *)0))
int main(void) {
const int ci = 1;
typeof_unqual(ci) i1 = ci;
typeof_unqual(const int) i2 = ci;
i1 = 0;
i2 = 0;
return i1 + i2;
}
@den-mentiei
den-mentiei / debounce.c
Created July 18, 2022 13:08
Digital input signal debouncing by Kenneth A. Kuhn
/******************************************************************************
debounce.c
written by Kenneth A. Kuhn
version 1.00
This is an algorithm that debounces or removes random or spurious
transistions of a digital signal read as an input by a computer. This is
particularly applicable when the input is from a mechanical contact. An
integrator is used to perform a time hysterisis so that the signal must
persistantly be in a logical state (0 or 1) in order for the output to change
#include <stdlib.h>
#include <string.h>
#define CAPACITY 100000
typedef struct Entry {
char* key;
void* value;
struct Entry* next;
} Entry;
@bakerface
bakerface / co.h
Last active June 10, 2025 15:06
Coroutines in 10 lines of ANSI C
/**
* Copyright (c) 2025 Chris Baker <mail.chris.baker@gmail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@Lokno
Lokno / camera.c
Last active September 17, 2025 01:16
Camera Code
// I have a plane of size A,B in 3D space. I have a camera, which is pointed dead-on at the plane. The camera is mapping the plane into a window of size X,Y.
// How far Z should the camera be away from the plane for the *entire* plane to be visible?
//
// Find the minimum distance where the entire plane is in view
float get_distance( float plane_width, float plane_height, float fov )
{
float half_width = plane_width / 2.0f;
float half_height = plane_height / 2.0f;
float half_fov = fov / 2.0f;
// This can grow a Robin Hood linear probing hash table near word-at-a-time memcpy speeds. If you're confused why I use 'keys'
// to describe the hash values, it's because my favorite perspective on Robin Hood (which I learned from Paul Khuong)
// is that it's just a sorted gap array which is MSB bucketed and insertion sorted per chain:
// https://pvk.ca/Blog/2019/09/29/a-couple-of-probabilistic-worst-case-bounds-for-robin-hood-linear-probing/
// The more widely known "max displacement" picture of Robin Hood hashing also has strengths since the max displacement
// can be stored very compactly. You can see a micro-optimized example of that here for small tables where the max displacement
// can fit in 4 bits: Sub-nanosecond Searches Using Vector Instructions, https://www.youtube.com/watch?v=paxIkKBzqBU
void grow(Table *table) {
u64 exp = 64 - table->shift;
// We grow the table downward in place by a factor of 2 (not counting the overflow area at table->end).