Skip to content

Instantly share code, notes, and snippets.

View angelcaru's full-sized avatar

angelcaru

View GitHub Profile
@angelcaru
angelcaru / 01-big-o.md
Created April 5, 2025 08:42
Explanation of Big O notation

For example, take this sorting algorithm:

void bubble_sort(int *array, size_t count) {
    for (size_t n = 0; n < count - 1; n++) {
        for (size_t i = 0; i < count - 1; i++) {
            size_t j = i + 1;
            if (array[j] < array[i]) {
                swap(&array[i], &array[j]);
            }
        }
#include <stdarg.h>
#include <string.h>
int switchcmp(char *tc, ...) {
va_list args;
va_start(args, tc);
const char *arg;
int c = 0;
while ((arg = va_arg(args, const char *)) != NULL) {
if (strcmp(tc, arg) == 0) {
va_end(args);
@angelcaru
angelcaru / main.c
Created February 27, 2025 22:35
Simple example of writing directly to `/dev/fb0` in C on Linux
#include <stdint.h>
#include <sys/ioctl.h>
#include <linux/fb.h>
typedef union {
uint32_t rgba;
struct {
uint8_t b, g, r, a;
@angelcaru
angelcaru / printimg.c
Created May 3, 2024 14:47
Simple ANSI terminal image viewer in C
// NOTE: you will need stb_image in order to compile this
// Currently only works on POSIX-compliant systems because of the use of ioctl()
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
#include <sys/ioctl.h>
void usage(const char *program_name) {
printf("Usage: %s <filename>\n", program_name);
}
@angelcaru
angelcaru / index.html
Created March 17, 2024 19:43
"""Cookie clicker""" in 11 lines of code
<canvas id="canvas" width="800" height="800"></canvas>
<script src="main.js"></script>
@angelcaru
angelcaru / bf.c
Created February 28, 2024 19:37
Brainf**k transpiler in C
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
void usage(const char *program_name) {
printf("Usage: %s <input-file>\n", program_name);
}