Skip to content

Instantly share code, notes, and snippets.

View ccgus's full-sized avatar

August "Gus" Mueller ccgus

View GitHub Profile
@ccgus
ccgus / gist:8327134
Created January 9, 2014 00:07
NSString isEqual: problems
static Boolean MOObjectEqual(const id value1, const id value2) {
debug(@"(id)value1: '%@'", NSStringFromClass([(id)value1 class]));
debug(@"(id)value2: '%@'", NSStringFromClass([(id)value2 class]));
debug(@"[(id)value1 isKindOfClass:[NSString class]]: %d", [(id)value1 isKindOfClass:[NSString class]]);
debug(@"[(id)value2 isKindOfClass:[NSString class]]: %d", [(id)value2 isKindOfClass:[NSString class]]);
return (Boolean)[(id)value1 isEqual:(id)value2];
}
var list = """George Washington
John Adams
Thomas Jefferson
James Madison
James Monroe
John Quincy Adams
Andrew Jackson
Martin Van Buren
William Henry Harrison
John Tyler
SInt32 TSSystemVersion(void) {
static dispatch_once_t once;
static int TSSystemVersionVal = 0x00;
dispatch_once(&once, ^{
NSDictionary *d = [NSDictionary dictionaryWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"];
NSString *prodVersion = [d objectForKey:@"ProductVersion"];
@ccgus
ccgus / gist:6324222
Created August 23, 2013 21:28
Custom SQLite Functions
[db makeFunctionNamed:@"UTTypeConformsTo" maximumArguments:2 withBlock:^(sqlite3_context *context, int argc, sqlite3_value **argv) {
if (sqlite3_value_type(argv[0]) == SQLITE_TEXT) {
const unsigned char *a = sqlite3_value_text(argv[0]);
const unsigned char *b = sqlite3_value_text(argv[1]);
CFStringRef as = CFStringCreateWithCString(nil, (const char*)a, kCFStringEncodingUTF8);
CFStringRef bs = CFStringCreateWithCString(nil, (const char*)b, kCFStringEncodingUTF8);
sqlite3_result_int(context, UTTypeConformsTo(as, bs));
@ccgus
ccgus / Xcode crash report
Created February 23, 2013 19:02
Xcode crash report whoa
Application Specific Information:
ProductBuildVersion: 4H127
ASSERTION FAILURE in /SourceCache/IDEInterfaceBuilder/IDEInterfaceBuilder-3084/Framework/Connections/Interface/IBConnectionPopUpMenu.m:388
Details: Need a menu.
Function: NSMenuItem *IBPopUpConnectionMenuWithMenuItems(NSArray *, NSMenuItem *, NSEvent *, NSRect, BOOL, NSSet *, CGFloat, NSWindow *, NSColor *, NSColor *, NSColor *, NSColor *, id<IBConnectionPopUpMenuDelegate>)
Thread: <NSThread: 0x40030a1e0>{name = (null), num = 1}
Hints: None
Backtrace:
0 0x000000010c77b249 -[IDEAssertionHandler handleFailureInFunction:fileName:lineNumber:messageFormat:arguments:] (in IDEKit)
1 0x000000010ba2ec65 _DVTAssertionHandler (in DVTFoundation)
@ccgus
ccgus / gist:4961749
Created February 15, 2013 17:03
replacing NSImage reps
NSImage *iRep = [NSImage imageNamed:[fileName stringByDeletingPathExtension]];
if (iRep) {
NSImage *ni = [[NSImage alloc] initByReferencingFile:output];
for (NSImageRep *r in [[iRep representations] copy]) {
[iRep removeRepresentation:r];
}
@ccgus
ccgus / gist:4544658
Created January 16, 2013 04:31
FMSimpleBlockAnimation
#import <Cocoa/Cocoa.h>
@interface FMSimpleBlockAnimation : NSAnimation {
void (^_animationBlock)(float t);
}
- (void)animateWithBlock:(void(^)(float t))block;
@end
@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;
/***** 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: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;