Skip to content

Instantly share code, notes, and snippets.

View mrnugget's full-sized avatar

Thorsten Ball mrnugget

View GitHub Profile
@mrnugget
mrnugget / broken_output_in_vim.md
Last active April 24, 2017 05:02
I wrote this down so people in the future know how to answer "do you know what happened to him?"

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.

#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 March 3, 2016 05:58
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.
package main
import (
"database/sql"
"fmt"
"log"
"math/rand"
"sync"
"time"
@mrnugget
mrnugget / expect_to_receive_spec.rb
Last active March 3, 2016 05:56
How do I expect to receive a message (maybe multiple times) and the arguments I specified have to be provided once?
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 February 1, 2016 15:52
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.
# 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 December 3, 2015 13:28
private.xml for Karabiner.app to map F15 to the OS X Emoji Menu
<?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
pid = fork { sleep 1 }
puts "pid=#{pid}"
sleep 3
puts "Process.waitall=#{Process.waitall}"
# Output:
# pid=52057
# Process.waitall=[[52057, #<Process::Status: pid 52057 exit 0>]]
@mrnugget
mrnugget / 01_small_hello_world_server.c
Last active August 29, 2015 14:26
Small "web server" in C to reproduce the problems I encountered with github.com/mrnugget/helles under OS X.
#ifdef __linux__
#define _XOPEN_SOURCE 700
#endif
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@mrnugget
mrnugget / n
Created July 7, 2015 07:56
n -- my note taking tool
#!/usr/bin/env bash
set -e
# Requirements:
# fzz - github.com/mrnugget/fzz
# selecta - github.com/garybernhardt/selecta
# the_silver_searcher/ag - github.com/ggreer/the_silver_searcher
# Usage:
# n [name] - Create note
@mrnugget
mrnugget / forking_rspec.rb
Last active August 29, 2015 14:22
Run RSpec tests on multiple processes at the same time
#!/usr/bin/env ruby
ENV['RAILS_ENV'] = 'test'
require 'benchmark'
rails_loading_time = Benchmark.measure { require './config/environment' }
puts "Rails env loaded in #{rails_loading_time}"
NUM_FORKS = 2
test_groups = `find ./spec -type f -iname "*foobar*"`.split("\n").in_groups(NUM_FORKS).to_a