Skip to content

Instantly share code, notes, and snippets.

View asmallteapot's full-sized avatar
😴
😴

Ellen Teapot asmallteapot

😴
😴
View GitHub Profile
@brentsimmons
brentsimmons / EmptyChecks.m
Created July 28, 2012 19:06
Checking if an object is empty
BOOL RSIsEmpty(id obj) {
return obj == nil || obj == [NSNull null] || ([obj respondsToSelector:@selector(length)] && [(NSData *)obj length] == 0) || ([obj respondsToSelector:@selector(count)] && [obj count] == 0);
}
BOOL RSStringIsEmpty(NSString *s) {
/*22 Feb. 2011: added NSNull check. JSON parser can put a null where we expect a string, and NSNull throws an exception when checking length. Since [NSNull null] is, arguably, emptiness, it makes sense to include it.*/
return s == nil || (id)s == (id)[NSNull null] || [s length] == 0;
}
@0xced
0xced / XCDFakeCarrier.m
Last active March 5, 2023 22:07
Hack to choose the displayed carrier name in the iOS simulator
//
// Copyright (c) 2012-2015 Cédric Luthi / @0xced. All rights reserved.
//
#import <Foundation/Foundation.h>
#if TARGET_OS_SIMULATOR
static const char *fakeCarrier;
static const char *fakeTime;
@henrik
henrik / prawndown.coffee
Created May 23, 2012 13:48
Prawndown! Super-tiny subset of Markdown for use with the Prawn PDF lib.
class Prawndown
constructor: (@text) ->
toPrawn: ->
@text.
replace(/\n/g, "<br>\n").
replace(/^# (.+)/gm, "<b>$1</b>")
# Use:
console.log (new Prawndown("# Foo\nbar")).toPrawn()
@alloy
alloy / KWChangeMatcher.h
Created April 12, 2012 14:36
An ‘assert difference’ type of matcher for Kiwi.
#import <Kiwi/KWMatcher.h>
typedef NSInteger (^KWChangeMatcherCountBlock_t)();
@interface KWChangeMatcher : KWMatcher {
@private
BOOL anyChange;
NSInteger expectedDifference, expectedTotal, actualTotal;
KWChangeMatcherCountBlock_t countBlock;
}
@iamleeg
iamleeg / pileOfPoo.m
Created March 22, 2012 01:51
The pile of poo Objective-C method
#import <Foundation/Foundation.h>
@interface A: NSObject
@end
@implementation A
void pileOfPoo(id self, SEL _cmd) {
NSLog(@"💩");
}
@ttscoff
ttscoff / massnippet.txt
Created March 18, 2012 20:52
Auto-redeem link for Mac App Store promo codes
macappstores://buy.itunes.apple.com/WebObjects/MZFinance.woa/wa/redeemLandingPage?code=XXXXXXXXX
@asmallteapot
asmallteapot / gist:1664575
Created January 23, 2012 18:07
Using C99 for clever and non-fragile UITableView configuration. Allows implicit defaults. Copypasta’d from a screencap tweeted by @jonsterling: http://twitpic.com/80uyfp
typedef enum {
kAccomplishmentTitleSection = 0,
kAccomplishmentCategorySection,
kNumberOfSections
} NESTemplateEditTableSections;
static NSString * const kCellIdentifiers[] = {
[kAccomplishmentTitleSection] = @"AccomplishmentTitleCell",
[kAccomplishmentCategorySection] = @"AccomplishmentCategoryCell"
};
@panicsteve
panicsteve / gist:1641705
Created January 19, 2012 18:26
Form letter template for acquired startups
Dear soon-to-be-former user,
We've got some fantastic news! Well, it's great news for us anyway. You, on
the other hand, are fucked.
We've just been acquired by:
[ ] Facebook
[ ] Google
[ ] Twitter
@plantpurecode
plantpurecode / NSIndexPath+JRAdditions.m
Created January 3, 2012 22:56
A handy category on NSIndexPath.
@implementation NSIndexPath (JRAdditions)
- (NSIndexPath *) indexPathByAddingRows:(NSInteger)rows andSections:(NSInteger)sections {
NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:MIN(NSIntegerMax, [self row] + rows)
inSection:MIN(NSIntegerMax, [self section] + sections)];
return newIndexPath;
}
- (NSIndexPath *) indexPathByAddingRows:(NSInteger) rows {
return [self indexPathByAddingRows:rows andSections:0];
@btedev
btedev / jongify.rb
Created December 30, 2011 04:01
Make a custom Kim Jong Il funeral procession image
# Create your very own Kim Jong Il funeral magic!
# Requires ImageMagick.
# OS X: brew install imagemagick
# Ubuntu: sudo apt-get install imagemagick
#
# Background image from Dustin Fenstermacher via http://gawker.com/5871682/give-yourself-a-dictators-funeral-with-this-kim-jong+il-photoshop-template
abort 'usage: jongify.rb image_file' unless ARGV.size == 1
original_image = ARGV[0]