Skip to content

Instantly share code, notes, and snippets.

View bewebste's full-sized avatar

Brian Webster bewebste

View GitHub Profile
Handle printHandle;
OSStatus err = noErr;
NSString* description = nil;
AEDesc descriptor;
err = AEPrintDescToHandle(&descriptor, &printHandle);
if (err == noErr)
{
description = [NSString stringWithCString:(char*)(*printHandle) encoding:NSASCIIStringEncoding];
DisposeHandle(printHandle);
@bewebste
bewebste / machine.h.motemplate
Created June 4, 2011 19:14
MOGenerator diff template
{
name = <$name$>,
managedObjectClassName = <$managedObjectClassName$>,
renamingIdentifier = <$renamingIdentifier$>,
isAbstract = <$isAbstract$>,
userInfo = <$userInfo$>,
relationships = (
<$foreach Relationship noninheritedRelationships do$>
{
name = <$Relationship.name$>,
//
// NSObject+BlockObservation.h
// Version 1.0
//
// Andy Matuschak
// andy@andymatuschak.org
// Public domain because I love you. Let me know how you use it.
//
#import <Cocoa/Cocoa.h>
//
// NSObject+BlockObservation.h
// Version 1.0
//
// Andy Matuschak
// andy@andymatuschak.org
// Public domain because I love you. Let me know how you use it.
//
/*
@bewebste
bewebste / gist:1402316
Created November 28, 2011 22:10
Shameful code
- (oneway void)release
{
int retainCount = [self retainCount];
[super release];
if(retainCount == 2)
[resourceFiles removeObjectForKey:path];
}
@bewebste
bewebste / backup_growl.rb
Created May 7, 2012 18:47
Script to display Time Machine progress messages as Growl notifications
#!/usr/bin/ruby
#Just run this script in a terminal window, leaving the window open in the
#background so it can continue to process messages.
IO.popen("syslog -F \'$(Sender): $Message\' -w -k Sender com.apple.backupd") { |syslogIO|
while (inputString = syslogIO.gets) do
escapedString = inputString.gsub("'", "\\'")
`/usr/local/bin/growlnotify -a 'Time Machine' -m '#{escapedString}'`
end
}
@bewebste
bewebste / lldb.txt
Created August 9, 2012 17:54
Am I crazy, or will this function always hang if it hits that dispatch_sync_f() call?
This is some LLDB output from my app in a hung state somewhere deep in the image rendering frameworks. It looks like it's hung on dispatch_sync_f(), and from what I can tell from the disassembly, it looks like it's dispatching it on the current queue (see the call to dispatch_get_current_queue() just a few instructions prior), which the docs say will always hang.
(lldb) bt
* thread #1: tid = 0x2203, 0x00007fff88b4f6c2 libsystem_kernel.dylib`semaphore_wait_trap + 10, stop reason = signal SIGSTOP
frame #0: 0x00007fff88b4f6c2 libsystem_kernel.dylib`semaphore_wait_trap + 10
frame #1: 0x00007fff88924c6e libdispatch.dylib`_dispatch_thread_semaphore_wait + 16
frame #2: 0x00007fff88924ace libdispatch.dylib`_dispatch_barrier_sync_f_slow + 188
frame #3: 0x00007fff89387efb OpenCL`clFinish + 120
frame #4: 0x00007fff8e5d5d3d CoreImage`-[FEOpenCLContext _quad:] + 3743
frame #5: 0x00007fff8e6ce18e CoreImage`-[FEContext(Drawing) quad:kernel:] + 107
@bewebste
bewebste / Tweetbot.applescript
Created August 31, 2012 20:32
Applescript to toggle Tweetbot window
tell application "System Events"
if exists application process "Tweetbot" then
tell application process "Tweetbot"
if frontmost then
set visible to false
else
set frontmost to true
end if
end tell
end if
@bewebste
bewebste / gist:6226400
Created August 13, 2013 22:39
Function to tell whether a debugger is attached
BOOL BWProcessIsBeingTraced()
{
int mib[4];
size_t bufSize = 0;
struct kinfo_proc kp;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PID;
mib[3] = getpid();
NSDateComponents* oneYear = [NSDateComponents new];
oneYear.year = 1;
dave.age = [[NSCalendar currentCalendar] dateByAddingComponents:oneYear toDate:dave.age options:0];