Skip to content

Instantly share code, notes, and snippets.

View bewebste's full-sized avatar

Brian Webster bewebste

View GitHub Profile
@bewebste
bewebste / wrapper.swift
Last active September 30, 2016 23:34
Swift 3 generic object wrapper gives EXC_BAD_ACCESS
//: Playground - noun: a place where people can play
import Cocoa
/*
I've been using an object like ObjectWrapper in Swift 2.x without any problems
to store a Swift struct as a property an Objective-C object, and then later
access and use that struct from other Swift code.
@bewebste
bewebste / crash.log
Created November 20, 2014 21:57
Recursive CFRetain crash
Date/Time: 2014-10-23 21:09:32 +0000
OS Version: Mac OS X 10.10.0 (14A389)
Report Version: 104
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x7fff5f3ffff8
Crashed Thread: 0
Thread 0 Crashed:
0 CoreFoundation 0x00007fff924ac084 CFRetain + 4
NSDateComponents* oneYear = [NSDateComponents new];
oneYear.year = 1;
dave.age = [[NSCalendar currentCalendar] dateByAddingComponents:oneYear toDate:dave.age options:0];
@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();
@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 / 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 / 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 / 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];
}
//
// NSObject+BlockObservation.h
// Version 1.0
//
// Andy Matuschak
// andy@andymatuschak.org
// Public domain because I love you. Let me know how you use it.
//
/*
//
// 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>