Skip to content

Instantly share code, notes, and snippets.

View Wevah's full-sized avatar
💻
Computerin‘

Nate Weaver Wevah

💻
Computerin‘
View GitHub Profile
@Wevah
Wevah / gist:1987687
Created March 6, 2012 17:41
NSPropertyListSerialization usage
NSString *errorString;
NSData *data = [NSPropertyListSerialization dataFromPropertyList:plist format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorString];
if (!data)
NSLog(@"%@", errorString);
@Wevah
Wevah / gist:2177811
Created March 24, 2012 03:08
Bigger tinychat
javascript:var a = document.getElementById('preload');a.style.marginLeft = '-200px';a.style.width = '1300px';a.style.height = '1200px';void(0);
@Wevah
Wevah / NSApplicationSubclass.m
Created May 3, 2012 19:34
Prevent clicks in a popover from activating an LSUIElement app
- (void)sendEvent:(NSEvent *)event {
if ([event type] == NSAppKitDefined && ([event subtype] & NSApplicationActivatedEventType) && [[event window] respondsToSelector:@selector(_popover)])
return;
[super sendEvent:event];
}
@Wevah
Wevah / gist:3335928
Created August 13, 2012 00:47
AEDebug redirect attempt
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"DebugAppleEvents"]) {
NSError *error = nil;
NSFileManager *fm = [NSFileManager defaultManager];
NSURL *logsDir = [fm URLForDirectory:NSLibraryDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil];
logsDir = [logsDir URLByAppendingPathComponent:@"Logs"];
logsDir = [logsDir URLByAppendingPathComponent:@"Paparazzi!"];
if (![logsDir checkResourceIsReachableAndReturnError:&error]) {
if (![fm createDirectoryAtURL:logsDir withIntermediateDirectories:YES attributes:nil error:&error])
@Wevah
Wevah / gist:3365918
Last active October 8, 2015 17:38
Pipe Parse
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSString *str = @"foo|bar|baz\\|quux";
BOOL lastWasBackslash = NO;
NSMutableString *sub = [NSMutableString string];
NSMutableArray *matches = [NSMutableArray array];
for (NSUInteger idx; idx < [str length]; ++idx) {
@Wevah
Wevah / gist:3483048
Created August 26, 2012 19:47
Adium 1.5.4b1 + Growl 2.0b6 crash
Process: Adium [12517]
Path: /Applications/Internet/Adium.app/Contents/MacOS/Adium
Identifier: com.adiumX.adiumX
Version: 1.5.4b1 (1.5.4b1)
Code Type: X86-64 (Native)
Parent Process: launchd [256]
User ID: 501
Date/Time: 2012-08-26 14:45:17.761 -0500
OS Version: Mac OS X 10.8.1 (12B19)
@Wevah
Wevah / NSString+MaxWidth.m
Last active December 29, 2015 14:29
Truncate a string, with an ellipsis in the center, to a max point width, without splitting composed character sequences (grapheme clusters).
- (NSString *)stringByInsertingCenterEllipsisWithMaxWidth:(CGFloat)maxWidth font:(NSFont *)font {
NSDictionary *attrs = @{ NSFontAttributeName: font };
NSSize size = [self sizeWithAttributes:attrs];
if (size.width <= maxWidth)
return self;
NSMutableString *mutable = [self mutableCopy];
NSMutableString *mutableWithEllipsis = nil;
@Wevah
Wevah / gist:10145527
Created April 8, 2014 15:44
Using kPasteboardTypeFileURLPromise/kPasteboardTypeFilePromiseContent
- (NSArray *)writableTypesForPasteboard:(NSPasteboard *)pasteboard {
// pasteboard must be stored away because there's no way to get it in -pasteboardPropertyListForType: :(
_currentPasteboard = pasteboard;
NSArray *types = @[(id)kPasteboardTypeFileURLPromise, (id)kPasteboardTypeFilePromiseContent];
return types;
}
// ...
@Wevah
Wevah / Makefile
Created March 14, 2016 00:50
Simple makefile for compiling single-file Cocoa test binaries.
# Toss in a directory
# Usage: make <binname>
# Compiles <binname>.m to <binname>
%: %.m
rm -f $@
$(CC) $(CPPFLAGS) $(CFLAGS) -Wall -fobjc-arc -fmodules $^ -o $@
@Wevah
Wevah / buildsqlite.txt
Last active January 27, 2021 20:46
Build SQLite dylib
clang -dynamiclib -Os -Wl,-install_name,@rpath/libsqlite3.dylib -mmacosx-version-min=10.9 -o libsqlite3.dylib sqlite3.c