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
\ |
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
/// ContentLoader is a lightweight state manager for loading and displaying content and/or errors. | |
/// It allows you to repeatedly make requests and display new content or cached content in the event of an error. | |
/// Commonly known as RemoteData or LCE (Loading / Content / Error). | |
/// Inspired by https://tech.instacart.com/lce-modeling-data-loading-in-rxjava-b798ac98d80 | |
/// | |
final class ContentLoader<T> { | |
init() { } | |
@discardableResult func loader(_ loader: (() -> Void)?) -> ContentLoader<T> { | |
self.loader = loader |
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
# Thanks to: https://medium.com/doraoutloud/migrating-your-apple-notes-to-evernote-12114418ba00 | |
# Open "Script Editor" application, paste and run. | |
tell application "Notes" | |
set theMessages to every note | |
repeat with thisMessage in theMessages | |
set myTitle to the name of thisMessage |
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 { | |
func localized(_ args: CVarArg...) -> String { | |
return String(format: NSLocalizedString(self, comment: ""), arguments: args) | |
} | |
} | |
let format = NSLocalizedString("Hello %@", comment: "") | |
print(String(format: format, "World")) |
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
// | |
// MigrationCreateItems.swift | |
// Stash | |
// | |
// Created by Andrew C on 8/30/17. | |
// Copyright © 2017 Andrew Crookston. All rights reserved. | |
// License: MIT | |
// | |
import Foundation |
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
struct Test { | |
let computed: Int | |
init(a: Int, b: Int, c: Int, d: Int, e: Int = 0, f: Int = 0, g: Int = 0, h: Int = 0) { | |
var value: Int = (a << 56) | |
value |= (b << 48) | |
value |= (c << 40) | |
value |= (d << 32) | |
value |= (e << 24) | |
value |= (f << 16) | |
value |= (g << 8) |
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 UIColor { | |
static func rgba(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat, _ a: CGFloat) -> UIColor { | |
return UIColor(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: a) | |
} | |
} |
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 TimeInterval { | |
var milliseconds: Int { | |
return Int(truncatingRemainder(dividingBy: 1) * 100) | |
} | |
var minutes: Int { | |
return Int(self / 60) | |
} | |
var seconds: Int { |
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
// | |
// CoreExtensions | |
// | |
// Created by Andrew Crookston on 1/30/18. | |
// | |
import Foundation | |
public extension DateComponents { | |
public static func with(year: Int? = nil, month: Int? = nil, day: Int? = nil, hour: Int? = nil, minute: Int? = nil, second: Int? = nil, calendar: Calendar = .current, timeZone: TimeZone? = nil) -> DateComponents { |
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 NSRegularExpression { | |
convenience init(substrings: [String], options: NSRegularExpression.Options) throws { | |
let escapedSubstrings: [String] = substrings.map(NSRegularExpression.escapedTemplate) | |
let pattern: String = escapedSubstrings.joined(separator: "|") | |
try self.init(pattern: pattern, options: options) | |
} | |
convenience init?(with pattern: String, options: NSRegularExpression.Options = []) { | |
do { | |
try self.init(pattern: pattern, options: options) |
NewerOlder