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
var AWS = require('aws-sdk'); | |
AWS.config.update({ | |
accessKeyId: '{AWS_KEY}', | |
secretAccessKey: '{AWS_SECRET}', | |
region: '{SNS_REGION}' | |
}); | |
var sns = new AWS.SNS(); |
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
console.log('Loading function'); | |
var AWS = require('aws-sdk'); | |
AWS.config.region = 'us-west-2'; | |
exports.handler = function(event, context) { | |
console.log("\n\nLoading handler\n\n"); | |
var sns = new AWS.SNS(); | |
sns.publish({ |
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
private extension ObservableType { | |
func withPrevious(startWith first: E) -> Observable<(E, E)> { | |
return scan((first, first)) { ($0.1, $1) }.skip(1) | |
} | |
} |
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
final class discardableThumbnail: NSDiscardableContent { | |
var thumbnail: UIImage! | |
var accessCounter: Int = 0 | |
init(image: UIImage) { | |
thumbnail = image | |
} | |
func beginContentAccess() -> Bool { | |
if !(self.thumbnail != nil) { |
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 String { | |
public var isEmail: Bool { | |
let dataDetector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) | |
let firstMatch = dataDetector?.firstMatch(in: self, options: .reportCompletion, range: NSRange(location: 0, length: count)) | |
return (firstMatch?.range.location != NSNotFound && firstMatch?.url?.scheme == "mailto") | |
} | |
} |
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
// to run something in 0.1 seconds | |
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { | |
// your code here | |
} |
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
let start = DispatchTime.now() | |
let end = DispatchTime.now() | |
let nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds // Difference in nano seconds (UInt64) | |
let timeInterval = Double(nanoTime) / 1_000_000_000 // Could overflow for long running tests | |
LogInfo("Time to generate pdf data: \(timeInterval) seconds") |
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
protocol CusotmEquatable { | |
func isEqual(to rhs: CusotmEquatable) -> Bool | |
} | |
extension CusotmEquatable where Self: Equatable { | |
func isEqual(to rhs: CusotmEquatable) -> Bool { | |
guard let rhs = rhs as? Self else { | |
return false | |
} | |
return self == 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
var localized: String { | |
return NSLocalizedString(self, comment: "") | |
} |
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 NSMutableAttributedString { | |
@discardableResult | |
func setAsLink(_ textToFind: String, linkURL: String) -> Bool { | |
let foundRange = mutableString.range(of: textToFind) | |
guard foundRange.location != NSNotFound else { return false } | |
addAttribute(NSAttributedStringKey.link, value: linkURL, range: foundRange) | |
return true | |
} | |
} |
OlderNewer