Skip to content

Instantly share code, notes, and snippets.

Avatar

Sam Warner sam-w

  • LoungeBuddy
  • Sydney, Australia
View GitHub Profile
View set-operations.ts
/**
* 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`),
View Color+UIKit.swift
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
View ModalLink.swift
@sam-w
sam-w / asc-desc-text
Created Jan 9, 2020
Text sample likely to hit maximum ascenders and descenders for any font which supports the glyphs
@sam-w
sam-w / xcode-env
Created Dec 10, 2019
Xcode 11 New Build System Environment Variables
View xcode-env
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
View Promise.firstSuccess.ts
/**
* 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 / SearchPattern2D.swift
Last active Jul 31, 2019
2D Search Pattern
View SearchPattern2D.swift
//
// SearchPattern2D.swift
// MapScan
//
// Created by Sam Warner on 31/7/19.
// Copyright © 2019 LoungeBuddy. All rights reserved.
//
import UIKit
@sam-w
sam-w / pretty-print-json
Created Jun 27, 2019
Convert directory of json to pretty-printed
View pretty-print-json
for file in output/**/*(.); do cat $file | jq . > /tmp/jq.json; cat /tmp/jq.json > $file; done
@sam-w
sam-w / keys-and-jwts.go
Last active Jun 13, 2019
Golang RSA Keys and JWTs
View keys-and-jwts.go
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"errors"
"fmt"
"time"
"gopkg.in/square/go-jose.v2"
View Import images to .xcassets
#delete the existing images
find '/Users/sam.warner/Domain/domain-ios-app/Resources/Images.xcassets/Loading Spinners/Gray' -name "*.png" -type f -delete
for i in `seq 0 9`; do
#edit Contents.json
sed -i '' "s/\"filename\" :.*@2x.*/\"filename\" : \"spinner-loop_0$i.png\",/g" "/Users/sam.warner/Domain/domain-ios-app/Resources/Images.xcassets/Loading Spinners/Gray/loading-spinner-frame0$i.imageset/Contents.json"
#rename the folder
mv "/Users/sam.warner/Domain/domain-ios-app/Resources/Images.xcassets/Loading Spinners/Gray/loading-spinner-frame0$i.imageset" "/Users/sam.warner/Domain/domain-ios-app/Resources/Images.xcassets/Loading Spinners/Gray/gray-spinner-frame0$i.imageset"
#copy the new images
cp ~/spinner-loop/spinner-loop_0$i.png "/Users/sam.warner/Domain/domain-ios-app/Resources/Images.xcassets/Loading Spinners/Gray/gray-spinner-frame0$i.imageset"