Skip to content

Instantly share code, notes, and snippets.

@WoodyAtHome
WoodyAtHome / main.zig
Created September 4, 2020 16:26
threaded http server
const std = @import("std");
const ConnectionContext = struct {
allocator: *std.mem.Allocator,
conn: std.net.StreamServer.Connection,
server: *std.net.StreamServer,
finished: bool = false,
thread: ?*std.Thread = null,
};
@WoodyAtHome
WoodyAtHome / datetime.zig
Last active December 21, 2023 18:44
unix timestamp to local time and date conversions (for Berlin/Amsterdam)
const std = @import("std");
const TimeOffset = struct {
from: i64,
offset: i16,
};
const timeOffsets_Berlin = [_]TimeOffset{
TimeOffset{ .from = 2140045200, .offset = 3600 }, // Sun Oct 25 01:00:00 2037
TimeOffset{ .from = 2121901200, .offset = 7200 }, // Sun Mar 29 01:00:00 2037
@WoodyAtHome
WoodyAtHome / main.zig
Created August 27, 2020 18:30
simple http server
const std = @import("std");
pub const io_mode = .evented;
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = &gpa.allocator;
const req_listen_addr = std.net.Address.parseIp4("127.0.0.1", 9000) catch unreachable;