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 luhnCheck(number: String) -> Bool { | |
var sum = 0 | |
let digitStrings = reverse(number).map { String($0) } | |
for tuple in enumerate(digitStrings) { | |
if let digit = tuple.element.toInt() { | |
let odd = tuple.index % 2 == 1 | |
switch (odd, digit) { | |
case (true, 9): |
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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: brown; icon-glyph: magic; | |
// Show a random MTG Card | |
const { transparent } = importModule('no-background') | |
let card = await randomCard() | |
let widget = await createWidget(card) |
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
/// Describes a type of credit card for a subset of known types. | |
enum CreditCardType: Printable { | |
case Amex, DinersClub, Discover, JCB, MasterCard, Visa, Unknown | |
var description: String { | |
switch self { | |
case .Amex: | |
return "Amex" | |
case .DinersClub: | |
return "Diners Club" |
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
import UIKit | |
import CoreData | |
class BasicFetchedResultsControllerDelegate: NSObject, NSFetchedResultsControllerDelegate { | |
let tableView: UITableView | |
var controllerDidChangeContentCallback: (() -> Void)? | |
/// The threshold for the number of inserts, deletes, and reloads to peform using animations. If the threshold is exceeded, the table will be reloaded using `reloadData()`. The default value is `50`. | |
var numberOfRowOperationsThresholdBeforeFullReloadOccurs = 50 | |
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
extension UIImage { | |
convenience init!(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) { | |
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) | |
UIGraphicsBeginImageContext(rect.size) | |
let context = UIGraphicsGetCurrentContext() | |
CGContextSetFillColorWithColor(context, color.CGColor) | |
CGContextFillRect(context, rect) | |
let image = UIGraphicsGetImageFromCurrentImageContext() |
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
#import <UIKit/UIKit.h> | |
@interface UIColor (Grayscale) | |
- (UIColor *)grayscale; | |
@end |
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
// Swift 2.2 | |
let queue = dispatch_queue_create("myqueue", nil) | |
dispatch_async(queue) { | |
// do stuff | |
} | |
// Swift 3 | |
let queue = DispatchQueue(label: "myqueue") | |
queue.async { | |
// do stuff |
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
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) | |
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending) | |
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) | |
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) | |
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending) |
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
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardShowNotification:) name:UIKeyboardWillShowNotification object:nil]; | |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardHideNotification:) name:UIKeyboardWillHideNotification object:nil]; | |
} | |
- (void)dealloc { | |
[[NSNotificationCenter defaultCenter] removeObserver:self]; | |
} |
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
- (void)viewWillDisappear:(BOOL)animated { | |
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) { | |
// back button was pressed. We know this is true because self is no longer | |
// in the navigation stack. | |
} | |
[super viewWillDisappear:animated]; | |
} |
NewerOlder