Skip to content

Instantly share code, notes, and snippets.

Jonathan Willing jwilling

Block or report user

Report or block jwilling

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
# Some things taken from here
# Ask for the administrator password upfront
sudo -v
# Keep-alive: update existing `sudo` time stamp until script has finished
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
jwilling / NSString+IBNMetrics.h
Created Jan 3, 2014
Better string metrics on OS X.
View NSString+IBNMetrics.h
#import <Foundation/Foundation.h>
@interface NSString (IBNMetrics)
- (CGSize)ibn_sizeConstrainedToSize:(CGSize)size font:(NSFont *)font;
- (CGSize)ibn_sizeWithFont:(NSFont *)font;
jwilling / LBHView.h
Last active Feb 6, 2018
A terrible, terrible hack to toggle AppKit's destruction of layer modifications.
View LBHView.h
#import <Cocoa/Cocoa.h>
@interface LBHView : NSView
/// This property controls whether the view can indirectly control its
/// backing layer's properties, specifically the following:
/// `affineTransform`
/// `anchorPoint`
/// These properties cannot be modified on the layer during the time that
jwilling / gist:8160367
Created Dec 28, 2013
NSViewLayerContentsRedrawCrossfade on 10.8
View gist:8160367
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.duration = 4.f;
context.allowsImplicitAnimation = YES;
[view.layer addAnimation:CATransition.animation forKey:@"contents"];
view.layer.contents = someImage;
} completionHandler:nil];
jwilling / QTMAsyncOperationQueue.h
Created Oct 29, 2013
Simple block-based serial queue for asynchronous operations.
View QTMAsyncOperationQueue.h
// QTMAsyncOperationQueue.h
// Quantum
// Created by Jonathan Willing on 10/28/13.
// Copyright (c) 2013 AppJon. All rights reserved.
#import <Foundation/Foundation.h>
jwilling / JNWThrottledBlock.h
Last active Aug 10, 2017
Simple throttling of blocks using dispatch sources.
View JNWThrottledBlock.h
#import <Foundation/Foundation.h>
@interface JNWThrottledBlock : NSObject
// Runs the block after the buffer time _only_ if another call with the same identifier is not received
// within the buffer time. If a new call is received within that time period the buffer will be reset.
// The block will be run on the main queue.
// Identifier and block must not be nil.
+ (void)runBlock:(void (^)())block withIdentifier:(NSString *)identifier throttle:(CFTimeInterval)bufferTime;
View JNWAsyncGroupOperation.m
#import <Foundation/Foundation.h>
typedef void (^JNWGroupAsyncOperationCompletion)();
@interface JNWGroupAsyncOperation : NSObject
// The completion block that will be fired when all operations have completed.
@property (nonatomic, copy) void(^groupCompletion)();
// Adds an asynchronous operation and starts it on the main thread. The completion block _must_
jwilling / gist:5929321
Last active Dec 19, 2015
Handling errors when using toProperty:onObject:.
View gist:5929321
RAC(self.someOrderedSet) = [[[[[[RACAble(self.searchField.text)
filter:^BOOL(NSString *text) {
return (text.length > 0);
map:^id(NSString *text) {
return [Something searchForAutocomplete:text]; // this signal can send errors
catchTo:[RACSignal return:[NSArray array]]]
map:^id(NSArray *objects) {
jwilling / gist:4186817
Last active Feb 24, 2016
Lets help improve AppKit.
View gist:4186817

Is AppKit causing you frustration? Instead of just complaining about it, lets try to make it better by compiling a list of specific problems with AppKit. Leave a comment below, and I'll include it in the list.


  • NSView does not have the ability to set an affine transform (rdar://15608609)
  • Controls that have cells (such as NSTextField) do not respond properly when layer-backed. Take NSButton as an example. When not layer-backed, it will animate properly using the animator proxy. When layer-backed, using the animator proxy breaks focus rings (they jump to destination immediately). Currently, directly manipulating the layer of a cell-based control is not supported (and will lead to a broken interface), but is much needed. (rdar://15608822)


  • NSViewController could be more useful. It has -loadView but no other lifecycle methods. (rdar://15608948)
jwilling / CustomClipView.m
Last active Oct 12, 2015
NSTableView with custom clip view
View CustomClipView.m
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (!self) return nil;
self.layer = [CAScrollLayer layer];
self.wantsLayer = YES;
self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawNever;
return self;
You can’t perform that action at this time.