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 / 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)
{
@mrnugget
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 (
"database/sql"
"fmt"
"log"
"math/rand"
"sync"
"time"
@mrnugget
mrnugget / expect_to_receive_spec.rb
Last active Mar 3, 2016
How do I expect to receive a message (maybe multiple times) and the arguments I specified have to be provided once?
View expect_to_receive_spec.rb
class MyWorker
def self.perform_at(timestamp, job_name)
end
end
describe 'expecting multiple calls to same method' do
it 'works if only one call is made to the method' do
time_now = Time.now
expect(MyWorker).to receive(:perform_at).with(time_now, 'dowork')
@mrnugget
mrnugget / sort_by_bug.rb
Last active Feb 1, 2016
Ruby 2.3 - sort_by "Bug" on OS X and Linux. The behaviour of `sort_by` has changed with Ruby 2.3 on OS X if the block passed to `sort_by` returns the same value for multiple values.
View sort_by_bug.rb
# Ruby 2.3.0 - OS X
`uname -a`
# => "Darwin keef.local 15.3.0 Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64\n"
puts RUBY_VERSION
# 2.3.0
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].sort_by {|element| nil }
# => [10, 2, 3, 4, 5, 6, 7, 8, 9, 1] --- First and last elements swapped
# Ruby 2.3.0 - Linux
irb(main):001:0> `uname -a`
@mrnugget
mrnugget / private.xml
Created Dec 3, 2015
private.xml for Karabiner.app to map F15 to the OS X Emoji Menu
View private.xml
<?xml version="1.0"?>
<root>
<item>
<name>Emoji Menu</name>
<appendix>Map Pause/F15 to Control+Cmd+Space</appendix>
<identifier>private.emoji_menu_f15</identifier>
<autogen>
__KeyToKey__
KeyCode::F15,
KeyCode::SPACE, ModifierFlag::COMMAND_L | ModifierFlag::CONTROL_L
You can’t perform that action at this time.