Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <stdint.h>
#define ONE_LETTER_CMD(str, c) ((str[0] == c) && (str[1] == ' '))
#define TWO_LETTER_CMD(str, c0, c1) ((str[0] == c0) && (str[1] == c1) && (str[2] == ' '))
#define VCMD(str) ONE_LETTER_CMD(str, 'v')
#define FCMD(str) ONE_LETTER_CMD(str, 'f')
@ancientstraits
ancientstraits / error.h
Created March 7, 2023 18:23
Simple error-handling utility for C
#ifndef ERROR_H
#define ERROR_H
#define LOG(...) do { \
fprintf(stderr, "%s:%s():%d: ", __FILE__, __func__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fputc('\n', stderr); \
} while(0)
#define FAIL(...) do { LOG("Error: " __VA_ARGS__); exit(1); } while(0)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define ROUNDS 100
float outval(float w, float x) {
return w * x;
}
@ancientstraits
ancientstraits / sane.c
Last active July 5, 2022 19:22
stupid github microsoft jerks tryna indoctrinate us into using spaces instead of tabs
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
typedef struct Node {
size_t size;
struct Node* next;
struct Node* prev;
} Node;
@ancientstraits
ancientstraits / mock.c
Created May 12, 2022 17:30
A mocking framework
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
void mock(char* s) {
srand(time(NULL));
for (int i = 0; s[i]; i++) {
if (rand() % 2 == 0)
@ancientstraits
ancientstraits / print_all_args.asm
Created May 12, 2022 12:42
print all arguments in x64 asm
global main
extern puts
main:
push rbp
mov rbx, rdi
.loop:
push rsi
mov rdi, [rsi]
local cm = require('codim')
-- An animation is a function that takes time in and returns an image.
local function logo(props, time)
if time.seconds <= props.seconds then
return cm.text {
location = cm.position.center,
color = white,
}
else
@ancientstraits
ancientstraits / build.sh
Created March 30, 2022 19:15
build.sh: An alternative to a Makefile which also creates a `compile_commands.json`. Has MIT License
#!/bin/bash
# The build script for the program
# Paths
[ -z $SRC ] && SRC='src'
[ -z $INC ] && INC='inc'
[ -z $OBJ ] && OBJ='obj'
[ -z $EXEC ] && EXEC='main'
I ran the program 3 times.
1st run:
Bubble Sort No Temp: 1.147000 ms (4.779167 μs per 240 iterations)
Bubble Sort With Temp: 0.963000 ms (4.012500 μs per 240 iterations)
2nd run:
Bubble Sort No Temp: 1.134000 ms (4.685950 μs per 242 iterations)
Bubble Sort With Temp: 0.980000 ms (4.049587 μs per 242 iterations)
@ancientstraits
ancientstraits / gitpod_vnc.sh
Last active September 16, 2021 12:08
Install VNC on gitpod
#!/bin/sh
# This script easily gives gitpod graphical
# capabilities by using tightvncserver and noVNC.
# To be lightweight, it also uses awesomeWM as the
# graphical environment, but you can change it
# by editing this script.
# Package management
sudo apt update