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
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 (
"bytes"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httptrace"
@mrnugget
mrnugget / steve_yegge_notes_mystery_machine_bus.md
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)
View steve_yegge_notes_mystery_machine_bus.md

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
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 (
"bytes"
+ "fmt"
"strings"
@mrnugget
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);
View Brewfile.rb
# vim: set ft=ruby
cask_args appdir: '/Applications'
tap 'homebrew/cask'
brew 'mas'
brew 'git'
brew 'zsh'
brew 'make'
@mrnugget
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]
View go_module_jitting.go
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"plugin"
@mrnugget
mrnugget / go_jit.go
Created Aug 17, 2018
JITting a function that writes the letter 'H' to a bytes buffer
View go_jit.go
package main
import (
"bytes"
"fmt"
"github.com/nelhage/gojit"
"github.com/nelhage/gojit/amd64"
)
@mrnugget
mrnugget / pipe_to_jq.el
Last active Jun 27, 2018
This binds `<leader>jq` to a command that pipes the current visual selection in evil-mode to `jq` and replaces it with the output.
View pipe_to_jq.el
;; Taken from here: https://emacs.stackexchange.com/questions/34894/how-to-execute-a-command-on-the-selection-shell-command-on-region-in-evil-mode
(defun shell-command-on-region-and-select
(start end command
&optional output-buffer replace
error-buffer display-error-buffer
region-noncontiguous-p)
"Wrapper for 'shell-command-on-region', re-selecting the output.
Useful when called with a selection, so it can be modified in-place"
(interactive)
@mrnugget
mrnugget / interpreter_to_compiler.md
Last active May 17, 2019
So you're finished with "Writing An Interpreter In Go" and want to read more?
View interpreter_to_compiler.md

This is what I once wrote to a reader:

  • Nand2Tetris book - http://www.nand2tetris.org/
  • 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: https://github.com/namin/inc\
  • 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: http://compilers.iecc.com/crenshaw/tutorfinal.pdf
  • 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.
You can’t perform that action at this time.