This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func exponentialMovingAverage(currentAverage: Double, newValue: Double, smoothing: Double) -> Double { | |
return smoothing * newValue + (1 - smoothing) * currentAverage | |
} | |
// Usage: | |
// var a = 3 | |
// a = exponentialMovingAverage(a, 8, 0.5) | |
// Swift 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PlaygroundSupport | |
import SwiftUI | |
// MARK: - Game | |
extension TicTacToe.Board { | |
var hasNonEmptyCells: Bool { | |
self.flatMap { $0 } | |
.contains(where: { $0 != .empty }) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -x | |
sudo rm -rf /Library/Developer/CommandLineTools/ | |
sudo rm -rf /Applications/Xcode.app | |
rm -rf ~/Library/Preferences/com.apple.dt.Xcode.plist | |
rm -rf ~/Library/Caches/com.apple.dt.Xcode | |
rm -rf ~/Library/Application\ Support/Xcode | |
rm -rf ~/Library/Developer/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
/** | |
* An @ViewBuilder will only allow statements that result in a View. | |
* `print(value)` does not result in a view and is not allowed in a @ViewBuilder such as `var body: some View`. | |
* This view extension allows you print inside a @ViewBuilder. | |
* | |
* Usage: | |
* ``` | |
* struct MyView: View { | |
* var body: some View { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FFMPEG=$(command -v ffmpeg) | |
INFILE=$1 | |
OUTFILE="${INFILE}.gif" | |
TMPFILE="${INFILE}_gifify_palette.png" | |
if ! $FFMPEG -L > /dev/null 2>&1; then | |
echo "Run: brew install ffmpeg" | |
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! sh | |
# Install: | |
# - Place this file next to the Package.swift in your project | |
# - Open a terminal and cd to the project directory | |
# - Run: brew install lcov | |
# - Run: chmod +x coverage.sh | |
# | |
# Usage: | |
# Run: ./coverage.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Retry a block of code until it succeeds, maximum n times | |
/// | |
/// Usage: | |
/// ``` | |
/// var failTimes = 3 | |
/// try retry(5) { | |
/// if failTimes > 0 { | |
/// failTimes -= 1 | |
/// throw MyError() | |
/// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Drop this code in an xcode playground for iOS | |
// Open the canvas to see the view rendered | |
// Cmd+Enter to Run | |
import PlaygroundSupport | |
import SwiftUI | |
// Wrap your application state in observable objects | |
// Adhering to ObservableObject is needed for @ObservedObject, @StateObject and @EnvironmentObject | |
final class Clock: ObservableObject { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol P {} | |
struct S: P {} | |
extension P { | |
static var a: P { S() } | |
} | |
let v = P.a | |
// error: static member 'a' cannot be used on protocol metatype 'P.Protocol' | |
// let v = P.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Paste these lines into your ~/.bashrc or other shell initialisation script | |
# Note that for most of these, your gitconfig has to have the aliasses from the .gitconfig in this gist | |
alias co='git checkout' | |
alias st='git status' | |
alias add='git add' | |
alias commit='git commit' | |
# Amend anything that is staged |
NewerOlder