Skip to content

Instantly share code, notes, and snippets.

import Foundation
extension Optional {
func unwrap(orThrow error: @autoclosure () -> Error) throws -> Wrapped {
guard let value = self else {
throw error()
}
return value
}
@pwc3
pwc3 / gh-gitignore
Last active May 18, 2022 17:30
Downloads Github's recommended .gitignore for the specified language and prints it to stdout
#!/usr/bin/env bash
# Downloads Github's recommended .gitignore for the specified language and prints it to stdout.
#
# When starting a project:
# gh-gitignore Swift > .gitignore
set -euo pipefail
E_BADARGS=85
@pwc3
pwc3 / convert-framework.sh
Last active July 9, 2024 06:29
Convert Legacy Framework to XCFramework
#!/usr/bin/env bash
# Converts a legacy framework into an xcframework.
# Usage: convert-framework.sh input_framework output_xcframework
set -euo pipefail
E_BADARGS=85
if [ $# -ne 2 ]; then
echo "Usage: $(basename $0) framework xcframework"
@pwc3
pwc3 / generate-git-revision.sh
Last active May 12, 2020 02:50
Generate GitRevision.swift for inclusion in an Xcode project
#!/usr/bin/env bash
set -euo pipefail
cat <<SWIFT
//
// GitRevision.swift
//
// This file was automatically generated. Do not edit manually. It will be overwritten on every build.
//
@pwc3
pwc3 / git-rmtag
Last active May 7, 2020 14:54
Remove Git Tag
#!/usr/bin/env bash
set -euo pipefail
E_BADARGS=85
if [ $# -ne 1 ]; then
echo "Usage: $(basename $0) tag-name"
exit $E_BADARGS
fi
@pwc3
pwc3 / ValueTypeCapture.swift
Created April 29, 2020 14:48
Value Type Capture
import Foundation
class SimulatedOperation {
// Simulated function that collects data from multiple async calls.
// Build an array of [String] values, one element per async call. Hit the
// completion block once all of the elements are populated.
func collectData(completion: @escaping ([String]) -> Void) {
// Locally accumulate the results here. Why does this work?
@pwc3
pwc3 / ppjson
Last active May 11, 2020 00:57
Pretty-Print JSON
#!/usr/bin/env python
from __future__ import print_function
import sys
import json
try:
json.dump(json.load(sys.stdin), sys.stdout, sort_keys=True, indent=4)
except ValueError as err:
print("Error:", err, file=sys.stderr)
@pwc3
pwc3 / pdf2appicon.py
Created March 27, 2020 17:42
Converts a PDF to an iOS app icon
#!/usr/bin/env python
import argparse
import codecs
import json
import subprocess
import sys
def parse_args(argv):
if argv is None:
@pwc3
pwc3 / unfuck-xcode
Last active October 14, 2021 14:19
Unfuck Xcode
#!/usr/bin/env bash
set -euo pipefail
echo "Exiting Xcode"
osascript -e 'quit app "Xcode"'
echo "Deleting DerivedData"
rm -rf ~/Library/Developer/Xcode/DerivedData/*
@pwc3
pwc3 / simulator-floating-name.py
Last active October 24, 2019 21:41
Show/HIde the floating name at the bottom of the iOS Simulator
#!/usr/bin/env python
import argparse
import codecs
import subprocess
import sys
def parse_args(argv):
if argv is None:
argv = sys.argv[1:]