Skip to content

Instantly share code, notes, and snippets.

View justin's full-sized avatar

Justin Williams justin

View GitHub Profile
@jcsalterego
jcsalterego / .gitignore
Last active December 14, 2023 16:59
Bluesky Icon
icon.iconset
@mattmc3
mattmc3 / optparsing_demo.zsh
Last active April 5, 2024 21:22
Zsh option parsing example
# Manual opt parsing example
#
# Features:
# - supports short and long flags (ie: -v|--verbose)
# - supports short and long key/value options (ie: -f <file> | --filename <file>)
# - supports short and long key/value options with equals assignment (ie: -f=<file> | --filename=<file>)
# - does NOT support short option chaining (ie: -vh)
# - everything after -- is positional even if it looks like an option (ie: -f)
# - once we hit an arg that isn't an option flag, everything after that is considered positional
function optparsing_demo() {
NSView *contentView = [self.window contentView];
self.button = [[NSButton alloc] initWithFrame:NSMakeRect(0, 0, 200, 50.0f)];
[self.button setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.button setTitle:@"This is a test button"];
[self.button setBordered:YES];
[contentView addSubview:self.button];
NSButton *button = self.button;
- (void)loadDefaultSettings
{
NSMutableDictionary *defaults = [NSMutableDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Default-Settings" ofType:@"plist"]];
// other setup...
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithDictionary:defaults]];
}
- (void)resetDefaultSettings
@aitskovi
aitskovi / NSObject_KVCExtensions.h
Created April 28, 2011 06:24
Key Value Coding - canSetValueForKey/KeyPath
#import <Foundation/Foundation.h>
@interface NSObject (NSObject_KVCExtensions)
- (BOOL)canSetValueForKey:(NSString *)key;
- (BOOL)canSetValueForKeyPath:(NSString *)keyPath;
@end
@cbarrett
cbarrett / BLOCK bself macro
Created March 16, 2011 04:25
I think this was it. I stopped using it because it made Xcode 3 put all errors or warnings for the block on the line of the macro invocation; total nonstarter.
#define BLOCK(...) ({ __block __typeof__(self) bself = self; __VA_ARGS__(); )}
//
// 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>