Skip to content

Instantly share code, notes, and snippets.

View peterhellberg's full-sized avatar
💙
Coding Go

Peter Hellberg peterhellberg

💙
Coding Go
View GitHub Profile
@peterhellberg
peterhellberg / grumpy_movie_reviewer.go
Created September 15, 2025 15:42
Genkit Go example
package main
import (
"cmp"
"context"
"encoding/json"
"fmt"
"io"
"log"
"os"
@peterhellberg
peterhellberg / publisher.c
Last active September 9, 2025 11:43
A pretty minimal publisher example using nats.c
#include <nats/nats.h>
#include <string.h>
const char *subj = "foo";
const char *payload = "example";
int64_t start = 0;
int64_t total = 1000000;
volatile int64_t count = 0;
@peterhellberg
peterhellberg / config.h
Created September 9, 2025 06:53
My config.h for st, with my color scheme
/* See LICENSE file for copyright and license details. */
/*
* appearance
*
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/
static char *font = "Office Code Pro D:antialias=true:style=Medium:pixelsize=20";
static int borderpx = 2;
@peterhellberg
peterhellberg / st.desktop
Created September 9, 2025 06:49
~/.local/share/applications/st.desktop and ~/.local/share/icons/st.png
[Desktop Entry]
Name=st
Comment=Simple Terminal
Exec=/home/peter/.local/bin/st -f "OfficeCodeProD Nerd Font:antialias=true:style=Medium:pixelsize=30"
Terminal=false
Type=Application
Icon=st
Categories=Utility;TerminalEmulator;
StartupWMClass=st-256color
@peterhellberg
peterhellberg / cbor-tagged-messages.go
Last active September 5, 2025 13:25
Tiny example in Go of using CBOR tags to distinguish between two different types of messages using github.com/fxamacker/cbor/v2
package main
import (
"fmt"
"log"
"github.com/fxamacker/cbor/v2"
)
const (
@peterhellberg
peterhellberg / autosave
Last active September 5, 2025 00:22
cmus configuration file
set aaa_mode=artist
set altformat_current= %F
set altformat_playlist= %f%= %d
set altformat_title=%f
set altformat_trackwin= %f%= %d
set auto_expand_albums_follow=true
set auto_expand_albums_search=true
set auto_expand_albums_selcur=true
set auto_reshuffle=true
set buffer_seconds=5
@peterhellberg
peterhellberg / counter.zig
Created August 22, 2025 12:26
Usage of @fieldParentPtr instead of the now removed usingnamespace
const std = @import("std");
pub fn main() !void {
var a = Counter(u32){};
var b = Counter(i32){ .value = 41 };
a.count.increment();
b.count.increment();
std.debug.print("a: {}\tb: {}\n", .{ a.value, b.value });
@peterhellberg
peterhellberg / Makefile
Last active August 15, 2025 21:23
Example of behavioral change when using `virtual` in C++
.PHONY: all
all: build run
CXX := $(or $(CXX),zig c++)
.PHONY: build
build:
${CXX} -std=c++23 -o greeter greeter.cpp
${CXX} -std=c++23 -o virtual virtual.cpp
@peterhellberg
peterhellberg / How_to_move_Valheim_world.html
Created July 12, 2025 10:36
Example of using Markdown support in Caddy using its `templates` directive.
{{ $doc := `
# How to move a Valheim world save
If you need to move a world save from one server to another,
or from your local machine to a server,
this shouldn’t be too painful ;)
## The default location that Valheim saves world files is:
- Windows: %USERPROFILE%/AppData/LocalLow/IronGate/Valheim/worlds/
const std = @import("std");
const mem = std.mem;
const sin = std.math.sin;
const cos = std.math.cos;
const signedRemainder = std.zig.c_translation.signedRemainder;
pub const object_size = std.zig.c_builtins.__builtin_object_size;
pub const memset_chk = std.zig.c_builtins.__builtin___memset_chk;
pub const useconds_t = c_uint;