Skip to content

Instantly share code, notes, and snippets.

View ccgus's full-sized avatar

August "Gus" Mueller ccgus

View GitHub Profile
@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 / quant.py
Created November 7, 2023 21:21
Making the Beby-Gan model quite a bit smaller.
# Before running this, setup a python venv for everything:
# python3 -m venv coremltools-venv
# source coremltools-venv/bin/activate
# pip install -U coremltools
import coremltools as ct
from coremltools.models.neural_network import quantization_utils
# load full precision model
model_fp32 = ct.models.MLModel('Beby-GANx4.mlmodel')
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));
#import <Foundation/Foundation.h>
#import <dlfcn.h>
// clang main.m -framework Foundation
int main(int argc, const char * argv[]) {
@autoreleasepool {
dlopen("/System/Library/Frameworks/CoreGraphics.framework/Resources/BridgeSupport/CoreGraphics.dylib", RTLD_LAZY);
from AppKit import *
from Foundation import *
html = NSString.stringWithString_("<b style='font-size: 20px; font-family: HelveticaNeue'>Hi</b>")
d = html.dataUsingEncoding_(NSUTF8StringEncoding);
ats = NSAttributedString.alloc().initWithHTML_options_documentAttributes_(d, None, None)[0];
ps = ats.attribute_atIndex_effectiveRange_(NSParagraphStyleAttributeName, 0, None)[0]
print(ps.minimumLineHeight())
print(ps.maximumLineHeight())
@ccgus
ccgus / Leaky16BPCTiff.m
Last active December 6, 2019 18:58
Asking the internet for help to make sure I'm not being stupid.
/*
This sample shows how CGImageSourceCreateThumbnailAtIndex leaks something akin
to the memory behind a CGImageRef when asked to create a thumbnail for a 16bpc
TIFF image if one isn't present.
Full sample project here:
http://shapeof.com/archives/2019/media/SixteenBitPerComponentThumbnailLeak.zip
*/
- (FJSValue*)evaluateModuleAtURL:(NSURL*)scriptURL {
if (scriptURL) {
NSError *error;
NSString *script = [NSString stringWithContentsOfURL:scriptURL encoding:NSUTF8StringEncoding error:&error];
if (script) {
#define NODE_STYLE_WRAPPER 1
#ifdef NODE_STYLE_WRAPPER
/*
How to install this plugin:
1) Choose Acorn's Help ▸ Open Acorn's App Support Folder menu item.
2) Place this script in the Plug-Ins folder (and make sure it ends with .jstalk)
3) Restart Acorn. The plugin will now show up in the Filter menu.
*/
function main(image, doc, layer) {
@ccgus
ccgus / gist:a475e2916f1e860b3b7dd2143862d5a5
Created September 19, 2018 16:28
Calling Core Image with FMJS
var url = NSURL.fileURLWithPath_('/Library/Desktop Pictures/Yosemite.jpg');
var img = CIImage.imageWithContentsOfURL_(url)
var f = CIFilter.filterWithName_('CIColorInvert');
f.setValue_forKey_(img, kCIInputImageKey);
var r = f.outputImage();
var tiff = r.TIFFRepresentation();
tiff.writeToFile_atomically_('/tmp/foo.tiff', true);
NSWorkspace.sharedWorkspace().openFile_('/tmp/foo.tif');