Skip to content

Instantly share code, notes, and snippets.

View boj's full-sized avatar

Brian Jones boj

  • Eagle River, Alaska
View GitHub Profile
@boj
boj / blog_zig_piece_table.md
Last active October 10, 2024 19:21
Zig Piece Table

Introduction

Inspired by the 300k USD Donation Pledged by Mitchell Hashimoto I decided to finally give Zig a look and see what all the fuss is about. I was curious what people meant by the simplicity of using something called "a modern C replacement". Rust has satisfied my low-level programming with safety itch, but people aren't wrong when they say it's a complicated language. What does a simple language look like in 2024?

Naturally, the first step to testing a language is finding a suitable project or domain to tackle. I love command line tools, and while it seems incredibly cliche, I've made it my goal to write a text editor of sorts. A true programmer's trial of ascension.

One of the first problems that needs solved when building a text editor is the matter of how you store and represent the text internally. There's a lot of naive approaches, such as storing each character in an array, or each line in a 2d array. However, those methods can be very in

{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Lens
import GHC.Generics
@boj
boj / Main.hs
Last active March 27, 2020 21:42
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Data.Coerce
@boj
boj / Main.hs
Last active March 27, 2020 21:07
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Data.Coerce
import Data.Tagged
data Validated
module Main where
import Data.Coerce
data Validated
data Unvalidated
class AbstractError e
data MyError = MyError String deriving (Show)
@boj
boj / shell.nix
Created February 29, 2020 00:38
Shell for hacking on Haskell Servant
{ compiler ? "ghc844" }:
let
nixpkgs = import <nixpkgs> {};
inherit (nixpkgs) pkgs stdenv;
in
# Make a new "derivation" that represents our shell
stdenv.mkDerivation {
name = "servant-dev";
@boj
boj / TypeSafe.hs
Last active February 3, 2020 22:30
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RecordWildCards #-}
module Main where
--------------------------------------------------------------------------------
import Data.Coerce
import Data.Foldable
--------------------------------------------------------------------------------
@boj
boj / shell.nix
Created July 18, 2019 18:06
Example shell.nix for Haskell dev
{ compiler ? "ghc865" }:
let
nixpkgs = import <nixpkgs> {};
inherit (nixpkgs) pkgs stdenv;
in
# Make a new "derivation" that represents our shell
stdenv.mkDerivation {
name = "communication-dev";
# don't trigger on branch
trigger:
branches:
exclude:
- '*'
# trigger on pr
pr:
autoCancel: true
branches:
@boj
boj / Main.asm
Created May 22, 2019 17:31
ghc -ddump-asm Main.hs
==================== Asm code ====================
.section .rodata.str,"aMS",@progbits,1
.align 1
.align 1
$trModule1_r1Lj_bytes:
.asciz "main"
==================== Asm code ====================