Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

Stan Stadelman sstadelman

🚀
View GitHub Profile
View ThrowingInorder.swift
import Foundation
func testIsBST() {
let list = [2, -10, -45, 200, 48, 10, 38, 47, 4, 2, 5]
var tree = BinaryTree<Int>(2)
for i in list[1...] {
tree.insert(i)
}
let test = isBST(tree)
View swiftpm-docker.sh
# references: https://oleb.net/2020/swift-docker-linux/
# TO LAUNCH DOCKER SWIFT ENV (from package root)
docker pull swiftlang/swift:nightly-5.3-bionic
# docker run --rm --privileged --interactive --tty --volume "$(pwd):/src" --workdir "/src" swift:latest
docker run --rm --privileged --interactive --tty --volume "$(pwd):/src" --workdir "/src" swiftlang/swift:nightly-5.3-bionic
# FROM INSIDE DOCKER
apt-get update && apt-get upgrade
apt-get install libsqlite3-dev
@sstadelman
sstadelman / String+RegEx.swift
Created Jul 12, 2020
String + Lookahead capture
View String+RegEx.swift
extension String {
var lookaheadCapture: String {
#"\s?\#(self)\s+(?<\#(self)>(\S++))"#
}
}
@sstadelman
sstadelman / String+RegEx.swift
Created Jul 12, 2020
String + Lookahead capture
View String+RegEx.swift
extension String {
var lookaheadCapture: String {
#"\s?\#(self)\s+(?<\#(self)>(\S++))"#
}
}
@sstadelman
sstadelman / git-check-status.sh
Last active Feb 26, 2020
Check status of nested repositories
View git-check-status.sh
for f in *; do
if [ -d ${f} ]; then
cd $(echo $f)
echo $(pwd)
for g in *; do
if [ -d ${g} ]; then
# Will not run if no directories are available
cd $(echo $g)
echo $(pwd) >> ../../git-check-status-output.txt
View bootstrap_swift_environment.sh
brew install cmake ninja
brew install sccache
mkdir swift-source
cd swift-source
git clone --branch swift-5.1.5-RELEASE git@github.com:apple/swift.git
./swift/utils/update-checkout --clone-with-ssh
# ./swift/utils/update-checkout --tag swift-5.1.5-RELEASE
# sccache --start-server
./swift/utils/build-script --clean --xcode --release-debuginfo
./swift/utils/build-script --ios --release-debuginfo
@sstadelman
sstadelman / CodableEnum.swift
Created Nov 19, 2019
Example of Codable enum
View CodableEnum.swift
enum QuicklinkBinding: Codable {
case icon(String)
case title(String)
case description(String)
case action(Action)
enum CodingKeys: CodingKey {
case icon, title, description, action
}
@sstadelman
sstadelman / MustacheRegex.swift
Created Nov 19, 2019
Matcher to find mustache placeholder keys and replacement ranges
View MustacheRegex.swift
extension Array where Element == NSRange {
func maxRange() -> Int {
return self.reduce(0) { (prev, next) in
let maxNext = NSMaxRange(next)
return Swift.max(prev, maxNext)
}
}
}
extension String {
View gist:18ee4374b7e9b3f03727afd9706fe978
brew install cmake ninja
mkdir swift-source
cd swift-source
git clone git@github.com:apple/swift.git
./swift/utils/update-checkout --clone-with-ssh
cd swift
utils/build-script --release-debuginfo
cd ..
alias st=/Users/stan/github/swift-source/build/Ninja-RelWithDebInfoAssert/swift-macosx-x86_64/bin/sourcekitd-test
View ArabicCharacterSet.swift
var arabic = CharacterSet(charactersIn: Unicode.Scalar(UInt16(0x0600))!...Unicode.Scalar(UInt16(0x06ff))!)
let arabicSupplement = CharacterSet(charactersIn: Unicode.Scalar(UInt16(0x750))!...Unicode.Scalar(UInt16(0x077f))!)
let arabicExtendedA = CharacterSet(charactersIn: Unicode.Scalar(UInt16(0x08a0))!...Unicode.Scalar(UInt16(0x08ff))!)
let arabicPresentationFormsA = CharacterSet(charactersIn: Unicode.Scalar(UInt16(0xfb50))!...Unicode.Scalar(UInt16(0xfdff))!)
let arabicPresentationFormsB = CharacterSet(charactersIn: Unicode.Scalar(UInt16(0xfe70))!...Unicode.Scalar(UInt16(0xfeff))!)
let rumiNumeralSymbols = CharacterSet(charactersIn: Unicode.Scalar(UInt32(0x10e60))!...Unicode.Scalar(UInt32(0x10e7f))!)
let indicSiyaqNumbers = CharacterSet(charactersIn: Unicode.Scalar(UInt32(0x1ec70))!...Unicode.Scalar(UInt32(0x1ecbf))!)
let ottomanSiyaqNumbers = CharacterSet(charactersIn: Unicode.Scalar(UInt32(0x1ed00))!...Unicode.Scalar(UInt32(0x1ed4f))!)