Skip to content

Instantly share code, notes, and snippets.

View mattstevens's full-sized avatar

Matt Stevens mattstevens

View GitHub Profile
@mattstevens
mattstevens / gist:eb758f55cb2898b670a5
Created November 8, 2015 17:25
Filter breakpoint on frame module
(lldb) b NSLog
Breakpoint 2: 2 locations.
(lldb) breakpoint command add -s python -o "return (frame.GetThread().GetFrameAtIndex(1).GetModule().GetFileSpec().GetFilename() == 'UIKit')"
@mattstevens
mattstevens / gist:9712783
Last active August 29, 2015 13:57
Preference Panes and Garbage Collection
- On 10.6 and 10.7 System Preferences's 64-bit image requires GC. If the user opens a preference pane
that does not support GC System Preferences will restart as a 32-bit process, provided that the
preference pane has a 32-bit image.
- On 10.8+ System Preferences's 64-bit image supports GC but does not require it, and by default it
launches with GC disabled. If the user opens a preference pane that requires GC System Preferences
relaunches with GC enabled, but still as a 64-bit process.
So if your deployment target is <= 10.7 you'll get the best user experience by building with
GCC_ENABLE_OBJC_GC = supported, as the preference pane will run on all platforms without requiring a
@mattstevens
mattstevens / filter.cpp
Last active December 22, 2015 00:48
Quick and dirty ZNC filter to stop people from crashing clients (no longer needed as of 10.8.5)
#include <znc/Modules.h>
using namespace std;
static const char evil[] = { (char)0xd8, (char)0xb3, 0 };
class CFilterMod : public CModule {
public:
MODCONSTRUCTOR(CFilterMod) {
}
@mattstevens
mattstevens / embedded_resource.m
Last active December 20, 2015 20:08
Access embedded resource in command line tool
#import <Foundation/Foundation.h>
#import <mach-o/dyld.h>
#import <mach-o/getsect.h>
#import <mach-o/ldsyms.h>
// Embed via other linker flags: -sectcreate __TEXT test $(PROJECT_DIR)/test.txt
// Names are limited to 16 characters.
NSData *MSEmbeddedResourceDataWithName(NSString *name) {
unsigned long size = 0;
uint8_t *data = getsectiondata(&_mh_execute_header, "__TEXT", [name UTF8String], &size);
@mattstevens
mattstevens / GoogleTests.h
Created June 2, 2013 04:36
Google Test integration for an Xcode unit test target
#import <SenTestingKit/SenTestingKit.h>
@interface GoogleTests : SenTestCase
@end
@mattstevens
mattstevens / gist:5623680
Last active December 17, 2015 14:19
Check for existence of a custom icon
- (BOOL)fileHasCustomIcon:(NSString *)path {
struct FinderInfoAttrBuf {
u_int32_t length;
FileInfo fileInfo;
ExtendedFileInfo extendedFileInfo;
} __attribute__((aligned(4), packed));
struct attrlist attrList = {};
struct FinderInfoAttrBuf attrBuf = {};
attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
@mattstevens
mattstevens / gist:5608445
Created May 19, 2013 18:04
Setting subject and email address for NSSharingServiceNameComposeEmail via private API
NSSharingService *service = [NSSharingService sharingServiceNamed:NSSharingServiceNameComposeEmail];
NSDictionary *parameters = @{
@"NSSharingServiceParametersDefaultSubjectKey": @"Lo, a subject!",
@"NSSharingServiceParametersDefaultRecipientsKey": @[@"someone@somewhere.com"]
};
[service setValue:parameters forKey:@"parameters"];
[service performWithItems:@[@"Woo, private API."]];
@mattstevens
mattstevens / gist:4948153
Last active December 13, 2015 17:28
Clear recent documents list
LSSharedFileListRef recentDocsList = LSSharedFileListCreate(NULL, kLSSharedFileListRecentDocumentItems, NULL);
LSSharedFileListRemoveAllItems(recentDocsList);
CFRelease(recentDocsList);
@mattstevens
mattstevens / gist:4400775
Last active March 9, 2022 12:53
Resizing an NSImage on retina Macs for output as a 1x image
NSImage *computerImage = [NSImage imageNamed:NSImageNameComputer];
NSInteger size = 256;
NSBitmapImageRep *rep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:size
pixelsHigh:size
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
@mattstevens
mattstevens / gist:3540222
Created August 30, 2012 20:34
NSDate for next minute
NSDate *now = [NSDate date];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *nowComponents = [calendar components:NSSecondCalendarUnit fromDate:now];
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
[offsetComponents setMinute:1];
[offsetComponents setSecond:-[nowComponents second]];
NSDate *nextMinute = [calendar dateByAddingComponents:offsetComponents toDate:now options:0];
NSTimeInterval interval = [nextMinute timeIntervalSinceDate:now];