Skip to content

Instantly share code, notes, and snippets.

View mitchellh's full-sized avatar

Mitchell Hashimoto mitchellh

View GitHub Profile
mitchellh / xtgettcap.zig
Created September 28, 2023 17:43
Snippet from Ghostty source.
View xtgettcap.zig
/// Returns a ComptimeStringMap for all of the capabilities in this terminfo.
/// The value is the value that should be sent as a response to XTGETTCAP.
/// Important: the value is the FULL response included the escape sequences.
pub fn xtgettcapMap(comptime self: Source) type {
const KV = struct { []const u8, []const u8 };
// We have all of our capabilities plus To, TN, and RGB which aren't
// in the capabilities list but are query-able.
const len = self.capabilities.len + 3;
var kvs: [len]KV = .{.{ "", "" }} ** len;
mitchellh / heap.zig
Last active September 14, 2023 08:44
Zig implementation of an intrusive heap based on pairing heaps
View heap.zig
const std = @import("std");
const assert = std.debug.assert;
/// An intrusive heap implementation backed by a pairing heap[1] implementation.
/// Why? Intrusive data structures require the element type to hold the metadata
/// required for the structure, rather than an additional container structure.
/// There are numerous pros/cons that are documented well by Boost[2]. For Zig,
/// I think the primary benefits are making data structures allocation free
/// (rather, shifting allocation up to the consumer which can choose how they
mitchellh / overlay.nix
Last active September 13, 2023 03:18
Playdate SDK on Nix on aarch64
View overlay.nix
# Playdate distributes their SDK as precompiled x86_64 binaries
# currently so we have to import cross-compiled packages for it
# if we're not on an x86_64 system.
pkgsIntel = import <nixpkgs> {
crossSystem = {
config = "x86_64-unknown-linux-gnu";
mitchellh / Atlas.zig
Last active September 12, 2023 01:57
Bin-packed texture atlas implementation in Zig.
View Atlas.zig
//! Implements a texture atlas (
//! The implementation is based on "A Thousand Ways to Pack the Bin - A
//! Practical Approach to Two-Dimensional Rectangle Bin Packing" by Jukka
//! Jylänki. This specific implementation is based heavily on
//! Nicolas P. Rougier's freetype-gl project as well as Jukka's C++
//! implementation:
//! Limitations that are easy to fix, but I didn't need them:
mitchellh /
Created August 13, 2019 04:29
Originally posted on Tumblr on Feb 25, 2011.

THIS WAS ORIGINALLY POSTED ON MY TUMBLR ON FEB 25, 2011. I forgot I had a Tumblr account. I recently logged in (in light of the acquisition by Automattic), found some old posts, and I'm republishing them exactly as they were with zero modifications.

CloudFormation: The Big Picture

Amazon announced CloudFormation to the public yesterday, and while the general opinion I could glean from various sources shows that people are excited about this new technology, many are still unsure what it is and how it fits into their current cloud workflow. I feel as though I have a firm grasp on CloudFormation and will attempt to answer some questions here.

Note: I'm definitely not a representative of Amazon in any way, and anything here is simply my educated opinion on the matter.

View bug.swift
/// This is demonstrating a strange behavior that I can't explain.
/// This is a minimal SwiftUI application that renders a NSView that only implements NSTextInputClient, allowing
/// it to behave like a text input field. The implementation is minimal. Any characters you type will be logged
/// to the console wit the codepoints that are inserted. If you type "a" you should see "97" in the logs, for example.
/// 1. Launch the program with the US traditional ("US") keyboard layout.
/// 2. Type characters and notice they are logged.
/// 3. Type a control character such as enter, backspace, notice they are _not_ logged (this is fine).
/// 4. Switch to US international ("us-intl") keyboard layout.
View LibtoolStep.zig
//! A zig builder step that runs "libtool" against a list of libraries
//! in order to create a single combined static library.
const LibtoolStep = @This();
const std = @import("std");
const Step =;
const RunStep =;
const FileSource =;
pub const Options = struct {
mitchellh / Metal.zig
Created May 29, 2023 18:32
Snapshot of the Metal renderer for my terminal. Probably not very useful on its own.
View Metal.zig
//! Renderer implementation for Metal.
//! Open questions:
pub const Metal = @This();
const std = @import("std");
const builtin = @import("builtin");
const glfw = @import("glfw");
const objc = @import("objc");
mitchellh /
Last active May 10, 2023 17:25
macOS Catalina (10.15+) Notarization Requirement for Go

macOS 10.15 Catalina requires binaries are notarized to run without annoying additional steps. See the issue here: hashicorp/terraform#23033

These are steps to notarize a direct binary. This does not cover stapling, installers (pkg), etc. This is primarily useful for static binary developers such as Go developers.

Manual Steps

Apple Developer Account

You first need an Apple Developer Account ($99/year). You need to accept all the agreements and stuff.

mitchellh / json.zig
Last active April 5, 2023 21:04
Streaming JSON decoder for Zig (NOT COMPLETE!)
View json.zig
const std = @import("std");
const builtin = @import("builtin");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const ArenaAllocator = std.heap.ArenaAllocator;
const StreamingParser = std.json.StreamingParser;
const Token = std.json.Token;
const TokenTag = std.meta.FieldEnum(Token);
/// Field options are options that can be set per-field on a struct at