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 / fenster_munching_squares.c
Created May 25, 2024 13:28
Munching squares example for Fenster
#include "fenster.h"
#define W 1920
#define H 1080
static void fenster_rect(struct fenster *f, int x, int y, int w, int h, uint32_t c) {
for (int row = 0; row < h; row++) {
for (int col = 0; col < w; col++) {
fenster_pixel(f, x + col, y + row) = c;
}
@peterhellberg
peterhellberg / vim-edit-over-http.go
Last active May 20, 2024 09:39
Edit file in Vim over HTTP GET and PUT
package main
import (
"io"
"log"
"net/http"
"os"
"sync"
)
@peterhellberg
peterhellberg / build.zig
Last active March 23, 2024 04:55
Example of using a current (as of 2023-12-01) version of Zig ⚡ to build a cart for the Gamercade fantasy console. https://gamercade.io
const std = @import("std");
pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{
.name = "cart",
.root_source_file = .{ .path = "src/main.zig" },
.target = .{ .cpu_arch = .wasm32, .os_tag = .wasi },
.optimize = .ReleaseSmall,
});
@peterhellberg
peterhellberg / pro-prisundersokning-graph.go
Created September 29, 2023 14:34
Using go-chart to generate a graph based on the PRO Prisundersökning data converted using https://gist.github.com/peterhellberg/ceed862a83c29a80b5bbd4631c24fb27
package main
import (
"encoding/json"
"fmt"
"os"
"strings"
_ "embed"
@peterhellberg
peterhellberg / pro-prisundersokning.go
Last active February 19, 2024 08:25
Conversion of the "PRO Prisundersökning" from XLSX to CSV, JSON,NDJSON
package main
import (
"encoding/csv"
"encoding/json"
"flag"
"fmt"
"io"
"net/http"
"os"
@peterhellberg
peterhellberg / minimal-htmx-todo.go
Last active December 28, 2023 18:48
A single Go file HTMX Todo list example, using no third party Go dependencies.
package main
import (
"context"
"crypto/rand"
"encoding/hex"
"fmt"
"html/template"
"net/http"
"os"
@peterhellberg
peterhellberg / .gitignore
Last active November 28, 2023 13:55
Compiling Zig to WASI, then calling it from Go using Wazero (https://ziglang.org, https://go.dev, https://wazero.io)
zig-cache
bin
@peterhellberg
peterhellberg / pp.zig
Created November 15, 2023 22:12
tic: Pixel position and color using the mouse
const tic = @import("tic");
fn pp(c: u8) void {
var m: tic.MouseData = .{};
tic.mouse(&m);
if (m.left) {
const x = m.x - 1;
const y = m.y - 1;
const tic = @import("tic80.zig");
const Rainbow = struct {
red: u8 = 255,
grn: u8 = 0,
blu: u8 = 0,
cyRG: bool = true,
cyGB: bool = false,
cyBR: bool = false,
const math = @import("std").math;
const tic = @import("tic80.zig");
export fn BDR(row: i32) void {
const urow: u8 = @intCast(row);
{ // skygradient
scanline(0x42, 0xFF -| urow, 0x99 +| urow);
}