Skip to content

Instantly share code, notes, and snippets.

View mdippery's full-sized avatar
💭
Have you seen an older me go by in a time machine?

Michael Dippery mdippery

💭
Have you seen an older me go by in a time machine?
View GitHub Profile
#import <Foundation/Foundation.h>
#import <stdio.h>
int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *s1 = @"foo";
NSString *s2 = @"foo";
NSString *s3 = [[NSString alloc] initWithString:@"foo"];
#import <Foundation/Foundation.h>
int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *json = @"DUMMY({parameters:{code:\"60246\", language:\"en\", country:\"en\"}, result:{\"...JSON...});";
NSUInteger rangeStart = [json rangeOfString:@"result:"].location;
NSUInteger lastBrace = [json rangeOfString:@"}" options:NSBackwardsSearch].location;
NSUInteger jsonStart = rangeStart + [@"result:" length];
#import <Foundation/Foundation.h>
int main(int argc, char **argv)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *json = @"DUMMY({parameters:{code:\"60246\", language:\"en\", country:\"en\"}, result:{\"...JSON...});";
NSUInteger rangeStart = [json rangeOfString:@"result:"].location;
NSString *justJson = [json substringFromIndex:rangeStart + [@"range:" length]];
NSUInteger lastBrace = [justJson rangeOfString:@"}" options:NSBackwardsSearch].location;
#include <stdio.h>
struct base {
int foo;
};
struct derived {
int foo;
char *bar;
};
@mdippery
mdippery / fabric.sh
Created October 4, 2010 19:22
A bash completion script for Fabric targets
# A bash completion script for Fabric targets
# Author: Michael Dippery <[email protected]>
_complete_fabric() {
COMPREPLY=()
if [ -e ./fabfile.py ]; then
local targets=$(fab -l | sed '1,2d' | awk '{print $1}')
local cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${targets}" -- ${cur}) )
fi
@mdippery
mdippery / book.m
Created October 28, 2010 18:11
An example of using @dynamic properties in Objective-C
#import <Foundation/Foundation.h>
@interface Book : NSObject
{
NSMutableDictionary *data;
}
@property (retain) NSString *title;
@property (retain) NSString *author;
@end
@mdippery
mdippery / fail.c
Created November 19, 2010 20:10
For those times when you type `fail -t` instead of `tail -f`
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(int argc, char **argv)
{
int i;
fprintf(stderr,
" FAIL WHALE! \n"
@mdippery
mdippery / NSNullCheck.m
Created November 19, 2010 22:40
Rails' nil?, for Objective-C
#import <Foundation/Foundation.h>
@interface NSObject (NSNullCheck)
- (BOOL)isNull;
@end
@implementation NSObject (NSNullCheck)
- (BOOL)isNull { return NO; }
@end
@mdippery
mdippery / FileTailer.m
Created January 12, 2011 23:02
A class that mimics `tail -f`
//
// Created by Michael Dippery on 1/12/2011.
// Copyright 2011 Michael Dippery. All rights reserved.
//
#import "FileTailer.h"
@implementation FileTailer
- (id)initWithPath:(NSString *)path refreshPeriod:(NSTimeInterval)aRefresh
@mdippery
mdippery / NSString+Random.h
Created February 8, 2011 15:34
Generate random strings in Objective-C
/*
* Copyright (C) 2011 Michael Dippery <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*