Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Willing jwilling

View GitHub Profile
View osx-for-hackers.sh
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# 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
jwilling / gist:2292277
Created Apr 3, 2012
Drawing with shadow offset
View gist:2292277
- (void)drawInRect:(CGRect)rect {
CGSize shadowOffset = CGSizeMake(0, -1);
float colorValues[] = {0, 0, 0, .9};
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
CGContextSetShadow (ctx, shadowOffset, 1);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGColorRef color = CGColorCreate(colorSpace, colorValues);
@jwilling
jwilling / gist:2773202
Created May 23, 2012
Simple category for changing window size to fit content
View gist:2773202
- (void)resizeWindowForContentSize:(NSSize)size animated:(BOOL)animated {
NSRect windowFrame = [self contentRectForFrameRect:[self frame]];
NSRect newWindowFrame = [self frameRectForContentRect:
NSMakeRect( NSMinX( windowFrame ), NSMaxY( windowFrame ) - size.height, size.width, size.height )];
[self setFrame:newWindowFrame display:YES animate:animated];
}
@jwilling
jwilling / JWLocationManager.h
Created Jul 31, 2012
Block-based wrapper around Core Location
View JWLocationManager.h
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
typedef void (^JWLocationManagerCallback)(CLLocation *location);
typedef void (^JWLocationManagerErrorCallback)(NSError *error);
@interface JWLocationManager : NSObject <CLLocationManagerDelegate>
@property (nonatomic, copy) NSString *purpose;
@property (nonatomic, copy) JWLocationManagerCallback locationUpdatedBlock;
@jwilling
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;
}
@jwilling
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
}]
switchToLatest]
catchTo:[RACSignal return:[NSArray array]]]
map:^id(NSArray *objects) {
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
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
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
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;
@end
You can’t perform that action at this time.