Skip to content

Instantly share code, notes, and snippets.

@mlen
mlen / objc-test.c
Created February 6, 2011 21:55
using objc from c
/*
* Compile with:
* gcc -g -Wall -pedantic -framework Foundation -framework ScriptingBridge -o objc-test objc-test.c
*/
#include <objc/objc-runtime.h>
#include <stdlib.h>
#include <stdio.h>
void listClasses() {
@mlen
mlen / test.rb
Created February 9, 2011 19:37
Calling privilidged methods from sandbox ($SAFE = 4)
#!/usr/bin/env ruby
class Sandbox
@@call = -> this, method, *args do
this.method(method).call(*args)
end
def self.method_added name
super
@mlen
mlen / p59.rb
Created September 23, 2011 21:21
Problem 59 from projecteuler.net
# I'm too lazy to load this from a file
ciphertext = [79,59,12,2,79,35,8,28,20,2,3,68,8,9,68,45,0,12,9,67,68,4,7,5,23,
27,1,21,79,85,78,79,85,71,38,10,71,27,12,2,79,6,2,8,13,9,1,13,9,
8,68,19,7,1,71,56,11,21,11,68,6,3,22,2,14,0,30,79,1,31,6,23,19,10,
0,73,79,44,2,79,19,6,28,68,16,6,16,15,79,35,8,11,72,71,14,10,3,79,
12,2,79,19,6,28,68,32,0,0,73,79,86,71,39,1,71,24,5,20,79,13,9,79,
16,15,10,68,5,10,3,14,1,10,14,1,3,71,24,13,19,7,68,32,0,0,73,79,
87,71,39,1,71,12,22,2,14,16,2,11,68,2,25,1,21,22,16,15,6,10,0,79,
16,15,10,22,2,79,13,20,65,68,41,0,16,15,6,10,0,79,1,31,6,23,19,28,
68,19,7,5,19,79,12,2,79,0,14,11,10,64,27,68,10,14,15,2,65,68,83,
@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 / 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
@mlen
mlen / flac2alac
Last active May 8, 2024 15:36
FLAC to ALAC converter. Requires Mac OS X and `flac` binary installed (ie. via Homebrew: `brew install flac`).
#!/usr/bin/env bash
set -e
convert_to_alac() {
flac="$1"
aiff="${flac%.*}.aiff"
alac="${flac%.*}.m4a"
flac -s -d --force-aiff-format -o "$aiff" "$flac"
afconvert -f m4af -d alac "$aiff" "$alac"
@mlen
mlen / audio-ping.sh
Created January 11, 2013 18:01
Ping with audio output!
audio-ping() {
ping $* 1>&2 |
while read; do say "ping"; done
}
#!/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