View draft.swift
/// 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 |
View notes migration.scpt
# 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 |
View String+Extensions.swift
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")) |
View MigrationCreateItems.swift
// | |
// MigrationCreateItems.swift | |
// Stash | |
// | |
// Created by Andrew C on 8/30/17. | |
// Copyright © 2017 Andrew Crookston. All rights reserved. | |
// License: MIT | |
// | |
import Foundation |
View fast_code.swift
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) |
View UIColorExtensions.swift
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) | |
} | |
} |
View TimeIntervalExtensions.swift
extension TimeInterval { | |
var milliseconds: Int { | |
return Int(truncatingRemainder(dividingBy: 1) * 100) | |
} | |
var minutes: Int { | |
return Int(self / 60) | |
} | |
var seconds: Int { |
View DateExtensions.swift
// | |
// 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 { |
View NSRegularExpression.swift
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