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 / C-Compilation-Process-Essentials.typ
Last active September 13, 2024 09:50
Trying out the cram-snap template for Typst
#import "@preview/cram-snap:0.1.0": cram-snap
#set page(
paper: "a3",
flipped: true,
margin: 1cm,
)
#set text(font: "Inter", weight: "regular", size: 8pt)
@peterhellberg
peterhellberg / build.zig
Last active September 11, 2024 16:00
A WebAssembly plugin for Typst
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.resolveTargetQuery(.{
.cpu_arch = .wasm32,
.os_tag = .freestanding,
});
const hello = b.addExecutable(.{
.name = "hello",
@peterhellberg
peterhellberg / dos.zig
Created September 9, 2024 08:34
Example of using dos-like from Zig
const std = @import("std");
const c = @cImport({
@cInclude("dos.h");
});
pub const videomode_40x25_8x8: usize = 0;
pub const videomode_40x25_9x16: usize = 1;
pub const videomode_80x25_8x8: usize = 2;
pub const videomode_80x25_8x16: usize = 3;
@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 / .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);
}