Skip to content

Instantly share code, notes, and snippets.

View ccgus's full-sized avatar

August "Gus" Mueller ccgus

View GitHub Profile
@ccgus
ccgus / stackcrasher.m
Created February 26, 2012 01:20
CI Stack Crasher
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
/*
This example will create around 15k stack frames on 10.7, which ends up crashing the process.
clang stackcrasher.m -o stackcrasher -framework Cocoa -framework QuartzCore -fobjc-arc
*/
@ccgus
ccgus / gist:2466760
Created April 22, 2012 20:43
custom margins.
function pageWasOpened(document, page) {
if ([page isRichText]) {
// custom insets per document!
var wc = [document mainWindowController];
var tv = [wc textView];
[tv setTextContainerInset:NSMakeSize(30, 0)];
}
}
@ccgus
ccgus / gist:2840343
Created May 31, 2012 01:50
Threads r hard
Thread 1, Queue : com.apple.main-thread
#0 0x00007fff901296b6 in semaphore_wait_trap ()
#1 0x00007fff8d85820a in _dispatch_semaphore_wait_slow ()
#2 0x00007fff966027e8 in -[NSDocument _performFileAccessOnMainThread:usingBlock:] ()
#3 0x00007fff966026ae in -[NSDocument performSynchronousFileAccessUsingBlock:] ()
#4 0x00007fff96602eb2 in -[NSDocument _isLocatedByURL:becauseOfAutosavedContentsFile:] ()
#5 0x00007fff9649f30e in -[NSDocumentController _documentForURL:] ()
#6 0x00007fff9649f1e0 in -[NSDocumentController documentForURL:] ()
#7 0x0000000108d76b74 in -[DUDocument writeSafelyToURL:ofType:forSaveOperation:error:] at /Volumes/srv/Users/gus/Dropbox/Code/DocumentForURLBlock/DocumentForURLBlock/DUDocument.m:42
#8 0x00007fff96609a7b in __-[NSDocument saveToURL:ofType:forSaveOperation:completionHandler:]_block_invoke_8 ()
#0 0x00007fff901296b6 in semaphore_wait_trap ()
#1 0x00007fff8d85820a in _dispatch_semaphore_wait_slow ()
#2 0x00007fff8d94efb9 in -[NSXPCConnection sendMessage:waitForAck:] ()
#3 0x00007fff8d91a202 in _CFXNotificationPost ()
#4 0x00007fff8d92b758 in CFNotificationCenterPostNotification ()
#5 0x00007fff8aee2086 in HIS_XPC_CFNotificationCenterPostNotification ()
#6 0x00007fff8ec88e4b in BroadcastToolboxMessage ()
#7 0x00007fff8ebf82c7 in SendMenuOpening ()
#8 0x00007fff8ebfb8cd in DrawTheMenu ()
#9 0x00007fff8ebfbdd7 in MenuChanged ()
10.6:
typedef signed __int32 cl_int2[2];
10.7:
typedef union
{
cl_int CL_ALIGNED(8) s[2];
#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ )
__extension__ struct{ cl_int x, y; };
__extension__ struct{ cl_int s0, s1; };
@ccgus
ccgus / FMDrawContext
Created July 16, 2012 18:57
Sketching up a little drawable context guy.
@interface FMDrawContext : NSObject {
CGContextRef _cgContext;
}
+ (id)drawContextWithSize:(NSSize)s;
- (CGImageRef)CGImage __attribute__((cf_returns_retained));
- (NSImage*)NSImage;
- (NSData*)dataOfType:(NSString*)uti;
- (void)drawInContextWithBlock:(void (^)())r;
@ccgus
ccgus / gist:3429274
Created August 22, 2012 20:56
SFPasswordAssistantInspectorController
[[jstalk jsController] loadFrameworkWithName:@"SecurityInterface"];
var paic = [[SFPasswordAssistantInspectorController alloc] init]
[paic showPasswordAssistantPanel:nil]
var assistWindow = [paic valueForKey:@"passwordAssistantPanel"];
[assistWindow center];
@ccgus
ccgus / gist:3716936
Last active October 10, 2015 16:17
Gestalt(gestaltSystemVersion, &v); replacement
/*
if ((TSSystemVersion() >= 0x1074) || (TSSystemVersion() < 0x1070)) {
// hurray, no stupid CoreImage stack crasher for lots of images being composited together!
}
*/
SInt32 TSSystemVersion(void) {
static dispatch_once_t once;
/***** GCL Generated File *********************/
/* Automatically generated file, do not edit! */
/**********************************************/
#include <OpenCL/opencl.h>
extern void (^seedFill_kernel)(const cl_ndrange *ndrange, cl_uchar4* input, cl_uint4 inputSize, cl_uchar* output, cl_int2 fillCenter, cl_uchar4 targetColor, cl_int tolerance);
extern void (^BlendFillImage_kernel)(const cl_ndrange *ndrange, cl_uchar4* baseImage, cl_uchar* mask, cl_uchar4* fillImage, cl_uint2 fillImageSize, cl_uchar4* outputImage, cl_uint elementsPerRow);
extern void (^AntiAliasMaskAndBlendFillImage_kernel)(const cl_ndrange *ndrange, cl_uchar4* baseImage, cl_uchar* mask, cl_uchar4* fillImage, cl_uint2 fillImageSize, cl_uchar4* outputImage, cl_uint elementsPerRow);
extern void (^AntiAliasMask_kernel)(const cl_ndrange *ndrange, cl_uchar* mask);
@ccgus
ccgus / gist:3805275
Created September 29, 2012 21:55
webExportWillWriteHTMLForItem
in your VPWebExportScript page, you can have this which will do simple replacements:
function webExportWillWriteHTMLForItem(contextDictionary, item, fileName, mutableHTMLString) {
mutableHTMLString.replaceOccurrencesOfString_withString_options_range_("<p>", "<div>", 0, NSMakeRange(0, mutableHTMLString.length()));
mutableHTMLString.replaceOccurrencesOfString_withString_options_range_("</p>", "</div>", 0, NSMakeRange(0, mutableHTMLString.length()));
return mutableHTMLString;