Skip to content

Instantly share code, notes, and snippets.

@chriswill0w
chriswill0w / aws-sns-example.js
Created October 25, 2017 12:47 — forked from tmarshall/aws-sns-example.js
aws-sdk sns example, in Node.js
var AWS = require('aws-sdk');
AWS.config.update({
accessKeyId: '{AWS_KEY}',
secretAccessKey: '{AWS_SECRET}',
region: '{SNS_REGION}'
});
var sns = new AWS.SNS();
@chriswill0w
chriswill0w / sns-publish
Created October 25, 2017 12:47 — forked from jeremypruitt/sns-publish
AWS Lambda function to publish to SNS topic
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({
private extension ObservableType {
func withPrevious(startWith first: E) -> Observable<(E, E)> {
return scan((first, first)) { ($0.1, $1) }.skip(1)
}
}
@chriswill0w
chriswill0w / discardableThumbnail.swift
Created November 14, 2017 00:27 — forked from benbahrenburg/discardableThumbnail.swift
UIImage that implements NSDiscardableContent
final class discardableThumbnail: NSDiscardableContent {
var thumbnail: UIImage!
var accessCounter: Int = 0
init(image: UIImage) {
thumbnail = image
}
func beginContentAccess() -> Bool {
if !(self.thumbnail != nil) {
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")
}
}
// to run something in 0.1 seconds
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
// your code here
}
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")
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
var localized: String {
return NSLocalizedString(self, comment: "")
}