Skip to content

Instantly share code, notes, and snippets.

View Pegolon's full-sized avatar

Markus Kirschner Pegolon

View GitHub Profile
@Pegolon
Pegolon / ViewFactory.h
Created November 15, 2008 18:51
Header for ViewFactory
@interface ViewFactory : NSObject {
NSMutableDictionary * viewTemplateStore;
}
- (id) initWithNib:(NSString*)aNibName;
- (UITableViewCell*)cellOfKind:(NSString*)theCellKind forTable:(UITableView*)aTableView;
@end
@Pegolon
Pegolon / ViewFactory.m
Created November 15, 2008 19:05
ViewFactory for using UITableViewCell in Interface Builder
#import "ViewFactory.h"
@implementation ViewFactory
- (id) initWithNib:(NSString*)aNibName
{
if (self == [super init]) {
viewTemplateStore = [[NSMutableDictionary alloc] init];
NSArray * templates = [[NSBundle mainBundle] loadNibNamed:aNibName owner:self options:nil];
for (id template in templates) {
hdiutil convert /path/to/filename.dmg -format UDTO -o /path/to/savefile.iso
\b(([\w-]+://?|www[.])[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/)))
@Pegolon
Pegolon / show_branch_prompt.sh
Created January 7, 2011 10:10
Shows the current branch of a git or mercurial repository as the last part of your command line prompt
function parse_branch {
local BRANCH=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')
if [ -z "$BRANCH" ]
then
BRANCH=$(hg branch 2>/dev/null)
if [ -n "$BRANCH" ]
then
BRANCH="("$BRANCH")"
fi
fi
@Pegolon
Pegolon / Repair a corrupt sqlite database
Created March 15, 2011 18:38
If you get an error like SQLite error code:11, 'database disk image is malformed' you can try to dump and reload the database with these commands
cd "$DATABASE_LOCATION"
echo '.dump'|sqlite3 $DB_NAME|sqlite3 repaired_$DB_NAME
mv $DB_NAME corrupt_$DB_NAME
mv repaired_$DB_NAME $DB_NAME
@Pegolon
Pegolon / Count lines of code
Created March 29, 2011 12:19
Find all header and implementation files and count the loc
find Classes -name '*.[hmM]' -print0|xargs -0 wc -l
@Pegolon
Pegolon / gist:1550345
Created January 2, 2012 11:26
Remove extra space from ObjC method signature
Find: ^([+-] \(.* \*\))( )
Replace: \1
@Pegolon
Pegolon / gist:1646742
Created January 20, 2012 11:14
Use a semaphore to block an asynchronous call
__block dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[self callAsyncBlock:^() {
// Do some work
dispatch_semaphore_signal(semaphore);
}];
// Wait until the semaphore has been signaled
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
dispatch_release(semaphore);
@Pegolon
Pegolon / gist:1851436
Created February 17, 2012 07:02
Showing clang predefined macros
> find /Applications/Xcode.app -name clang
# Pick one
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c /dev/null -dM -E