Skip to content

Instantly share code, notes, and snippets.

View bradleymackey's full-sized avatar
👔
Building

Bradley Mackey bradleymackey

👔
Building
View GitHub Profile
@bradleymackey
bradleymackey / vs-code-settings.json
Last active March 11, 2019 19:29
Fix RLS Error on VS Code
// add this line to the user settings to fix the RLS (Rust Language Server) unable to start error
{
"rust-client.channel": "stable"
}

Keybase proof

I hereby claim:

  • I am bradleymackey on github.
  • I am bradleymackey (https://keybase.io/bradleymackey) on keybase.
  • I have a public key ASDQ12_qS4snqloFk1BH5ZXZKIRPlWFMq7EhJfIEXNWxGAo

To claim this, I am signing this object:

@bradleymackey
bradleymackey / autolayout.swift
Last active October 14, 2019 16:20
Helpers for Autolayout I use in basically every project -- make Autolayout more bearable for you!
//
// UIView+Constraints.swift
//
// Created by Bradley Mackey on 30/06/2019.
// Copyright © 2019 Bradley Mackey. All rights reserved.
//
/*
* Abstract: AutoLayout helpers when programmatically defining views
*/
#!/usr/bin/swift sh
/*
Abstract:
Given an image, resize it, creating 1x, 2x and 3x versions for iOS
Internally, we use the `sips` tool to perform this resizing, this is just a nice wrapper.
*/
import Foundation
/**
* Abstract:
* cloning with additional special-hanling logic for Firestore native objects
* adapted from klona
*/
import * as firebaseAdmin from "firebase-admin";
import * as firebaseTest from "@firebase/rules-unit-testing";
export enum Direction {
@bradleymackey
bradleymackey / Atomic.swift
Last active January 8, 2022 15:17
Locking abstraction over any type.
import os
/// An efficient lock to prevent contesting access to a resource across threads
///
/// This is a very thin wrapper around `os_unfair_lock` with a better Swift interface.
/// It also has a similar interface to `NSLock`
public final class Lock: @unchecked Sendable {
@usableFromInline
var _mutex = os_unfair_lock()
/// An efficient lock to prevent contesting access to a resource across threads
///
/// This is a very thin wrapper around `os_unfair_lock` with a better Swift interface.
/// It also has a similar interface to `NSLock`
public final class Lock: @unchecked Sendable {
@usableFromInline
var _mutex = os_unfair_lock()
public init() { }
import Foundation
/// Asynchrously supply and then remember a result.
public final class Eventual<T>: Sendable where T: Sendable {
/// Mediated access to the supplying function.
private let supplierInternal: Atomic<@Sendable () async -> T>
/// The closure that provides the value.
///
/// This will be called implictly when you `get()` the value.
public extension Task where Success == Never, Failure == Never {
/// Blueprint for a task that should be run, but not yet.
struct Blueprint<Output> {
public var priority: TaskPriority
public var operation: @Sendable () async throws -> Output
public init(
priority: TaskPriority = .medium,
operation: @escaping @Sendable () async throws -> Output
) {