Skip to content

Instantly share code, notes, and snippets.

@SpexGuy
SpexGuy / net.zig
Created October 30, 2020 19:32
Is this correct nonblocking use?
const std = @import("std");
pub const raw = @import("zig-network");
const heap_allocator = std.heap.c_allocator;
// config vars
pub var serverConnectionPort: u16 = 0x4d3;
pub var addressFamily: raw.AddressFamily = .ipv4;
pub var maxConnectionsPerFrame: usize = 4;
@SpexGuy
SpexGuy / day01_vectorized.zig
Created December 1, 2020 23:35
Advent of code 2020 day 1, in zig, vectorized.
const std = @import("std");
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
const print = std.debug.print;
const Timer = std.time.Timer;
const data = @embedFile("data/day01.txt");
const EntriesList = std.ArrayList(i16);
var tok = std.mem.tokenize(line, "- :");
var min = try std.fmt.parseInt(u32, tok.next().?, 10);
var max = try std.fmt.parseInt(u32, tok.next().?, 10);
var char = tok.next().?[0];
var pass = tok.next().?;
assert(tok.next() == null);
/// This function issues a compile error with a helpful message if there
/// is a problem with the provided context type. A context must have the following
/// member functions:
/// - hash(self, PseudoKey) Hash
/// - eql(self, PseudoKey, Key) bool
/// If you are passing a context to a *Adapted function, PseudoKey is the type
/// of the key parameter. Otherwise, when creating a HashMap or HashMapUnmanaged
/// type, PseudoKey = Key = K.
pub fn verifyContext(comptime RawContext: type, comptime PseudoKey: type, comptime Key: type, comptime Hash: type) void {
comptime {
const std = @import("std");
const Channel = struct {
value: u32,
frame: anyframe,
};
fn generate(channel: *Channel) void {
suspend { channel.frame = @frame(); }
var i: u32 = 2;
@SpexGuy
SpexGuy / DrawCircleQuads.c
Created September 4, 2023 13:49
DrawCircle with quads, saving previous corner position
rlBegin(RL_QUADS);
float lastCornerX = center.x + cosf(DEG2RAD*angle)*radius;
float lastCornerY = center.y + sinf(DEG2RAD*angle)*radius;
// NOTE: Every QUAD actually represents two segments
for (int i = 0; i < segments/2; i++)
{
float nextAngle = angle + stepLength*2.0f;
float nextCornerX = center.x + cosf(DEG2RAD*(nextAngle))*radius;