Skip to content

Instantly share code, notes, and snippets.

View mrnugget's full-sized avatar

Thorsten Ball mrnugget

View GitHub Profile
# vim: set ft=ruby
cask_args appdir: '/Applications'
tap 'homebrew/cask'
brew 'mas'
brew 'git'
brew 'zsh'
brew 'make'
@mrnugget
mrnugget / conways.rkt
Created November 24, 2018 14:13
Conway's Game of Life in Racket
#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]
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"plugin"
@mrnugget
mrnugget / go_jit.go
Created August 17, 2018 15:18
JITting a function that writes the letter 'H' to a bytes buffer
package main
import (
"bytes"
"fmt"
"github.com/nelhage/gojit"
"github.com/nelhage/gojit/amd64"
)
@mrnugget
mrnugget / pipe_to_jq.el
Last active June 27, 2018 11:10
This binds `<leader>jq` to a command that pipes the current visual selection in evil-mode to `jq` and replaces it with the output.
;; 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 June 3, 2023 11:59
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 - 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.
@mrnugget
mrnugget / fix_rails_migration.md
Created September 8, 2017 09:06
Fixing a Rails migration in a previous commit

Fixing a Rails migration in a previous commit

Status Quo

We're sitting on a commit and a previous commit introduced a migration. The migration and the resulting db/structure.sql (or db/schema.rb) have been commited in <commit-to-be-fixed>.

Problem

@mrnugget
mrnugget / foobar.go
Created July 26, 2017 04:59
Using test helpers in Go -- how do I know which test failed with vim-go?
package main
func AddTwo(input int) int {
return input + 2
}
func AddFour(input int) int {
return input + 4
}
@mrnugget
mrnugget / parse_fat_arrow_functions_monkey.patch
Last active July 18, 2017 16:19
These changes add support for fat arrow functions to Monkey's parser. E.g. `(a, b) => { a + b }`. The current implementation expects that the body is a block statement, i.e. it needs curly braces.
diff --git src/monkey/ast/ast.go src/monkey/ast/ast.go
index fb30b05..70668a6 100644
--- src/monkey/ast/ast.go
+++ src/monkey/ast/ast.go
@@ -337,3 +337,28 @@ func (hl *HashLiteral) String() string {
return out.String()
}
+
+type FatArrowFunction struct {
@mrnugget
mrnugget / markdown-toc.rkt
Created June 10, 2017 13:29
Reads a markdown file from STDIN and outputs the TOC to STDOUT. Install Racket to run it.
#!/usr/bin/env racket
#lang racket
(define (contains-heading? line)
(regexp-match #rx"^#+" line))
(define (heading-level line)
(length (regexp-match* #rx"#" line)))