Skip to content

Instantly share code, notes, and snippets.

View mrnugget's full-sized avatar

Thorsten Ball mrnugget

View GitHub Profile
@mrnugget
mrnugget / n
Created May 28, 2015 05:07
n - my note taking script. Using ag, selecta and fzz.
#!/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 / routing_test.rb
Last active August 29, 2015 14:21
A failing testcase for ActionDispatch (4-2-stable) that tries to demonstrate the behaviour of routing constraints when applied to a wildcard route.
class TestGlobFormatConstraints < ActionDispatch::IntegrationTest
Routes = ActionDispatch::Routing::RouteSet.new.tap do |app|
app.draw do
ok = lambda { |env| [200, { 'Content-Type' => 'text/plain' }, []] }
# tests fail with these:
get '/*id', to: ok, constraints: { format: 'html' }
#get '/*id', to: ok, constraints: { format: /html/ }
# tests succeed with this:
@mrnugget
mrnugget / brainfuck.c
Last active August 29, 2015 14:20
Simple brainfuck interpreter in 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 / brainfuck.rb
Last active August 29, 2015 14:20
Brainfuck Interpreter in Ruby
class Brainfuck
attr_accessor :memory
attr_accessor :memory_pointer
attr_accessor :code
attr_accessor :ip
attr_accessor :input
attr_accessor :output
@mrnugget
mrnugget / hall_of_blame.sh
Created February 13, 2015 15:12
The Hall Of Blame - Find out who put the most TODOs in the codebase.
#!/bin/bash
# ag is the_silver_searcher (https://github.com/ggreer/the_silver_searcher)
ag TODO | while read line; do
file=$(echo ${line} | awk -F ':' '{print $1}');
lineno=$(echo ${line} | awk -F ':' '{print $2}');
git blame --line-porcelain "./${file}" -L ${lineno},${lineno} | grep author-mail | cut -d ' ' -f 2;
done | sort | uniq -c
@mrnugget
mrnugget / fzz.vim
Last active August 29, 2015 14:11
fzz.vim - Use fzz and the_silver_searcher in Vim.
function! Fzz(...)
let l:fzz_executable = "fzz"
if !executable(l:fzz_executable)
echoe "Fzz command '" . l:fzz_executable . "' not found. Is in your $PATH?"
return
endif
let l:ag_cmd = "ag --nogroup --nocolor"
let l:ag_executable = get(split(l:ag_cmd, " "), 0)
if !executable(l:ag_executable)
@mrnugget
mrnugget / 01_before.rb
Created November 15, 2014 17:30
Simple preforking TCP Server in Ruby in two versions
require 'socket'
sock1 = Socket.new(:INET, :STREAM)
addr1 = Socket.pack_sockaddr_in(8888, '0.0.0.0')
sock1.bind(addr1)
sock1.listen(10)
sock2 = Socket.new(:INET, :STREAM)
addr2 = Socket.pack_sockaddr_in(9999, '0.0.0.0')
sock2.bind(addr2)
@mrnugget
mrnugget / Makefile
Created November 1, 2014 08:24
Dotfiles Makefile
DOTFILE_PATH := $(shell pwd)
$(HOME)/.%: %
ln -sf $(DOTFILE_PATH)/$^ $@
irb: $(HOME)/.irbrc
ack: $(HOME)/.ackrc
git: $(HOME)/.gitconfig $(HOME)/.githelpers $(HOME)/.gitignore
psql: $(HOME)/.psqlrc
zsh: $(HOME)/.zprofile
@mrnugget
mrnugget / fzzcd.sh
Created October 21, 2014 08:17
Use fzz to interactively find a file and then `cd` to the directory of the top result
cdfzz() {
local file=$(fzz find . -iname "*{{}}*" | head -n 1)
local filedir=$(dirname ${file})
cd ${filedir}
}
@mrnugget
mrnugget / fix_postgres.sh
Created October 18, 2014 10:27
Fix PostgreSQL after upgrading to Yosemite if PostgreSQL was installed via homebrew
mkdir /usr/local/var/postgres/pg_tblspc
mkdir /usr/local/var/postgres/pg_twophase
mkdir /usr/local/var/postgres/pg_stat_tmp
mkdir /usr/local/var/postgres/pg_stat