Skip to content

Instantly share code, notes, and snippets.

View zwaldowski's full-sized avatar

Zachary Waldowski zwaldowski

View GitHub Profile
@zwaldowski
zwaldowski / gist:777c5b9e004122ba7930
Last active April 11, 2016 13:31 — forked from groue/gist:f2ecc98b8301ed63d843
A function declared as rethrows that synchronously executes a throwing block in a dispatch_queue.
import Dispatch
@_silgen_name("dispatch_sync") private func os_dispatch_sync(queue: dispatch_queue_t, @noescape _ block: dispatch_block_t)
@_silgen_name("dispatch_barrier_sync") private func os_dispatch_barrier_sync(queue: dispatch_queue_t, @noescape _ block: dispatch_block_t)
private func dispatch_sync_rethrow_wrapper<Return>(queue: dispatch_queue_t, @noescape dispatcher: (dispatch_queue_t, dispatch_block_t) -> Void, @noescape body: () throws -> Return, @noescape onError: ErrorType throws -> Void) rethrows -> Return {
var ret: Return!
var innerError: ErrorType?
os_dispatch_sync(queue) {
// Derived from http://blog.krzyzanowskim.com/2015/10/24/chunksequence-have-cake-and-eat-it/
struct ChunkSequence<Element>: SequenceType {
typealias Collection = AnyForwardCollection<Element>
let collection: Collection
let chunkSize: Collection.Index.Distance
private init<C: CollectionType where C.Index: ForwardIndexType, C.Generator.Element == Element>(_ base: C, chunkSize: C.Index.Distance) {
self.collection = AnyForwardCollection(base)
self.chunkSize = chunkSize.toIntMax()
@zwaldowski
zwaldowski / DynamicTypeLabel.swift
Last active April 26, 2016 20:18 — forked from indragiek/DynamicTypeLabel.swift
Dynamic Type, made dynamic - with Avenir!
//
// DynamicTypeLabel.swift
//
// Created by Indragie on 10/16/14.
// Copyright (c) 2014 Indragie Karunaratne. All rights reserved.
//
import UIKit
class DynamicTypeLabel : UILabel {
//
// Copyright (c) 2012-2013 Cédric Luthi / @0xced. All rights reserved.
//
#if TARGET_IPHONE_SIMULATOR
@interface NSObject ()
- (void)setItem:(int)item enabled:(BOOL)enabled;
@zwaldowski
zwaldowski / test.m
Created July 13, 2012 17:44 — forked from mikeash/test.m
Cocoa array slicing
// clang -framework Foundation -fobjc-arc -O3 test.m
#import <Foundation/Foundation.h>
@interface NSNumber (RangeCreation)
- (NSValue *): (NSInteger)length;
@end