Skip to content

Instantly share code, notes, and snippets.

@mlen
mlen / config.ru
Created February 16, 2012 12:52
Super stupid simple rack app to make livereload work
class App
def initialize(settings = {})
@defaults = {:root_path => ".", :type => "text/plain", :file => "index.html"}
@defaults.merge(settings)
end
def call(env)
file = env['REQUEST_PATH'] == '/'? @defaults[:file] : env['REQUEST_PATH']
[
200,
// clang++ -std=c++11 -stdlib=libc++ main.cpp
#include <thread>
#include <vector>
#include <iostream>
using namespace std;
template <typename T> class sum {
vector<T> &v;
T &r;
@mlen
mlen / gen.rb
Last active October 9, 2015 08:44
quine generator in ruby
head = "#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
char *s = "
@mlen
mlen / function.rb
Created December 15, 2012 08:55 — forked from rf-/function.rb
def self.method_missing(name, *args)
name
end
def function(*param_names, &block)
klass = Class.new { attr_accessor :this, *param_names }
this = TOPLEVEL_BINDING.eval('self')
proc do |*params|
context = klass.new
#!/usr/bin/env bash
#
# Usage
# bash compare-gem.sh GEMNAME GEMVERSION GEMPLATFORM
#
# Return value: 0 when the gem is OK, 1 when there was a mismatch
#
# Note: it requires that the gem being checked is installed on your local system
# in $GEM_HOME
@mlen
mlen / gist:5284679
Last active December 15, 2015 15:49

Testing standard streams in Python

I was testing a program that took N lines of input, manipulated them somehow and returned M lines of output. To test it properly I wanted to test both the internal interface and the external interface.

The main function looked something like this:

import sys
# -*- mode: ruby -*-
# vi: set ft=ruby :
#
Vagrant.configure("2") do |config|
config.vm.box = "precise64"
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = ".."
chef.add_recipe File.basename(File.dirname(__FILE__))
@mlen
mlen / makefile
Last active December 17, 2015 12:09 — forked from anonymous/makefile
Shellcode testbed. Works on Debian 7
test: test.c test.h
gcc -o test test.c
test.h: test.bin
xxd -i test.bin > test.h
test.bin: test.s
nasm -f bin -o test.bin test.s
clean:
sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage.original
# for Mountain Lion 10.8.3 - 10.8.4
sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x54)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
# for Mountain Lion 10.8.1-10.8.2 and Lion 10.7.5
#sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x4D)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2|sg' /System/Library/Extensions/IOAHCIFamily.kext/Contents/PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage
# for Mountain Lion 10.8.0 and Lion 10.7.4 BELOW
#sudo perl -pi -e 's|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C\x00{1,20})[^\x00]{9}(\x00{1,20}\x51)|
import System.MIDI
import System.MIDI.Utility
import Control.Concurrent
import Control.Monad
import Data.Maybe
import Data.IORef
import Data.Tuple
import Data.Map hiding (filter, map)
import Prelude hiding (lookup, null)