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 / accessors.st
Created December 8, 2008 18:28
Smalltalk
"Extensions for making writing classes with accessors a bit less verbose"
ClassDescription extend [
accessors: aString [
self readers: aString.
self writers: aString.
]
readers: aString [
aString substrings do: [:ivar |
# prevent the use of `` in tests
Spec::Runner.configure do |configuration|
backtick = nil # establish the variable in this scope
saved_system = nil
configuration.prepend_before(:all) do
# raise an exception if Kernel#` or Kernel#system is used
# in our tests, we want to ensure we're fully self-contained
Kernel.instance_eval do
backtick = instance_method(:'`')
saved_system = instance_method(:system)
@mkhl
mkhl / creation-time.sh
Created December 28, 2008 02:11
File Creation Date via `mdls`
# Find out a files "creation time"
# Source: http://inessential.com/?comments=1&postid=3576
mdls -name kMDItemContentCreationDate -raw #{f}
@mkhl
mkhl / GetCurrentURL.rb
Created February 7, 2009 14:30
Insert the Current URL of the default browser. For use with ThisService.
#!/usr/bin/env ruby -rubygems
# Unicode considerations:
# Set $KCODE to 'u'. This makes STDIN and STDOUT both act as containing UTF-8.
$KCODE = 'u'
# Since any Ruby version before 1.9 doesn't much care for Unicode,
# patch in a new String#utf8_length method that returns the correct length
# for UTF-8 strings.
UNICODE_COMPETENT = ((RUBY_VERSION)[0..2].to_f > 1.8)
@mkhl
mkhl / mkhl-yasnippet.el
Created April 2, 2009 22:51
Disable yasnippet expansion when in indentation
(eval-after-load "yasnippet-bundle"
'(defadvice yas/expand (around mkhl-yas/expand-or-indent)
(let ((in-indentation? (looking-back (rx bol (0+ blank)))))
(if in-indentation?
(funcall (or (lookup-key (current-local-map) yas/trigger-key)
(lookup-key (current-global-map) yas/trigger-key)))
ad-do-it))))
// Getting Loaded
// Source: http://googlemac.blogspot.com/2006/11/getting-loaded.html
@implementation Foo (FooBarAdditions)
...
@end
@interface Foo (FooBarAdditionsPrivateMethods)
+ (void) initializeBar;
@end
@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
@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 / 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 / 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=":"