Skip to content

Instantly share code, notes, and snippets.

Thorsten Ball mrnugget

Block or report user

Report or block mrnugget

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mrnugget / pointers_and_arrays.c
Last active Sep 27, 2019
Kind of a cheat sheet for pointers and arrays in C
View pointers_and_arrays.c
#include <stdio.h>
int main(int argc, char *argv[])
// Taken from here:
// initialize an array of ints
int numbers[5] = {1,2,3,4,5};
// standard array notation
mrnugget / go-sqlite3_database_is_locked.go
Created Mar 3, 2016
Program that tests the concurrency issues with go-sqlite3. This will create two tables: `products` and `users`. One goroutine will repeatedly read from the `products` table in N fresh goroutines. At the same time ONE goroutine writes to the other table.
View go-sqlite3_database_is_locked.go
package main
import (

Scheme x86 Compiler - Debugging wrong call


((lambda (g x) (g x)) (lambda (x) (prim-apply + 1 x)) 2)

Problem: generated code contains two functions.

mrnugget / reproduce_github_eof.go
Created Jun 4, 2019
This can be used to reproduce EOF errors while using GitHubs API, because GitHub closes keep-alive connections after 60s.
View reproduce_github_eof.go
package main
import (
mrnugget / conways.rkt
Created Nov 24, 2018
Conway's Game of Life in Racket
View conways.rkt
#lang racket
(define (make-grid rows columns)
(build-vector rows (lambda (r) (make-vector columns 0))))
(define (rows grid) (vector-length grid))
(define (columns grid) (vector-length (vector-ref grid 0)))
(define (cell grid row column)
(cond [(or (< row 0) (< column 0)) 0]
mrnugget / 01_vm_test.go
Last active May 29, 2019
Little bug in "Writing A Compiler In Go" 1.0
View 01_vm_test.go
func TestCallingRecursiveFunctionsInFunctions(t *testing.T) {
tests := []vmTestCase{
// This works
input: `
let inner = fn(x) {
if (x == 0) {
return 0;
} else {
inner(x - 1);
mrnugget /
Last active May 17, 2019
So you're finished with "Writing An Interpreter In Go" and want to read more?

This is what I once wrote to a reader:

  • Nand2Tetris book -
  • The paper "An Incremental Approach to Compiler Construction", by Abdulaziz Ghuloum. You can find a hosted PDF version of the paper and an implementation of its contents here:\
  • Jack Crenshaw's classic "LET'S BUILD A COMPILER" from 1988. Even though it's kinda dated (he's using Turbo Pascal), it's one of the great "let's roll our sleeves up and write some code" texts. Here is the PDF version:
  • Then there are also the 4th and 5th chapters of Structure an Interpretation of Computer Programs (SICP), in which you'll build an interpreter and a kinda bytecode-compiler for a virtual register machine. It's a pretty abstract and seemingly alien affair (using a Lisp dialect to build a virtual register machine for a bytecode defined in Lisp, produced by a Lisp compiler, etc.), but it teaches the concepts behind the whole compiler and VM thing.
mrnugget /
Last active Apr 2, 2019
Steve Yegge - Notes from the Mystery Machine Bus. This is a mirror of the post on Google+, kept here for safekeeping when Google+ shuts down tomorrow. (converted to Markdown by pasting it into Dropbox Paper and exporting as Markdown)

Note: I'm not the original author. That's Steve Yegge. I copied the essay here from Google+ for safekeeping before Google+ shuts down.

Author: Steve Yegge

Publication Date: 10 Aug 2012

Notes from the Mystery Machine Bus

I've spent the past eight years (starting back in June 2004) writing elaborate rants about a bunch of vaguely related software engineering issues.

mrnugget / op_get_self.diff
Last active Mar 20, 2019
Fix for recursive closures that are defined in other functions. These break in version 1.0 of "Writing A Compiler In Go". This fix adds another opcode, OpGetSelf, and emits it whenever there's a reference to the currently executed function.
View op_get_self.diff
diff --git a/ast/ast.go b/ast/ast.go
index 8db3b39..f0420f4 100644
--- a/ast/ast.go
+++ b/ast/ast.go
@@ -2,6 +2,7 @@ package ast
import (
+ "fmt"
View Brewfile.rb
# vim: set ft=ruby
cask_args appdir: '/Applications'
tap 'homebrew/cask'
brew 'mas'
brew 'git'
brew 'zsh'
brew 'make'
You can’t perform that action at this time.