Skip to content

Instantly share code, notes, and snippets.

View forksnd's full-sized avatar
🍴
Forking together, for great pleasure

forksnd

🍴
Forking together, for great pleasure
View GitHub Profile
@forksnd
forksnd / f32_to_str.c
Created August 20, 2025 08:21
Tiny Dragon4 implementation for printing floats (taken from https://pastebin.com/z9hYEWF1)
/* float to decimal string, exact conversion; tested for all possible inputs against mingw 4.0 sprintf with define _XOPEN_SOURCE 1
tei.andu@tutanota.com
*/
typedef union {
float f;
uint32_t u32;
struct {
uint32_t m:23;
uint32_t x:8;
@forksnd
forksnd / git.md
Last active October 28, 2025 23:20 — forked from zefhemel/git.md
function log (message)
  local msg = message or ""
  editor.flashNotification(msg)
  print(msg)
end
git = {}
@forksnd
forksnd / Object.h
Created June 7, 2025 14:32 — forked from CodaFi/Object.h
The headers of the oldest version of the Objective-C runtime I could still find. Extracted from an old NeXT image.
#ident "@(#) Object.h, Rev 2.10, 96/08/02"
//
// Copyright (c) 1995-1996, Sun Microsystems, Inc.
// portions (c) Copyright 1988, 1989 NeXT, Inc.
// All rights reserved.
#ifndef _OBJC_OBJECT_H_
#define _OBJC_OBJECT_H_
#import <objc/objc.h>
@forksnd
forksnd / lisp.c
Last active February 26, 2025 08:31
Lisp interpreter implemented by ChatGPT (not that there are multiple C files with their own version of the interpreter).
/*
===========================================================================
Common Lisp InterpreterBytecode-Based, Register-VM Architecture
===========================================================================
This interpreter implements a minimal Common Lisp system featuring:
1. Reading:
- Input: A text file.
- Operations: Tokenization and application of reader macros (quotes, backquote/unquote,
unquote-splicing, read-time evaluation).
// based on xxhash32
unsigned int hash(char *data, size_t len)
{
unsigned int hash;
if (len < 4) {
// load 3 bytes, overlapping if len < 3
static unsigned char offset1[4] = { 0,0,1,1 };
static unsigned char offset2[4] = { 0,0,0,2 };
unsigned int h = data[0] + (data[offset1[len]]<<8) + (data[offset2[len]]<<16);
h = xxprime1 + h*xxprime2;
@forksnd
forksnd / maths.cpp
Created December 7, 2024 09:42 — forked from nakst/maths.cpp
// NOTE Compile without fast math flags.
/*
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.
@forksnd
forksnd / !README.md
Created December 3, 2024 12:18 — forked from mmozeiko/!README.md
Download MSVC compiler/linker & Windows SDK without installing full Visual Studio

This downloads standalone MSVC compiler, linker & other tools, also headers/libraries from Windows SDK into portable folder, without installing Visual Studio. Has bare minimum components - no UWP/Store/WindowsRT stuff, just files & tools for native desktop app development.

Run py.exe portable-msvc.py and it will download output into msvc folder. By default it will download latest available MSVC & Windows SDK - currently v14.40.33807 and v10.0.26100.0.

You can list available versions with py.exe portable-msvc.py --show-versions and then pass versions you want with --msvc-version and --sdk-version arguments.

To use cl.exe/link.exe first run setup_TARGET.bat - after that PATH/INCLUDE/LIB env variables will be updated to use all the tools as usual. You can also use clang-cl.exe with these includes & libraries.

To use clang-cl.exe without running setup.bat, pass extra /winsysroot msvc argument (msvc is folder name where output is stored).

@forksnd
forksnd / incbin.c
Created November 27, 2024 05:21 — forked from Ionizing/incbin.c
Include binary file with gcc/clang
#define STR2(x) #x
#define STR(x) STR2(x)
#ifdef __APPLE__
#define USTR(x) "_" STR(x)
#else
#define USTR(x) STR(x)
#endif
#ifdef _WIN32
@forksnd
forksnd / sqrt_exact.c
Created November 16, 2024 04:24 — forked from mdickinson/sqrt_exact.c
Fast square root of a 64-bit square number
// Exact square root of a known square integer
// ===========================================
// This snippet contains a function `isqrt64_exact` with signature
//
// uint32_t isqrt64_exact(uint64_t n);
//
// `isqrt64_exact` computes the 32-bit square root of its unsigned 64-bit
// integer input, under the assumption that that input is a perfect square.
//
// Compile under gcc or clang with:
struct Object {
Key key; // The key is any piece of data that uniquely identifies the object.
// ...
};
struct Handle {
Key key;
Index index; // This caches a speculative table index for an object with the corresponding key.
};