Skip to content

Instantly share code, notes, and snippets.

@douglashill
douglashill / KeyboardTableView.swift
Last active March 30, 2023 22:01
A UITableView that allows navigation and selection using a hardware keyboard.
// Douglas Hill, December 2018
// Made for https://douglashill.co/reading-app/
// Find the latest version of this file at https://github.com/douglashill/KeyboardKit
import UIKit
/// A table view that allows navigation and selection using a hardware keyboard.
/// Only supports a single section.
class KeyboardTableView: UITableView {
// These properties may be set or overridden to provide discoverability titles for key commands.
@vzsg
vzsg / 1_configure.swift
Created December 8, 2018 09:23
Vapor 3 Sessions with PostgreSQL example
import FluentPostgreSQL
import Vapor
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
// (1) Standard PostgreSQL setup
try services.register(FluentPostgreSQLProvider())
let pgURL = Environment.get("DATABASE_URL") ?? "postgres://vapor:vapor@127.0.0.1:5432/vapor"
let pgConfig = PostgreSQLDatabaseConfig(url: pgURL)!
import Foundation
extension String {
/// Converts an ISO 8601 formatted `String` into `NSDateComponents`.
///
/// - Note: Does not accept fractional input (e.g.: P3.5Y), must be integers (e.g.: P3Y6M).
/// - SeeAlso: https://en.wikipedia.org/wiki/ISO_8601#Durations
/// - Returns: If valid ISO 8601, an `NSDateComponents` representation, otherwise `nil`.
func ISO8601DateComponents() -> NSDateComponents? {
// Regex adapted from Moment.js https://github.com/moment/moment/blame/develop/src/lib/duration/create.js#L16