This file contains 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
func isLuhnValid(number: String) -> Bool { | |
let asciiOffset: UInt8 = 48 | |
let digits = Array(number.utf8).reverse().map{$0 - asciiOffset} | |
let convert: (UInt8) -> (UInt8) = { | |
let n = $0 * 2 | |
return n > 9 ? n - 9 : n | |
} | |
var sum: UInt8 = 0 |
This file contains 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
func isLuhnValid(number: String) -> Bool { | |
let asciiOffset: UInt8 = 48 | |
let convert: (UInt8) -> (UInt8) = { | |
let n = $0 * 2 | |
return n > 9 ? n - 9 : n | |
} | |
let digits = Array(number.utf8).reverse().map{$0 - asciiOffset} | |
let indices = Array(0..digits.count) | |
let evens = indices.filter{$0 & 1 == 0}.map{digits[$0]} | |
let odds = indices.filter{$0 & 1 == 1}.map{digits[$0]}.map(convert) |
This file contains 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
operator infix || {} | |
@infix func ||<T>(lhs: T?, rhs: T) -> T { | |
return lhs ? lhs! : rhs | |
} |
This file contains 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
-- Adapted from these sources: | |
-- http://peterdowns.com/posts/open-iterm-finder-service.html | |
-- https://gist.github.com/cowboy/905546 | |
-- | |
-- Modified to work with files as well, cd-ing to their container folder | |
on run {input, parameters} | |
tell application "Finder" | |
set my_file to first item of input | |
set filetype to (kind of (info for my_file)) | |
-- Treats OS X applications as files. To treat them as folders, integrate this SO answer: |
This file contains 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 © 2014 Yuri Kotov | |
// | |
#import <UIKit/UIKit.h> | |
@interface ADVTabViewController : UIViewController | |
@property (nonatomic) NSUInteger selectedIndex; | |
@property (nonatomic, copy) NSArray *viewControllers; |
This file contains 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
#ifndef NS_DESIGNATED_INITIALIZER | |
#if __has_attribute(objc_designated_initializer) | |
#define NS_DESIGNATED_INITIALIZER __attribute((objc_designated_initializer)) | |
#else | |
#define NS_DESIGNATED_INITIALIZER | |
#endif | |
#endif |
This file contains 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 © 2014 Yuri Kotov | |
// | |
#import <UIKit/UIKit.h> | |
@interface ADVDiscreteSlider : UISlider | |
@property (nonatomic) float unitValue; |
This file contains 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 © 2014 Yuri Kotov | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSObject (ADVDescription) | |
- (NSString *) autoDescription; |
This file contains 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 <CoreData/CoreData.h> | |
@interface NSManagedObject (ADVCopying) | |
- (instancetype) adv_copyInContext:(NSManagedObjectContext *)context; |
This file contains 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 © 2012 Yuri Kotov | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSData (ADVHexadecimalRepresentation) | |
- (NSString *) hexadecimalRepresentation; |