Skip to content

Instantly share code, notes, and snippets.

View lmllrjr's full-sized avatar
🥬

Lukas Moeller lmllrjr

🥬
View GitHub Profile
@lmllrjr
lmllrjr / NEWS.md
Last active July 1, 2024 05:19
Random dev joke

A programmer puts two glasses on his
bedside table before going to sleep.

  • A full one, in case he gets thirsty,
    and an empty one, in case he doesn’t.

01.07.2024 05:19:04

@lmllrjr
lmllrjr / datetime.zig
Last active December 21, 2023 18:45
convert unix epoch timestamp to local time and date
// date time handling
pub const DateTime = struct {
day: u8,
month: u8,
year: u16,
hour: u8,
minute: u8,
second: u8,
};
@lmllrjr
lmllrjr / curl_request_with_presigned_url.md
Last active November 28, 2023 19:20
How to create a curl request using a presigned URL from an AWS S3 bucket

AWS S3 Presigned URL Example

The url that is being returned by aws s3.PresignClient:

"http://localhost:9000/bucket-name/bucket-key?
X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=minioadmin%2F20231127%2Feu-west-1%2Fs3%2Faws4_request
&X-Amz-Date=20231127T163354Z
&X-Amz-Expires=900
&X-Amz-SignedHeaders=expires%3Bhost
&x-id=PutObject
&X-Amz-Signature=b187cc4d700e46a3b6e381a37a334e604cc782fe9a544051e8e411ac23316a6e"
const std = @import("std");
const time = std.time;
pub fn main() !void {
var timespec = std.os.timespec{
.tv_sec = 0,
.tv_nsec = 0,
};
std.debug.print("\n\n{any}\n\n", .{timespec});
try std.os.clock_gettime(std.os.CLOCK.REALTIME, &timespec);
@lmllrjr
lmllrjr / argv.zig
Created October 16, 2023 21:19
⚡️ zig get command line arguments
const std = @import("std");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);
@lmllrjr
lmllrjr / gpa.zig
Created July 30, 2023 00:30
use general purpose allocator for string concatenation
const std = @import("std");
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = gpa.allocator();
pub fn main() !void {
var distance: i32 = 7857;
var str = std.fmt.allocPrint(
alloc,
"test alloc: {d}",
.{distance},
@lmllrjr
lmllrjr / updategist.zig
Created July 16, 2023 11:21
[Zig⚡️] update a gist
const std = @import("std");
const http = std.http;
const Client = http.Client;
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const calloc = gpa.allocator();
pub fn main() !void {
// get token and gist id from .envrc file (get ENV VAR)
const token = std.os.getenv("GH_TOKEN") orelse "";
@lmllrjr
lmllrjr / bazighttp.zig
Last active June 4, 2023 19:50
[Zig⚡️] basic http server with multiplexer
// zig version 0.10.1
const std = @import("std");
const net = std.net;
const mem = std.mem;
const log = std.log;
const stdout = std.io.getStdOut().writer();
const BUFSIZE = 8192;
const HTTPHEAD =
@lmllrjr
lmllrjr / get_user_input.zig
Created June 4, 2023 14:31
[Zig⚡️] get user input
const std = @import("std");
const stdout = std.io.getStdOut().writer();
const stdin = std.io.getStdIn().reader();
pub fn main() anyerror!void {
var buf = std.io.bufferedReader(stdin);
// Get the Reader interface from BufferedReader
var r = buf.reader();