Skip to content

Instantly share code, notes, and snippets.

const std = @import("std");
const Channel = std.event.Channel;
const Timer = std.time.Timer;
const warn = std.debug.warn;
pub const io_mode = .evented;
// Send the sequence 2, 3, 4, ... to channel 'ch'.
fn generate(ch: *Channel(u32)) void {
var i: u32 = 2;
@SpexGuy
SpexGuy / vk_nv_raytracing.zig
Created April 21, 2020 03:55
The NV_ray_tracing extension subset of vulkan_core.zig
pub const NV_ray_tracing = 1;
pub const AccelerationStructureNV = *@OpaqueType();
pub const NV_RAY_TRACING_SPEC_VERSION = 3;
pub const NV_RAY_TRACING_EXTENSION_NAME = "VK_NV_ray_tracing";
pub const SHADER_UNUSED_NV = (~@as(u32, 0));
pub const AccelerationStructureTypeNV = extern enum(i32) {
TOP_LEVEL = 0,
BOTTOM_LEVEL = 1,
@SpexGuy
SpexGuy / vla.zig
Last active June 18, 2021 15:40
VLA types implemented in user space in Zig
const std = @import("std");
pub fn VLA(comptime ArrayType: type, comptime ParentStruct: type, comptime fieldName: []u8) type {
return struct {
const headerSize: usize = comptime std.mem.alignForward(@sizeOf(ParentStruct), @alignOf(ArrayType));
const headerAlign: u29 = comptime std.math.max(@alignOf(ArrayType), @alignOf(ParentStruct));
len: usize,
pub fn get(self: *@This()) []ArrayType {
@SpexGuy
SpexGuy / tagged_unions.zig
Last active April 19, 2025 23:57
Zig: Using tagged unions to make a simple json formatter
const JsonString = struct {
value: []const u8,
};
const JsonNumber = struct {
value: f64,
};
const JsonObject = struct {
const Property = struct {
name: []const u8,
value: JsonValue,
@SpexGuy
SpexGuy / main.cpp
Created February 28, 2017 02:14
GlfwTemplate simple triangle on mac
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <glm/glm.hpp>
#include <stb/stb_image.h>
#include "gl_includes.h"
@SpexGuy
SpexGuy / DelaunayAdjacency.java
Last active December 22, 2016 22:22
A routine to calculate whether two points are adjacent in the Delaunay Triangulation of a space.
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
/**
* This class computes whether two points are adjacent in the Delaunay Triangulation of a set of points.
* Throughout the implementation, it makes the assumption that points can be compared with reference equality for uniqueness.
*/
public abstract class DelaunayAdjacency {
private static final float EPSILON = 0.000001f;