Skip to content

Instantly share code, notes, and snippets.

@qexat
qexat / vec.c
Last active August 5, 2023 11:06
learning c lol
/* Vec */
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#define LAST_OF(array, length) array[length-1]
size_t get_capacity(size_t length)
{
@qexat
qexat / range_iter.c
Last active August 5, 2023 18:19
idk i wrote some range iterator
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define DEFAULT_START 0
#define DEFAULT_STEP(START, STOP) START < STOP ? 1 : -1
#define TO_INT(STR) (int)strtol(STR, NULL, 10)
#define IS_HELP_FLAG(STR) (!strcmp(STR, "--help")) || (!strcmp(STR, "-h"))
@qexat
qexat / hello.c
Last active March 11, 2025 16:20
least portable C hello world program
// only works on Compiler Explorer with x86-64 gcc
// gcc hello.c -o hello && ./hello
extern int(puts)(char const *);
char static *message = "Hello World!\n";
__attribute__((used)) void f(void)
{
puts(message);
@qexat
qexat / mfw_monads.py
Created August 26, 2023 14:40
wtf monads?? 😳️😳️😳️
from __future__ import annotations
import abc
import dataclasses
import enum
import typing
from collections.abc import Callable
T1 = typing.TypeVar("T1")
T2 = typing.TypeVar("T2")
@qexat
qexat / become_unrunnable.py
Last active August 28, 2023 21:55
become unrunnable. 💪️💪️💪️💪️
import os
import sys
# Printing? No.
del sys.stdout
# Really, no.
del sys.__stdout__
# Errors? "uhhhh object address: [...] lost sys.stderr"
del sys.stderr
# Recovery of stderr: no
@qexat
qexat / lisp_fib.py
Created August 29, 2023 09:24
totally lisp
import os
__annotations__ = globals()
fib: \
(lambda n:
n if n <= 1 else fib(n - 2) + fib(n - 1))
main: \
(lambda:
@qexat
qexat / refined_nat.hs
Created August 31, 2023 21:45
this static refinement type is not valid haskell code :(
refined Nat n where
n :: (Integer t) => t
n >= 0
@qexat
qexat / elevatedFoldr1.hs
Last active September 4, 2023 13:52
Elevated `foldr1`
import Data.Foldable (foldr1)
{-
Fold a list of values into an elevated operator.
This allows applying an operator on a list which values type do not
support the operator, but can be casted to a type which does.
The `toLifted` function casts every value of `values` to a type that `op`
accepts, then `fromLifted` casts back the result to the `values` type.
@qexat
qexat / .bashrc
Created September 13, 2023 13:14
My .bashrc when I'm not using `fish`
#
# ~/.bashrc
#
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
[[ -f ~/.welcome_screen ]] && . ~/.welcome_screen
_set_liveuser_PS1() {
@qexat
qexat / python_interoperability.courbe
Last active September 17, 2023 20:49
python interoperability within a courbe codebase
module (~python {
def fib(n: int) -> int:
if n <= 1:
return n
return fib(n - 2) + fib(n - 1)
}) MyModule
function MyModule.fib fib
function (args::List<String>) -> UInt8 {