Skip to content

Instantly share code, notes, and snippets.

View mkhl's full-sized avatar
🖤
…at any cost

Martin Kühl mkhl

🖤
…at any cost
View GitHub Profile
@mkhl
mkhl / ansicolor
Created February 23, 2011 21:35
Generate ANSI escape sequences.
#!/usr/bin/env ruby -w
# Usage: ansicolor attr... [-- string...]
# Generate ANSI escape sequences.
# With string arguments, print them on stdout,
# followed by a `clear' escape sequence.
begin
require 'term/ansicolor'
rescue LoadError
require 'rubygems'
@mkhl
mkhl / usage
Created February 22, 2011 22:52
Simple usage information for shell scripts
#!/bin/sh
# Usage documentation and program description go here,
# nicely formatted and laid out to fit 78 columns.
# NOTE: The blank line above is the end of the file comment header.
# Check command-line options
if true; then
# Display the file comment header.
sed -n '2,/^$/s/^# //p' "$0"
@mkhl
mkhl / any2mp3
Created February 22, 2011 17:43
Convert media files to MP3 using ffmpeg and lame. With automatic tagging.
#!/usr/bin/env ruby
require 'tempfile'
opts = Hash[*%w[--tt title
--ta artist
--tl album
--ty year
--tc comment
@mkhl
mkhl / maude
Created August 6, 2010 22:32
Wrapper script to run Maude from its directory tree.
#!/usr/bin/env bash
function search-prelude {
local prelude="prelude.maude"
for dir ; do
for file in "${dir}/${prelude}" "${dir}/maude/${prelude}" "${dir}/lib/maude/${prelude}" ; do
if [[ -f "${file}" ]]; then
echo -n "$(dirname "${file}")"
return 0
fi
// Author: Marcus Zarra
// Source: http://www.cimgf.com/2010/05/02/my-current-prefix-pch-file/
#ifdef DEBUG
#define DLog(...) NSLog(@"%s %@", __PRETTY_FUNCTION__, [NSString stringWithFormat:__VA_ARGS__])
#define ALog(...) [[NSAssertionHandler currentHandler] handleFailureInFunction:[NSString stringWithCString:__PRETTY_FUNCTION__ encoding:NSUTF8StringEncoding] file:[NSString stringWithCString:__FILE__ encoding:NSUTF8StringEncoding] lineNumber:__LINE__ description:__VA_ARGS__]
#else
#define DLog(...) do { } while (0)
#ifndef NS_BLOCK_ASSERTIONS
#define NS_BLOCK_ASSERTIONS
@mkhl
mkhl / docbook-register
Created July 3, 2010 12:05
Register Homebrew-installed DocBook on Mac OS X
#!/bin/bash
# Bail out if anything goes wrong
set -e
# Make sure Homebrew and DocBook are present
which -s brew
docbook="$(brew --prefix docbook)"
test -d "$docbook"
/*
* ctrl-f1
* -------
* Query or toggle the "Full Keyboard Access" hotkey, Ctrl-F1
*
* make CC=clang CFLAGS="-framework Carbon" ctrl-f1
*/
#include <Carbon/Carbon.h>
@mkhl
mkhl / gist:446222
Created June 20, 2010 23:31
QSB on a case-sensitive filesystem
We couldn’t find that file to show.
//
// DebuggingUtilities.h
// BreakingIntoGDB
//
// Created by Alexandre Colucci on 23/08/08.
// Source: http://blog.timac.org/?p=190
//
#import <Foundation/Foundation.h>
#import <ApplicationServices/ApplicationServices.h>
// Technical Q&A QA1361
// Detecting the Debugger
// Source: http://developer.apple.com/mac/library/qa/qa2004/qa1361.html
#include <assert.h>
#include <stdbool.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/sysctl.h>