Skip to content

Instantly share code, notes, and snippets.

url=https://gist.githubusercontent.com/samdods/1ac451370729c0e9df72cce8bfcaa828/raw/3548420695acec86c721ffa9c74424212dcc2283/impactChecker.swift
exe=/tmp/impactChecker`uuidgen`
curl -fsSL $url > $exe
chmod +x $exe
git diff `git merge-base origin/develop HEAD`..HEAD --name-only | $exe
rm $exe
url=https://gist.githubusercontent.com/samdods/1ac451370729c0e9df72cce8bfcaa828/raw/3548420695acec86c721ffa9c74424212dcc2283/impactChecker.swift
curl -fsSL $url > /tmp/impactChecker
chmod +x /tmp/impactChecker
#!/usr/bin/swift
import Foundation
extension Array where Element == String {
func sortedWithPodsLast() -> [String] {
self.sorted { lhs, rhs in
if lhs.hasPrefix("Pods_") && rhs.hasPrefix("Pods_") {
return lhs < rhs
{
"groups": [
{
"name": "reds",
"colors": [
{
"name": "red",
"hex": "FF0000"
},
{
override func viewDidLoad() {
super.viewDidLoad()
isModalInPresentation = true
navigationController?.presentationController?.delegate = self
}
/// conforming to UIAdaptivePresentationControllerDelegate
func presentationControllerDidAttemptToDismiss(_ presentationController: UIPresentationController) {
let controller = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
// ...
@samdods
samdods / AVSpeechSynthesizer+Shared.swift
Created October 9, 2019 10:11
Showing AVSpeechSynthesizer extension for Speak Selection blog post
extension AVSpeechSynthesizer {
static let forSpeakSelection: AVSpeechSynthesizer = {
let synthesizer = AVSpeechSynthesizer()
synthesizer.delegate = SpeechDelegate.shared
return synthesizer
}()
}
// MARK: - Private
@samdods
samdods / SelectableLabel-Truncated.swift
Created October 9, 2019 09:57
Snippet of the SelectableLabel.swift for a blog post on Speak Selection
final class SelectableLabel: UILabel {
// 1...
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupTextSelection()
}
private func setupTextSelection() {
enum Frank {
static func start(port: Int = 8080) {
// ... steps 1 to 8 from sample code above ...
}
}
typealias ResponseBodyProvider = () -> String
private var routedGET: [String: ResponseBodyProvider] = [:]
func get(_ path: String, bodyProvider: @escaping ResponseBodyProvider) {
get("/home") {
return "🏠"
}
get("/people") {
return """
<html><head><style>
h1 { font-size:4cm; text-align: center }
</style></head>
<body><h1>👫👫👫👫👫</h1></body>
@samdods
samdods / SwiftServer-Loop.swift
Last active April 10, 2019 11:40
Listening on a socket and waiting for request
while(true) {
// 5: Wait for a request
let fd = accept(sock, nil, nil)
print("Connection made")
guard fd >= 0 else {
print("Can't accept connection")