Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian Williams briandw

  • Mountain View, Ca
View GitHub Profile
@briandw
briandw / XCTestCase-RLWaitWithExpectation.m
Created Jul 8, 2015
Use this in your Xcode test cases to wait for something to happen while waiting on an exception
View XCTestCase-RLWaitWithExpectation.m
#import <XCTest/XCTest.h>
@interface XCTestCase (RLWaitWithExpectation)
- (void)waitFor:(NSTimeInterval)seconds withExpectationBlock:(BOOL (^)())block;
@end
@implementation XCTestCase (RLWaitWithExpectation)
@briandw
briandw / RLCrashyView.m
Created Oct 31, 2013
This will crash the Mac OS X Mavericks window server.
View RLCrashyView.m
//
// RLCrashyView.m
// CrashyMcCrashy
//
// Created by brian on 10/31/13.
// Copyright (c) 2013 Rantlab. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@briandw
briandw / RLArrowView.m
Created Jun 24, 2013
rantlab 1 full arrow view
View RLArrowView.m
//
// RLArrowView.m
//
// Created by brian on 6/20/13.
// Copyright (c) 2013 RantLab. All rights reserved.
//
#import "RLArrowView.h"
@implementation RLArrowView
View gist:5851387
- (void)wiggleFromPath:(CGPathRef)path target:(CGPoint)target amount:(CGFloat)amount
{
CGPoint middle = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
CGPathRef endPath = [RLArrowView createPathWithArrowFromPoint:middle
toPoint:target
tailWidth:2.0
headWidth:10.0
headLength:20.0
wiggle:amount];
@briandw
briandw / gist:5851365
Last active Dec 18, 2015
rantlab post 1.3
View gist:5851365
CGPathRef endPath = [RLArrowView createPathWithArrowFromPoint:middle
toPoint:target
tailWidth:2.0
headWidth:10.0
headLength:20.0
wiggle:0];
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context){
@briandw
briandw / gist:5851343
Last active Dec 18, 2015
rantlab post 1.2
View gist:5851343
- (void)mouseDown:(NSEvent *)event
{
arrow = [CAShapeLayer layer];
CGFloat minMagnitude = 20;
CGPoint middle = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
CGPoint vector = CGPointMake(target.x-middle.x, target.y-middle.y);
CGFloat magnitude = sqrt(vector.x*vector.x+vector.y*vector.y);
CGPoint start = CGPointMake(middle.x+vector.x/magnitude*minMagnitude, middle.y+vector.y/magnitude*minMagnitude);
@briandw
briandw / gist:5851290
Last active Dec 18, 2015
rantlab post 1.1
View gist:5851290
+ (CGPathRef )createPathWithArrowFromPoint:(CGPoint)startPoint
toPoint:(CGPoint)endPoint
tailWidth:(CGFloat)tailWidth
headWidth:(CGFloat)headWidth
headLength:(CGFloat)headLength
wiggle:(CGFloat)wiggle
{
CGFloat length = hypotf(endPoint.x - startPoint.x, endPoint.y - startPoint.y);
CGPoint points[9];
View NSObject+BlockObservation.h
//
// 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>