Skip to content

Instantly share code, notes, and snippets.

View jwilling's full-sized avatar

Jonathan Willing jwilling

View GitHub Profile
@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;
@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 =
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@0xced
0xced / NSRunningApplication+DockIcon.h
Created March 15, 2012 16:00
NSRunningApplication category to dynamically show and hide any running application icon in the Dock
//
// Created by Cédric Luthi on 2011-05-03
// Copyright 2011-2012 Cédric Luthi. All rights reserved.
//
#import <AppKit/AppKit.h>
@interface NSRunningApplication (DockIcon)
- (BOOL) setDockIconHidden_xcd:(BOOL)dockIconHidden;
@bignerdranch
bignerdranch / BNRTimeBlock.h
Created March 9, 2012 13:51
Timing Utility Post 20120308
CGFloat BNRTimeBlock (void (^block)(void));
@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
@lukeredpath
lukeredpath / ExampleClass.m
Created June 30, 2011 22:18
Macro for creating your "shared instance" using GCD
@implementation MySharedThing
+ (id)sharedInstance
{
DEFINE_SHARED_INSTANCE_USING_BLOCK(^{
return [[self alloc] init];
});
}
@end
@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
@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:
@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);