Skip to content

Instantly share code, notes, and snippets.

@icanzilb
icanzilb / Task.sleep.swift
Created September 9, 2021 09:30
Task.sleep(seconds:)
extension Task where Success == Never, Failure == Never {
/// Suspends the current task for at least the given duration in seconds.
/// Throws if the task is cancelled while suspended.
/// - Parameter seconds: The sleep duration in seconds.
static func sleep(seconds: TimeInterval) async throws {
try await Task.sleep(nanoseconds: UInt64(seconds * 1_000_000_000))
}
}
@srirammanian
srirammanian / PagingList.swift
Last active June 19, 2019 20:10
Generic infinite paging list in SwiftUI
//
// PagingList.swift
//
// Created by Sriram Manian on 6/17/19.
// Copyright © 2019 Sriram Manian. All rights reserved.
//
import SwiftUI
import Combine
@bardonadam
bardonadam / DynamicColor.swift
Last active August 20, 2021 03:22
DynamicColor property wrapper type to remove boilerplate code when defining dynamic colors to adopt dark mode on iOS 13
@DynamicColor(lightVariant: .black, darkVariant: .white)
static var dynamicLabelColor: UIColor
@propertyWrapper
struct DynamicColor {
let lightVariant: UIColor
let darkVariant: UIColor
var wrappedValue: UIColor {
get {
@erica
erica / fold.md
Last active August 6, 2019 19:49
@JohnSundell
JohnSundell / AnyOf.swift
Created August 21, 2017 21:23
A way to easily compare a given value against an array of candidates
import Foundation
struct EquatableValueSequence<T: Equatable> {
static func ==(lhs: EquatableValueSequence<T>, rhs: T) -> Bool {
return lhs.values.contains(rhs)
}
static func ==(lhs: T, rhs: EquatableValueSequence<T>) -> Bool {
return rhs == lhs
}
@nrollr
nrollr / MySQL.md
Last active October 28, 2020 02:53
Install MySQL on El Capitan using Homebrew

Install MySQL on OS X El Capitan

Normally the installation of MySQL can be achieved with a single command, which executes a script provided by MacMiniVault : bash <(curl -Ls http://git.io/eUx7rg)

However, at the time of writing the script is not compatible with OS X El Capitan (10.11)

Install MySQL using Homebrew

An alternative to the aforementioned installation script is installing MySQL using Homebrew. This gist assumes you already have Homebrew installed, if not first read the article "Homebrew and El Capitan"

Make sure Homebrew has the latest formulae, so run brew update first

@benvium
benvium / search-array.swift
Last active March 29, 2024 22:29
searching arrays in apple swift. Search for matching strings and strings containing other strings.
class Person {
var name = ""
var age = 0
init(name: String, age:Int) {
self.name = name
self.age = age
}
}
@deekayen
deekayen / 1-1000.txt
Last active October 5, 2024 21:32
1,000 most common US English words
the
of
to
and
a
in
is
it
you
that