Math trick: works with any number
(Source: https://twitter.com/Perspective_pic/status/399718664540520448)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// (c) 2015 Nate Cook, licensed under the MIT license | |
// | |
// Fisher-Yates shuffle as protocol extensions | |
extension CollectionType { | |
/// Return a copy of `self` with its elements shuffled | |
func shuffle() -> [Generator.Element] { | |
var list = Array(self) | |
list.shuffleInPlace() | |
return list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
protocol Serializable { | |
static func deserializeInto(bytePtr: UnsafeMutablePointer<UInt8>, bytes: ArraySlice<UInt8>) -> ArraySlice<UInt8> | |
} | |
extension Serializable { | |
typealias WorkaroundSelf = Self | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
struct Person { | |
var name: String = "John" | |
var age: Int = 50 | |
var dutch: Bool = false | |
var address: Address? = Address(street: "Market St.") | |
} | |
struct Address { |
Find a 9 letter string of characters that contains only letters from
acdegilmnoprstuw
such that the hash(the_string) is
910897038977002
Find a 9 letter string of characters that contains only letters from
acdegilmnoprstuw
such that the hash(the_string) is
910897038977002
if hash is defined by the following pseudo-code:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LHNetworking+Endpoint.swift | |
// magellan | |
// | |
// Created by Ivan Bruel on 09/04/15. | |
// Copyright (c) 2015 Passworks S.A. All rights reserved. | |
// | |
import Foundation | |
import Lighthouse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface UIStoryboard (Additions) | |
- (id __nullable)tryInstantiateViewControllerWithIdentifier:(NSString * __nonnull)identifier; | |
@end | |
@implementation UIStoryboard (Additions) | |
- (id)tryInstantiateViewControllerWithIdentifier:(NSString *)identifier { | |
@try { | |
return [self instantiateViewControllerWithIdentifier:identifier]; | |
} | |
@catch (NSException *exception) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Copyright © 2013 Yuri Kotov | |
// | |
#import <UIKit/UIKit.h> | |
@interface ADVPlaceholderViewController : UIViewController | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum StringPaddingStyle {case Left, Right} | |
func padStringToLength( | |
sourceString: String, | |
destinationCount: Int, | |
paddingStyle: StringPaddingStyle = .Left, | |
paddingCharacter: Character = " " | |
) -> String { | |
let padCount = destinationCount - sourceString.characters.count, | |
padString = String(count: padCount, repeatedValue: paddingCharacter) |