Skip to content

Instantly share code, notes, and snippets.

View mrnugget's full-sized avatar

Thorsten Ball mrnugget

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / 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
@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 / 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>