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 / chroma-hash.user.js
Created August 22, 2009 14:07
Userscript for Chroma-Hash password visualization.
// ==UserScript==
// @name Chroma-Hash password visualization
// @namespace http://purl.org/net/mkhl
// @description Add Chroma-Hash visualization to all password field inputs. Compatible with Greasemonkey and GreaseKit.
// @include *
// ==/UserScript==
// Many thanks to Henrik Nyh and Mattt Thompson for doing all the hard work!
(function() {
@mkhl
mkhl / MyTestCase.m
Created August 1, 2009 16:18
Cocoa UI Unit Testing
// Cocoa UI Unit Testing
// Source: http://eschatologist.net/blog/?p=205
@interface MyTestCase : SenTestCase
@end
@implementation MyTestCase
/*! Tells whether the control sends the action to the target. */
- (BOOL)checkControl:(NSControl *)control
@mkhl
mkhl / Makefile
Created July 31, 2009 21:44
Small and generic Makefile skeleton
PROJECT=foo
SOURCES=bar.c baz.c
LIBRARY=nope
INCPATHS=../some_other_project/
LIBPATHS=../yet_another_project/
LDFLAGS=-ldosomething
CFLAGS=-c -Wall
CC=gcc
# ------------ MAGIC BEGINS HERE -------------
@mkhl
mkhl / Ellipses.m
Created July 29, 2009 23:09
Replace triple dots with proper ellipses
// Replace triple dots with proper ellipses.
// Source: http://www.mikeabdullah.net/ellipses_and_sheepkit.html
- (BOOL)textView:(EweEyeTextView *)textView
shouldChangeTextInRange:(NSRange)range
replacementText:(NSString *)text
{
BOOL result = YES;
if ([text hasSuffix:@"."]) // Accounts for somehow entering ".."
{
#!/usr/bin/env ruby -wKU -rubygems
# http://www.stompy.org/2008/08/14/xcode-and-git-another-build-script/
# I saw the script from the above URL and thought it was unnecessarily complicated.
# So I uncomplicated it.
require 'osx/plist'
File.open(File.join(ENV['BUILT_PRODUCTS_DIR'], ENV['INFOPLIST_PATH']), 'r+') do |io|
plist, format = OSX::PropertyList.load(io, true)
@mkhl
mkhl / path_helper.patch
Created June 4, 2009 08:53
Patch to `/usr/libexec/path_helper` to prevent hangs with long `PATH`s
Patch to `/usr/libexec/path_helper` to prevent hangs with long `PATH`s.
--- path_helper_bak 2009-05-07 15:54:37.000000000 +0200
+++ path_helper 2009-06-04 10:51:39.000000000 +0200
@@ -15,7 +15,7 @@
for f in "$DIR" "$DIR".d/* ; do
if [ -f "$f" ]; then
for p in $(< "$f") ; do
- [[ "$NEWPATH" = *(*:)${p}*(:*) ]] && continue
+ egrep -q "(^|${SEP})${p}($|${SEP})" <<<"$NEWPATH" && continue
[ ! -z "$NEWPATH" ] && SEP=":"
@mkhl
mkhl / snippet.rb
Created May 29, 2009 12:34
Reads a file containing Espresso snippets and turns them into TEA snippets
#!/usr/bin/env ruby -wKU -rubygems
require "nokogiri"
def to_action(text)
doc = Nokogiri::XML(text)
doc.xpath('/action-recipes/snippet').each do |node|
txt = node.at('text')
txt.remove
snippet = txt.content
@mkhl
mkhl / file.m
Created May 21, 2009 17:24
Proper Key-Value Observer Usage
// Source: http://www.dribin.org/dave/blog/archives/2008/09/24/proper_kvo_usage/
// Define a static object; strings are easily readable, which is a plus
static NSString *const kOpeningBalanceChanged = @"openingBalance changed";
// Use it for the `context` parameter when adding KVO
[object addObserver:observer
forKeyPath:@"openingBalance"
options:options
context:kOpeningBalanceChanged];
@mkhl
mkhl / file.m
Created May 21, 2009 14:58
Define a protocol MyProtocol that inherits from the NSObject protocol
// Define a protocol MyProtocol that inherits from the NSObject protocol.
// This way, calls to NSObject messages (release, retain, …) don’t warn.
// Source: http://www.mobileorchard.com/idprotocol-retainrelease-and-protocol-inheritance/
@protocol MyProtocol<NSObject>
- (void)someMessage;
@end
// Getting Loaded
// Source: http://googlemac.blogspot.com/2006/11/getting-loaded.html
@implementation Foo (FooBarAdditions)
...
@end
@interface Foo (FooBarAdditionsPrivateMethods)
+ (void) initializeBar;
@end