Skip to content

Instantly share code, notes, and snippets.

View Jomy10's full-sized avatar

Jonas Everaert Jomy10

View GitHub Profile
@Jomy10
Jomy10 / tagged_union.h
Last active April 24, 2024 17:53
C Tagged Union Macro
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Author: Jonas Everaert
//
// You can change these however you like
#define _TU_TYPE_PREFIX(Type) T_##Type
@Jomy10
Jomy10 / main.rs
Last active December 18, 2023 16:24
Some WGPU code, very cool
use winit::{
window::Window,
event::{Event, WindowEvent, self},
event_loop,
};
use wgpu::util::DeviceExt;
use anyhow::Result;
#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
@Jomy10
Jomy10 / make.rb
Last active December 21, 2023 14:56
Beaver 3.0 example
require 'beaver'
project = Project.new("MyProject")
project.set_configs("Debug", "Release")
# Set configuration options for the C language
project.c_configs = {
"Debug" => C::Configuration.new(cflags: ["-DDEBUG"]),
"Release" => C::Configuration.new(cflags: ["-DRELEASE"])
}
project.default_config = "Debug"
@Jomy10
Jomy10 / array.c
Created December 29, 2023 14:21
C Array
#include <stdio.h>
#include <stdlib.h>
#define Array(Type) struct array_##Type
#define DefineArray(Type) struct array_##Type { Type* elements; int len; int cap; }
#define array_get(array, index) (array).elements[index]
#define array_set(array, value, index) (array).elements[index] = value
#define create_Array(Type, cap) (struct array_##Type) { (Type*) malloc(cap * sizeof(Type)), 0, cap }
#define destroy_Array(array) free((array).elements)
#define array_append(array, value) (array).elements[(array).len++] = value
#include <stdio.h>
#include <stdlib.h>
typedef void*(*allocator_alloc_fn)(void* userData, size_t cap);
typedef void (*allocator_free_fn)(void* userData, void* ptr);
typedef void*(*allocator_realloc_fn)(void* userData, void* ptr, size_t cap);
typedef struct _allocator {
allocator_alloc_fn alloc;
allocator_free_fn free;
@Jomy10
Jomy10 / build.sh
Last active January 8, 2024 15:30
Libcamera to framebuffer
clang++ main.cpp $(pkg-config libcamera --libs --cflags) -std=gnu++20