Skip to content

Instantly share code, notes, and snippets.

View collindonnell's full-sized avatar

Collin Donnell collindonnell

View GitHub Profile
@rsms
rsms / sleeping-barber.m
Created November 10, 2010 19:04
Sleeping barber with GCD (Grand Central Dispatch)
int main (int argc, const char * argv[]) {
dispatch_queue_t waitingChairs = dispatch_queue_create("waitingChairs", 0);
dispatch_queue_t barber = dispatch_queue_create("barber", 0);
dispatch_semaphore_t semaphore = dispatch_semaphore_create(3);
NSInteger ident = 0;
while (++ident) {
if (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW) != 0) {
printf("Customer %d turned away\n", ident);
continue;
}
@collindonnell
collindonnell / gist:1458205
Created December 11, 2011 03:58
Draw a two part gradient in a given graphics context in one line of code.
- (void)drawGradientInContext:(CGContextRef)context withStartPosition:(CGPoint)startPosition endPosition:(CGPoint)endPosition startColor:(UIColor *)startColor endColor:(UIColor *)endColor
{
CGFloat locations[2] = {0.0, 1.0};
const CGFloat *startComponents = CGColorGetComponents(startColor.CGColor);
const CGFloat *endComponents = CGColorGetComponents(endColor.CGColor);
CGFloat components[8] = {startComponents[0], startComponents[1], startComponents[2], startComponents[3], endComponents[0], endComponents[1], endComponents[2], endComponents[3]};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, 2);
CGContextDrawLinearGradient(context, gradient, startPosition, endPosition, 0);
@c0diq
c0diq / Xcode4HockeyAppTestFlightintegration.sh
Created March 27, 2012 07:13
Automatic TestFlight/HockeyApp Upload XCode Script
#!/bin/bash
#
# (Above line comes out when placing in Xcode scheme)
#
# Inspired by original script by incanus:
# https://gist.github.com/1186990
#
# Rewritten by martijnthe:
# https://gist.github.com/1379127
#
@ecridge
ecridge / link-icloud-drive.sh
Created October 2, 2016 17:47
Add a symbolic link to iCloud Drive in Bash on macOS.