Skip to content

Instantly share code, notes, and snippets.

View jwilling's full-sized avatar

Jonathan Willing jwilling

View GitHub Profile
@jessearmand
jessearmand / PointyRoundedRect.m
Created January 23, 2011 02:47
Using CG to draw a pointy rounded rect.
//
// From http://stackoverflow.com/questions/4442126/how-to-draw-a-speech-bubble-on-an-iphone
//
void DrawPopupShapeInRect(CGRect rect, CGColorRef borderColor, CGColorRef backgroundColor, CGFloat borderRadius, CGFloat strokeWidth, CGFloat pointerWidth, CGFloat pointerHeight)
{
CGRect currentFrame = self.bounds;
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineWidth(context, strokeWidth);
@chrismiles
chrismiles / MyLayer.m
Created March 14, 2011 07:35
Animate a custom property in a CALayer example.
//
// MyLayer.m
//
// Created by Chris Miles on 14/03/11.
// Copyright 2011 Chris Miles.
//
/*
Animate custom property example:
@micahbrich
micahbrich / PaddedTextFieldCell.rb
Created June 16, 2011 05:35
Awesome Text Fields in MacRuby
class PaddedTextFieldCell < NSTextFieldCell
def drawingRectForBounds(cellFrame)
super
result = cellFrame
padding_left = (result.size.width / 16).round # to make sure text is clear
padding_top = (result.size.height / 4).round
result.origin.x += padding_left
result.origin.y += padding_top
@Kentzo
Kentzo / gist:1188869
Created September 2, 2011 15:08
-[CATextLayer drawInContext:]
;return address *(long*)$esp
;first parameter $rdi
;second parameter $rsi
;third parameter $rdx
;fourth parameter $rcx
;fifth parameter $r8
;sixth parameter $r9
@kgn
kgn / gist:3012995
Created June 28, 2012 18:11
Noise in Cocoa
+ (void)drawNoiseWithOpacity:(CGFloat)opacity inRect:(CGRect)rect{
static UIImage *noiseImage = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
NSUInteger width = 64, height = 64;
NSUInteger size = width*height;
char *rgba = (char *)malloc(size); srand(124);
for(NSUInteger i=0; i < size; ++i){rgba[i] = rand()%256;}
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef bitmapContext =
@jspahrsummers
jspahrsummers / gcd-deadlocks.m
Created September 19, 2012 19:19
Contrived example of two GCD queue-synchronized objects deadlocking
@implementation OuterClass
- (id)init {
self = [super init];
if (self == nil) return nil;
_outerQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
self.innerObject = [[InnerClass alloc] init];
self.innerObject.delegate = self;
//
// FGOManagedObjectContextStack.h
//
// Created by Indragie Karunaratne on 2012-12-23.
// Copyright (c) 2012 Indragie Karunaratne. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface FGOManagedObjectContextStack : NSObject
@jspahrsummers
jspahrsummers / RACSocketReader.h
Last active December 14, 2015 04:59
An example of emulating an asynchronous pull-driven stream with lazy signals. The idea is that the producer (in this case, a socket) should be throttled to a speed that the consumer (the signal subscribers) can handle – accomplished here by using multiple individual signals which only read data when subscribed to.
@interface RACSocketReader : NSObject
// Sends a RACSignal whenever there's new data ready to be read. Each signal
// will send an NSData upon subscription.
//
// If you only want the NSData objects as fast as possible, simply -concat
// this signal to get a eager signal of NSData values.
@property (nonatomic, strong, readonly) RACSignal *signalOfDataSignals;
- (id)initWithSocketDescriptor:(int)fildes;
// Defines a yet undocumented method to add a warning if super isn't called.
#ifndef NS_REQUIRES_SUPER
#if __has_attribute(objc_requires_super)
#define NS_REQUIRES_SUPER __attribute((objc_requires_super))
#else
#define NS_REQUIRES_SUPER
#endif
#endif
@depth42
depth42 / gist:6886194
Last active December 25, 2015 00:09
The xib compiler in Xcode 5.0.1 always sets the scaling bit of all NSViews which results in dramatically reduced performance. Until Apple fixes this severe bug, we work around this by patching NSKeyedUnarchiver to clear the bit during decoding of the compiled xib files. By the way: We filed this bug three months ago under rdar://14359398.
@interface NSKeyedUnarchiver (Xcode5Fix)
@end
@implementation NSKeyedUnarchiver (Xcode5Fix)
+ (void)load
{
[self exchangeInstanceMethod:@selector(decodeInt32ForKey:)
withMethod:@selector(xcode5Fix_decodeInt32ForKey:)];
}