Skip to content

Instantly share code, notes, and snippets.

View sam-w's full-sized avatar

Sam Warner sam-w

View GitHub Profile
@sam-w
sam-w / pretty-print-json
Created June 27, 2019 03:31
Convert directory of json to pretty-printed
for file in output/**/*(.); do cat $file | jq . > /tmp/jq.json; cat /tmp/jq.json > $file; done
@sam-w
sam-w / SearchPattern2D.swift
Last active July 31, 2019 03:52
2D Search Pattern
//
// SearchPattern2D.swift
// MapScan
//
// Created by Sam Warner on 31/7/19.
// Copyright © 2019 LoungeBuddy. All rights reserved.
//
import UIKit
/**
* Executes a list of Promises in parallel and resolves with the first successful resolution.
*
* Like `Promise.race` in that it takes a list of Promises and only waits for the first completion, but
* differs in that it requires a _successful_ resolution before it completes. Only rejects if _all_ children reject.
*
* Different
* @param promises a list of promises to resolve.
* @param where an optional predicate. Any Promise `p` which resolves but for which the predicate
* produces an error will behave as `p` instead rejected.
@sam-w
sam-w / xcode-env
Created December 10, 2019 06:18
Xcode 11 New Build System Environment Variables
CLANG_WARN_STRICT_PROTOTYPES=YES
COPY_PHASE_STRIP=NO
ENABLE_STRICT_OBJC_MSGSEND=YES
EXECUTABLES_FOLDER_PATH=consumer-ios-app.app/Executables
HEADERMAP_INCLUDES_PROJECT_HEADERS=YES
JAVA_ZIP_FLAGS=-urg
LOCAL_APPS_DIR=/Applications
REMOVE_CVS_FROM_RESOURCES=YES
SDK_PRODUCT_BUILD_VERSION=17B102
SED=/usr/bin/sed
@sam-w
sam-w / asc-desc-text
Created January 9, 2020 04:18
Text sample likely to hit maximum ascenders and descenders for any font which supports the glyphs
"Ầζq"
@sam-w
sam-w / ModalLink.swift
Created February 27, 2020 12:37
Modal Link
@sam-w
sam-w / set-operations.ts
Created November 24, 2020 08:55
Set Operations
/**
* Returns the union of the two sets (`a ∪ b`),
* i.e. all elements present in either set.
*/
export const union = <T>(a: Set<T>, b: Set<T>) => new Set(
[...a].concat(...b)
)
/**
* Returns the intersection of the two sets (`a ∩ b`),

Keybase proof

I hereby claim:

  • I am sam-w on github.
  • I am sam_w (https://keybase.io/sam_w) on keybase.
  • I have a public key ASC6cjL7YNkszC3qNsAyHsyWXZ5roB3PM1lLEYOl-2iq_Qo

To claim this, I am signing this object:

import SwiftUI
import UIKit
extension Color {
var uiColor: UIColor {
if #available(iOS 14, *) {
// iOS 14 introduces an API to convert SwiftUI.Color to UIKit.UIColor
// but it does not produce a color which reacts to changes in color scheme
// (light mode/dark mode). To make that work we need to extract the color