Skip to content

Instantly share code, notes, and snippets.


Mitchell Hashimoto mitchellh

View GitHub Profile
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");
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 / 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
mitchellh / flatpak.zig
Last active March 2, 2023 18:57
Zig + GLib API for detecting Flatpak and executing host processes.
View flatpak.zig
const std = @import("std");
const assert = std.debug.assert;
const Allocator = std.mem.Allocator;
const builtin = @import("builtin");
const log = std.log.scoped(.flatpak);
/// Returns true if we're running in a Flatpak environment.
pub fn isFlatpak() bool {
return if (std.fs.accessAbsolute("/.flatpak-info", .{})) true else |_| false;
mitchellh / heap.zig
Last active March 14, 2023 16:39
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 April 11, 2023 22:31
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 December 22, 2022 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 / vmware-guest.diff
Created October 20, 2021 00:08
aarch64: vmmouse and vmware video driver not yet working, but shared folders and copy & paste do work!
View vmware-guest.diff
diff --git a/machines/vm-arch/aarch64-linux.nix b/machines/vm-arch/aarch64-linux.nix
index 7944fbc..932ce99 100644
--- a/machines/vm-arch/aarch64-linux.nix
+++ b/machines/vm-arch/aarch64-linux.nix
@@ -9,6 +9,13 @@
+ # Disable the default module and import our override. We have
+ # customizations to make this work on aarch64.
mitchellh / RadixTrees.tla
Last active June 30, 2021 15:01
Radix tree and validation in TLA+
View RadixTrees.tla
This module contains operations for working with radix trees. A radix tree
is a data structure for efficient storage and lookup of values that often
share prefixes, typically used with strings.
A common question when I show this to people is: how do I add to the tree?
delete? update? For these, grab the Range of the tree, use set logic to
add/remove any elements, and construct a new tree with RadixTree.
For educational purposes, I've heavily commented all the operations. I
recommend using the constant expression evaluator to try the building blocks
mitchellh / example.nix
Created May 10, 2020 16:29
Nix function for creating a derivation (package) that installs binaries from
View example.nix
self: super: {
consul-bin = self.callPackage ./hashicorp-generic.nix {
name = "consul";
version = "1.7.3";
sha256 = "0k03n7h5h8miqhh3n3y47894vhwdcp8m611w55f826swmq9angl1";
# and so on...