Skip to content

Instantly share code, notes, and snippets.

@liamnichols
liamnichols / README.md
Created January 30, 2024 10:31
A bit of an overview of issues using offset-based pagination when concerned with mutation of the paginated content

Offset based pagination and mutating lists

Offset pagination offers a simple solution when it comes to paging a collection of data where the contents of the collection infrequently updates.

When using offset-based pagination, the client will specify the page of data that they require, and the size of the page. For example, lets consider requesting letters of the alphabet. When working with a page size of 5, the data will be broken out into the following pages:

Letter | A B C D E  F G H I J  K L M N O  P Q R S T  U V W X Y  Z
 Page  | 1 1 1 1 1  2 2 2 2 2  3 3 3 3 3  4 4 4 4 4  5 5 5 5 5  6
import Foundation
public struct Localizer {
/// Returns the best match localized string for the given locale based on the languages available as part of the bundle.
///
/// This method is similar to the system `NSLocalizedString(_:tableName:bundle:value:comment:)` function, but its resolution is much more granular.
///
/// With `NSLocalizedString`, if the current language is missing a phrase for the specified `key`, it would return the `value`, or the `key` even if the bundle contained the phrase in a different (but relevant) language.
///
/// Using this method, a lookup list will be made using `Bundle.preferredLocalizations(from:forPreferences:)` instead, and each language in the order of most preferable will be searched instead.
require_relative './helpers/config_item_validation_helpers'
require 'trainer'
module Fastlane
module Actions
class ExportBitriseTestReportAction < Action
extend ConfigItemValidationHelpers
class Runner
attr_reader :name, :xcresult_path, :test_result_dir, :deploy_dir
@liamnichols
liamnichols / Example.swift
Last active March 14, 2024 12:22
Embed a SwiftUI view inside a UITextView/UITextField inputAccessoryView to present it above the keyboard
import SwiftUI
import UIKit
class ViewController: UIViewController {
private lazy var textField: UITextField = {
let textField = UITextField()
textField.borderStyle = .roundedRect
textField.translatesAutoresizingMaskIntoConstraints = false
textField.setInputAccessoryView(height: 56) {
ScrollView(.horizontal) {
import Foundation
import XCTest
extension XCTestCase {
/// Waits for an escaping closure to be invoked with a result value for the specified timeout duration and returns the value.
///
/// When using this method, you must trigger work inside the `performWork` closure that invokes the `completion` closure exactly once.
/// Failure to do so within the specified `timeout` will result in an error being thrown.
///
/// ```swift
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "StaticSwiftSyntaxParser",
products: [
.library(name: "StaticSwiftSyntaxParser", type: .static, targets: ["StaticSwiftSyntaxParser"])
],
import Cocoa
import Foundation
// MARK: - DataModule
// Types here have a 1:1 match against the API spec and are generated from an OpenAPI specificaition
// They are public types of the DataModule intended only for use within the DomainModule
public struct CollectionDTO: Equatable {
public let id: Int
@liamnichols
liamnichols / URL+StaticString.swift
Created July 10, 2020 06:52
A non-failable initialiser extension for URL that accepts StaticString
import Foundation
extension URL {
/// Initialize with a static string.
///
/// If the `URL` cannot be formed with the string (for example, if the string contains characters that are illegal in a URL, or is an empty string), a precondition failure will trigger at runtime.
init(staticString: StaticString) {
guard let url = Self.init(string: String(describing: staticString)) else {
preconditionFailure("'\(staticString)' does not represent a legal URL")
}
diff --git a/spec/fixtures/SwiftFile.swift b/spec/fixtures/SwiftFile.swift
index 0e18440..9dda539 100755
--- a/spec/fixtures/SwiftFile.swift
+++ b/spec/fixtures/SwiftFile.swift
@@ -10,10 +10,33 @@ module Danger
// Hello, World! Program
import Swift
var tempString: String? = "Hello, World!"
print(tempString!)
@liamnichols
liamnichols / sign_in_with_apple.yml
Created February 21, 2020 14:53
Localisations of the "Sign in with Apple" string taken from Xcode 11.1
SIGN_IN_WITH_APPLE:
- de: Mit Apple anmelden
- he: התחברות באמצעות Apple
- en_AU: Sign in with Apple
- ar: تسجيل الدخول باستخدام Apple
- el: Σύνδεση μέσω Apple
- ja: Appleでサインイン
- en: Sign in with Apple
- uk: Увійти з Apple
- es_419: Iniciar sesión con Apple