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
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 Jan 6, 2020
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.
@mrnugget
mrnugget / fix_rails_migration.md
Created Sep 8, 2017
Fixing a Rails migration in a previous commit
View fix_rails_migration.md

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 Jul 26, 2017
Using test helpers in Go -- how do I know which test failed with vim-go?
View foobar.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 Jul 18, 2017
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.
View parse_fat_arrow_functions_monkey.patch
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 Jun 10, 2017
Reads a markdown file from STDIN and outputs the TOC to STDOUT. Install Racket to run it.
View markdown-toc.rkt
#!/usr/bin/env racket
#lang racket
(define (contains-heading? line)
(regexp-match #rx"^#+" line))
(define (heading-level line)
(length (regexp-match* #rx"#" line)))
@mrnugget
mrnugget / broken_output_in_vim.md
Last active Apr 24, 2017
I wrote this down so people in the future know how to answer "do you know what happened to him?"
View broken_output_in_vim.md

RSpec output in Vim broken

Tests are run with vim-dispatch and this command:

:Dispatch bundle exec rspec spec/path/to/file_spec.rb

vim-dispatch creates a new tmux pane where it runs the command. The output of the command is fed to Vim.

Problem

Sometimes the STDOUT output produced by bundle exec rspec is malformed. Lines are missing, or merged together.

View brainfuck.c
#include <string.h>
#include <stdio.h>
#define MEM_SIZE 30000
char mem[MEM_SIZE] = {0};
char *memp = mem;
void bf_eval(char *code, int len, FILE *in, FILE *out)
{
You can’t perform that action at this time.