Skip to content

Instantly share code, notes, and snippets.

Ben Cohen airspeedswift

Block or report user

Report or block airspeedswift

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@airspeedswift
airspeedswift / shuffle.swift
Last active Feb 2, 2018 — forked from natecook1000/shuffle.swift
Fisher-Yates shuffle as protocol extension on any random-access collection
View shuffle.swift
// adapted from original, which was (c) 2015 Nate Cook, licensed under the MIT license
//
// Fisher-Yates shuffle as protocol extensions
import Darwin
extension CollectionType where Index: RandomAccessIndexType {
/// Return a copy of `self` with its elements shuffled
func shuffle() -> [Generator.Element] {
var list = Array(self)
View Measure.swift
func measure(title: String?, call: () -> Void) {
let startTime = CACurrentMediaTime()
call()
let endTime = CACurrentMediaTime()
if let title = title {
print("\(title): ")
}
println("Time - \(endTime - startTime)")
}
View gist:6c7051b427fa60534c41
import KeychainAPI
let keychain: Keychain = Keychain(service: "com.secondgear.myapp", accessibility: Accessibility.WhenUnlocked)
let userAccount = Account(userName: "justinw@me.com", secret: "lovesecretsexgod")
keychain.add(userAccount)
if let fetchedAccount = keychain.accountFor("justinw@me.com")
{
fetchedAccount.secret = "newpassword"
View Swift Generic Functions
func sortedSet<S: RangeReplaceableCollectionType where S.Generator.Element: Comparable>(seq:S, obj:S)-> [S.Generator.Element] {
let s = reduce(seq, obj){
ac, x in contains(ac,x) ? ac : ac + [x]
}
let set = sorted(s){$0<$1}
return set
}
func insert<S:RangeReplaceableCollectionType, I: SignedIntegerType where I == S.Index.Distance, S.Generator.Element: Equatable>(inout seq:S, ins:S, ind:I) {
// use of abs() prevents a negative value causing the insertIndex to be before the startIndex
You can’t perform that action at this time.