This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Instantiate one of these structs, and use it in print statements to get formatted output | |
// | |
// Set the .value if you know the float value, or .string if you have a string value | |
// Set the currency to override the currency prefix | |
// | |
// Will format the number using commas, so 1234.56 -> 1,234.56 for example | |
// | |
// If Negative, will wrap the output in a <span class="negative"></span> (which turns it red) | |
// and places the negative sign outside the currency symbol | |
// Hack/Change this suit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// vendored from https://github.com/nektro/zig-time/tree/master | |
const std = @import("std"); | |
const string = []const u8; | |
const time = @This(); | |
pub const DateTime = struct { | |
ms: u16, | |
seconds: u16, | |
minutes: u16, | |
hours: u16, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const Self = @This(); | |
fn runLoop(self: *Self) !void { | |
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
const allocator = gpa.allocator(); | |
var server = std.http.Server.init(allocator, .{ .reuse_address = true, .kernel_backlog = 64 }); | |
defer server.deinit(); | |
var listen_address = try std.net.Address.resolveIp("0.0.0.0", 8080); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const Self = @This(); | |
fn runLoop(self: *Self) !void { | |
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
const allocator = gpa.allocator(); | |
var server = std.http.Server.init(allocator, .{ .reuse_address = true, .kernel_backlog = 4096 }); | |
defer server.deinit(); | |
var listen_address = try std.net.Address.resolveIp("127.0.0.1", self.config.port); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn main() !void { | |
var server = Server.init(std.heap.page_allocator, .{ .reuse_address = true }); | |
defer server.deinit(); | |
try server.listen(try net.Address.parseIp("127.0.0.1", 8080)); | |
while (true) { | |
var buf: [8192]u8 = undefined; | |
std.log.info("Waiting for a new connection ...", .{}); | |
const res = try server.accept(.{ .static = &buf }); // use a buffer for headers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn sendfile(res: *std.http.Server.Response, filename: []const u8) !void { | |
var file = std.fs.cwd().openFile(filename, .{}) catch { | |
// TODO - Add any extra 404 handling code here | |
res.status = .not_found; | |
try res.do(); | |
return; | |
}; | |
defer file.close(); | |
const file_len = try file.getEndPos(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const Stuff = enum { zeroth, first, second, third, somethingElse }; | |
const OtherStuff = enum { zeroth, first, second, third, somethingElse }; | |
const EnumLookupError = error{InvalidName}; | |
// convert a string into a enum field | |
pub fn stringToEnum(comptime E: type, name: []const u8) EnumLookupError!E { | |
inline for (std.meta.fields(E)) |e| { | |
if (std.mem.eql(u8, name, e.name)) { |