This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function parse_git_branch { | |
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' | |
} | |
export PS1="\t:\w\$(parse_git_branch)>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Full screen mode for MacVim | |
"======================= | |
" To run MacVim in this mode from the commandline, put this whole thing into a file focus.vim and type: | |
" | |
" > mvim -S focus.vim | |
" | |
" Original tweaked from http://www.chendry.org/2009/04/22/writeroom-vim-style.html | |
set lines=40 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Examples | |
# {:foo => [1,2,3,4]} - {:foo => [1,2]} | |
# results in {:foo => [3,4]} | |
# | |
# {:bar => {:baz => [8,9]}, :buz => "deleteme"} - {:bar => 8, :buz => "deleteme"} | |
# results in {:bar => {:baz => [9]}, :buz => nil} | |
# | |
class Hash | |
def - (h) | |
self.merge(h) do |k, old, new| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef BOOL (^BooleanBlock)(id obj); // Returns true or false given an object | |
typedef id (^ValueBlock)(id obj); // Returns an object given an object (generally of the same type, may or may not be modified) | |
typedef id (^AccumulatorBlock)(id acc, id obj); // Returns the accumulator object, likely mutated. | |
// A few ruby-like list comprehensions. | |
@implementation NSArray (ListComprehensions) | |
// Returns the first object for which the block returns true. AKA array.match() | |
-(id) find:(BooleanBlock)block { | |
NSUInteger index = [self indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "RoundedRect.h" | |
@implementation RoundedRect | |
-(id) initWithFrame:(CGRect)frame { | |
self = [super initWithFrame:frame]; | |
if (self != nil) { | |
[self drawBackground]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define DEBUG_ON // Set to DEBUG_OFF to toggle | |
#ifdef DEBUG_ON | |
#define debug(format, ...) CFShow((__bridge void *)[NSString stringWithFormat:format, ## __VA_ARGS__]); | |
#else | |
#define debug(format, ...) | |
#endif | |
#define debugRect(rect) debug(@"%s x:%.2f, y:%.2f, h:%.2f, w:%.2f", #rect, rect.origin.x, rect.origin.y, rect.size.height, rect.size.width) | |
#define debugSize(size) debug(@"%s h:%.2f, w:%.2f", #size, size.height, size.width) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
= NAME | |
trie - prefix tree for query suggestions | |
= SYNOPSIS | |
trie = Trie.new | |
trie.push('my query term', 'my query term suggestion') | |
trie.push('my other query term', 'my other query term suggestion') | |
hits1 = trie.find('my') | |
pp hits1 # 2 hits |