Skip to content

Instantly share code, notes, and snippets.

@richardbuckle
richardbuckle / shut down core data.m
Created September 23, 2011 22:29
Shut down a Core Data store prior to deleting the underlying file
- (void)closeDown {
NSArray *stores = [self.persistentStoreCoordinator persistentStores];
for (NSPersistentStore *store in stores) {
DebugLogging(@"Closing Core Data store at %@", [store URL]);
NSError *error = nil;
if (![self.persistentStoreCoordinator removePersistentStore:store error:&error]) {
DebugLogging(@"Unable to close Core Data store: error %@", [error localizedDescription]);
}
}
}
@richardbuckle
richardbuckle / Nonlocalised string regex.txt
Last active September 27, 2015 16:28
VERY quick and dirty regex to hunt for string literals that may need to be localised
(?<!Path:|Key:|NSLocalizedString\(|NibName:|NibNamed:|imageNamed:|PathComponent:|xpathQuery:|initForModel:|initWithDomain:|predicateWithFormat:|setDateFormat:|fontWithName:|entities:|sortBy:|NSClassFromString\(|NSLog\(|DLog\(|ALog\(|DebugLogging\()\s*(?!@"%@"|@"%d")@".+"
@richardbuckle
richardbuckle / NoNSTableView tooltips
Created January 31, 2012 20:46
NSTableView delegate methods to prevent tooltips
- (BOOL)tableView:(NSTableView*)tableView shouldShowCellExpansionForTableColumn:(NSTableColumn*)tableColumn row:(NSInteger)row
{
return NO; // no tool tips
}
- (NSString*)tableView:(NSTableView*)aTableView toolTipForCell:(NSCell*)aCell rect:(NSRectPointer)rect tableColumn:(NSTableColumn*)aTableColumn row:(NSInteger)row mouseLocation:(NSPoint)mouseLocation
{
return nil; // no tool tips
}
@richardbuckle
richardbuckle / gist:6038567
Created July 19, 2013 11:43
Use a nil-targeted action to message a view controller higher up the responder chain without introducing coupling
// in some parent view controller's header file
- (IBAction)yourActionNameHere:(id)sender;
// implementation does whatever you want
// Now, from any call site, as long as you're on the main thread
// just post an action to nil and it will be sent to the first responder,
// then all the way up the responder chain until it finds your view controller
[[UIApplication sharedApplication] sendAction:@selector(yourActionNameHere:)
@richardbuckle
richardbuckle / gist:7189956
Created October 28, 2013 01:15
Answers for @mikeabdullah's hipster question "What is the only public class in the Cocoa frameworks that has no methods of its own?
I found:
NSMessagePort
NSURLSessionDataTask
NSURLSessionUploadTask
None of these were what Mike had in mind, which was NSFileSecurity.
I commented that NSFileSecurity was doubly interesting because it's in Foundation but not listed in "Foundation Framework Reference".
@richardbuckle
richardbuckle / gist:e5205cdc9ad105741bb0
Last active August 29, 2015 14:03
fopen() fails with ENOENT but open() works. WTF?
Verbatim LLDB session with an iPad Air running iOS 7.1.1.
As you can see, "finPath", which is a const char*, is an absolute path.
Normally fopen(finPath, "r") works fine but sometimes after stress-testing the app gets into a state where it always fails with ENOENT.
How could fopen(finPath, "r") fail with ENOENT while open(finPath, O_RDONLY) succeeds?
Edit: forgot to say that no memory warnings were received during the stress test.
(lldb) p finPath
@richardbuckle
richardbuckle / gist:2a72cf293ec9dd7b7e01
Last active August 29, 2015 14:05
Let's break Swift Integer addition
// written with Swift as of Xcode 6 beta 5
import Swift
let a = 2
let b = 5
let c = a + b // returns 42 not 7 even though coder is unaware of the override below, which could even be buried in a malicious import
// extremely evil override
public func + (x: Int, y: Int) -> Int {
@richardbuckle
richardbuckle / make-qa-log.py
Created August 16, 2014 07:35
Format your Git change log into markdown for nightly builds
#! /usr/bin/env python
'''
Format the Git log between current and master into the markdown required for the HockeyApp nightly builds.
'''
import os
import re
ticketRegex = re.compile(r'#(\d+)')
@richardbuckle
richardbuckle / French journal.log
Created April 17, 2018 19:31
French language Elite Dangerous journal
{ "timestamp":"2018-04-17T19:13:12Z", "event":"Fileheader", "part":1, "language":"French\\FR", "gameversion":"3.0.5.402 EDH", "build":"r168330/r0 " }
{ "timestamp":"2018-04-17T19:13:12Z", "event":"Music", "MusicTrack":"NoTrack" }
{ "timestamp":"2018-04-17T19:13:12Z", "event":"Music", "MusicTrack":"MainMenu" }
{ "timestamp":"2018-04-17T19:13:45Z", "event":"Friends", "Status":"Online", "Name":"Doug Heisenberch" }
{ "timestamp":"2018-04-17T19:13:45Z", "event":"Friends", "Status":"Online", "Name":"Myself_st" }
{ "timestamp":"2018-04-17T19:13:45Z", "event":"Friends", "Status":"Online", "Name":"ST4R F0X" }
{ "timestamp":"2018-04-17T19:13:45Z", "event":"Friends", "Status":"Online", "Name":"Spike1986" }
{ "timestamp":"2018-04-17T19:13:45Z", "event":"Friends", "Status":"Online", "Name":"Freak97" }
{ "timestamp":"2018-04-17T19:13:45Z", "event":"Friends", "Status":"Online", "Name":"NSR2" }
{ "timestamp":"2018-04-17T19:13:45Z", "event":"Friends", "Status":"Online", "Name":"Valcor_" }
@richardbuckle
richardbuckle / gist:ac34863f350fa7581774549b273c15d4
Created September 16, 2018 21:59
Mission check galaxy VB version
{_ Mission report }
{_ Check what systems you have missions in }
{_ Setup allmissions function }
{set allmissions(system) to:
{set here to find(systems, system)}
{if here > -1:
{set number to systems_count[here] + 1}
{set systems_count to union(systems_count, [here:number])}