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
NSInteger result = 401; | |
const void *val = &result; | |
id mockResponse = [OCMockObject mockForClass:[NSHTTPURLResponse class]]; | |
[[[mockResponse stub] andReturn:[NSValue value:val withObjCType:@encode(NSInteger)]] statusCode]; |
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
/* | |
* Subclassing in this case wins over mocking | |
*/ | |
@interface MockHTTPURLResponse : NSHTTPURLResponse { | |
NSInteger statusCode; | |
} | |
@property(readwrite,nonatomic) NSInteger statusCode; | |
@end | |
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
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification | |
{ | |
NSString *path = [NSString stringWithFormat:@"%@/Music/iTunes/iTunes Library.xml", NSHomeDirectory()]; | |
NSData *xmlData; | |
NSDictionary *plist; | |
xmlData = [NSData dataWithContentsOfFile:path]; | |
NSString *error; | |
NSPropertyListFormat format; |
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
NSError *error = nil; | |
ITLibrary *library = [ITLibrary libraryWithAPIVersion:@"1.0" error:&error]; | |
if (library) | |
{ | |
NSArray *playlists = library.allPlaylists; | |
NSArray *tracks = library.allMediaItems; | |
NSLog(@"Playlists count: %lu", [playlists count]); | |
NSLog(@"Tracks count: %lu", [tracks count]); | |
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
- (NSString *)schemaFor:(NSString *)dbFile | |
{ | |
sqlite3 *db; | |
NSString *query = @"select name, sql from sqlite_master where type = 'table'"; | |
NSString *result; | |
if (sqlite3_open([dbFile UTF8String], &db) == SQLITE_OK) { | |
sqlite3_stmt *stmt; | |
if (sqlite3_prepare_v2(db, [query UTF8String], -1, &stmt, NULL) == SQLITE_OK) { | |
if (sqlite3_step(stmt) == SQLITE_ROW) { |
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
NSMutableArray *albumIDs = [[NSMutableArray alloc] initWithCapacity:1000]; | |
for (MPMediaItemCollection *collection in items) { | |
@autoreleasepool { | |
MPMediaItem *props = collection.representativeItem; | |
NSString *albumTitle = [props valueForProperty:MPMediaItemPropertyAlbumTitle]; | |
NSString *artistName = [props valueForProperty:MPMediaItemPropertyAlbumArtist]; | |
MPMediaItemArtwork *artwork = [props valueForProperty:MPMediaItemPropertyArtwork]; |
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
- (void)textDidChange:(NSNotification *)aNotification | |
{ | |
NSTextView *textView = self.detailTextView; | |
NSString *contents = textView.textStorage.string; | |
NSRange selectionRange = textView.selectedRange; | |
if (selectionRange.length == 0 && contents.length > 0) { | |
NSString *possibleMatch = [contents substringWithRange:NSMakeRange(selectionRange.location - 1, 1)]; | |
if ([possibleMatch isEqualToString:@"{"]) { | |
[textView complete:nil]; |
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
# | |
# Brute force method of grabbing 200 characters preceeding first <blockquote> element | |
# | |
p = Post.last | |
parts = p.split_as_html | |
root = Nokogiri::HTML.fragment(parts.first.raw_content) | |
bq = root.search('blockquote')[1] | |
test_string = root.inner_html[(root.inner_html.index(bq.to_html) - 200)...(root.inner_html.index(bq.to_html))] | |
# ">\n<br><br><div class=\"gmail_quote\">On Tue, Jun 29, 2014 at 11:19 AM, John Smith <span dir=\"ltr\">< |
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
func createAuthHandler() -> NXOAuth2PreparedAuthorizationURLHandler { | |
return { (url: NSURL!) -> Void in | |
let sourceScript = "tell application \"Safari\"\n" | |
+ " open location \"\(url.absoluteString!)\"\n" | |
+ " activate\n" | |
+ "end tell\n" | |
var err : NSDictionary? | |
let script = NSAppleScript(source: sourceScript)! | |
if script.compileAndReturnError(&err) { |
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
let escape = "\u{001B}[" | |
let none = escape + "0m" | |
let red = escape + "0;31m" | |
let green = escape + "0;32m" | |
let yellow = escape + "0;33m" | |
println("\(red)Everything \(green)or \(yellow)nothing\(none).") |
OlderNewer