Skip to content

Instantly share code, notes, and snippets.

View hollance's full-sized avatar

Matthijs Hollemans hollance

View GitHub Profile
@JadenGeller
JadenGeller / Fraction.swift
Last active January 5, 2023 06:28
Fractions in Swift
// Now availbile as a Swift package on GitHub!
// https://github.com/jadengeller/fractional
public typealias Fraction = Fractional<Int>
private func gcd<Number: IntegerType>(var lhs: Number, var _ rhs: Number) -> Number {
while rhs != 0 { (lhs, rhs) = (rhs, lhs % rhs) }
return lhs
}
// See: https://devforums.apple.com/message/1000934#1000934
import Foundation
// Logic
operator prefix ¬ {}
@prefix func ¬ (value: Bool) -> Bool {
return !value
}
anonymous
anonymous / Set.swift
Created June 10, 2014 17:43
import Swift
struct SetGenerator<T : Hashable> : Generator {
var dictGenerator : DictionaryGenerator<T, Void>
init(_ d : Dictionary<T,Void>) {
dictGenerator = d.generate()
}
@jianpx
jianpx / wwdc2014-videos-and-pdf
Created June 7, 2014 13:42
wwdc 2014 videos and pdf download links, including HD/SD version.
http://devstreaming.apple.com/videos/wwdc/2014/403xxksrj0qs8c0/403/403_hd_intermediate_swift.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/403xxksrj0qs8c0/403/403_sd_intermediate_swift.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/403xxksrj0qs8c0/403/403_intermediate_swift.pdf?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/419xxli6f60a6bs/419/419_hd_advanced_graphics_and_animation_performance.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/419xxli6f60a6bs/419/419_sd_advanced_graphics_and_animation_performance.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/419xxli6f60a6bs/419/419_advanced_graphics_and_animation_performance.pdf?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/101xx36lr6smzjo/101/101_hd.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/101xx36lr6smzjo/101/101_sd.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2014/236xxwk3fv82sx2/236/236_hd_building_interruptible_and_responsive_interactions.mov?dl=1
http://devstreaming.apple.com/videos/wwdc/2
@calebd
calebd / ArrayHelpers.swift
Last active November 4, 2022 15:17
Swift Helpers
extension Array {
func first() -> Element? {
if isEmpty {
return nil
}
return self[0]
}
func last() -> Element? {
//
// NudgeModel.h
// NudgeFoundation
//
// Created by Jeremy Tregunna on 10/7/2013.
// Copyright (c) 2013 Jeremy Tregunna. All rights reserved.
//
#import <Foundation/Foundation.h>
@mattt
mattt / uiappearance-selector.md
Last active March 19, 2024 12:52
A list of methods and properties conforming to `UIAppearance` as of iOS 12 Beta 3

Generate the list yourself:

$ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS*.sdk/System/Library/Frameworks/UIKit.framework/Headers
$ grep UI_APPEARANCE_SELECTOR ./*     | \
  sed 's/NS_AVAILABLE_IOS(.*)//g'     | \
  sed 's/NS_DEPRECATED_IOS(.*)//g'    | \
  sed 's/API_AVAILABLE(.*)//g'        | \
  sed 's/API_UNAVAILABLE(.*)//g'      | \
 sed 's/UI_APPEARANCE_SELECTOR//g' | \
#import <UIKit/UIKit.h>
@class BDSegmentedControl;
@protocol BDSegmentedControlDelegate <NSObject>
- (NSUInteger)segmentedControl:(BDSegmentedControl *)segmentedControl numberOfMenuItemsForSegmentAtIndex:(NSUInteger)segmentIndex;
- (UIImage *)segmentedControl:(BDSegmentedControl *)segmentedControl imageForMenuBackgroundForSegmentAtIndex:(NSUInteger)segmentIndex;
- (UIImage *)segmentedControl:(BDSegmentedControl *)segmentedControl imageForMenuItemAtIndex:(NSUInteger)menuItemIndex forSegmentAtIndex:(NSUInteger)segmentIndex;
- (UIImage *)segmentedControl:(BDSegmentedControl *)segmentedControl imageForSelectedMenuItemAtIndex:(NSUInteger)menuItemIndex forSegmentAtIndex:(NSUInteger)segmentIndex;
@mikeash
mikeash / blockforward.m
Created October 21, 2011 02:38
NSInvocation works for blocks too!
#import <dlfcn.h>
#import <Foundation/Foundation.h>
struct BlockDescriptor
{
unsigned long reserved;
unsigned long size;
void *rest[1];
dispatch_block_t RecursiveBlock(void (^block)(dispatch_block_t recurse))
{
// assuming ARC, so no explicit copy
return ^{ block(RecursiveBlock(block)); };
}
typedef void (^OneParameterBlock)(id parameter);
OneParameterBlock RecursiveBlock1(void (^block)(OneParameterBlock recurse, id parameter))
{