Skip to content

Instantly share code, notes, and snippets.

@eonil
eonil / HPSFNavigationStack.swift
Last active December 20, 2023 22:14
HPSFNavigationStack
import SwiftUI
import UIKit
struct HPSFNavigationStack<SliceID: Hashable, Content: View>: View {
private var spec: Spec
enum Action {
case userNavigation([SliceID])
}
init(slices: [SliceID], content: @escaping (SliceID) -> Content) {
spec = Spec(slices: slices, content: content, action: noop)
@eonil
eonil / README.md
Created June 11, 2022 16:15 — forked from IsaacXen/README.md
(Almost) Every WWDC videos download links for aria2c.
@eonil
eonil / ci.bash
Created September 10, 2020 11:52
How to build iOS app project without signing with simulator test.
cd TestApp1
DEST="platform=iOS Simulator,name=iPhone 8,OS=13.6"
SIGNFLAGS="CODE_SIGN_IDENTITY= CODE_SIGNING_REQUIRED=NO CODE_SIGNING_ALLOWED=NO"
xcodebuild clean build test -scheme TestApp1 -sdk iphonesimulator -destination "$DEST" $SIGNFLAGS
~
~
~
@eonil
eonil / impl.md
Last active July 7, 2020 03:01
An Opinion about How to Implement UI Apps for Apple Frameworks

An Opinion about How to Implement UI Apps for Apple Frameworks

Eonil, 2020.

This explains how I organize code of interactive programs.

Overview

@eonil
eonil / sample.swift
Created May 20, 2020 18:48
How to write imperative I/O control program with GCD (spawned thread) and Combine.
import Foundation
import Combine
final class Task<I,O> {
let control = PassthroughSubject<Int,Error>()
let report = PassthroughSubject<Int,Error>()
init() {
let i = Channel(control)
let o = Channel(report)
DispatchQueue.global().async { [i,o] in
@eonil
eonil / sssl.swift
Created January 9, 2020 10:27
Single Selection SwiftUI List
//
// ContentView.swift
// SwiftUIWithNSWindowWithoutTitlebar1
//
// Created by Henry Hathaway on 1/9/20.
// Copyright © 2020 Eonil. All rights reserved.
//
import SwiftUI
@eonil
eonil / topologicalSort.swift
Last active December 27, 2019 18:34
Topological Sort in Swift
extension RelPath: Comparable {
/// Sorts by lexicographical topological order.
public static func < (_ a:RelPath, _ b:RelPath) -> Bool {
let c = Swift.min(a.count, b.count)
for i in 0..<c {
if a[i] < b[i] { return true }
if a[i] > b[i] { return false }
}
return a.count < b.count
}
@eonil
eonil / HTTP.get.swift
Last active October 15, 2019 10:44
The most reliable and quick way to perform synchronous HTTP call with URLSession. See https://github.com/eonil/swift-sync-http for packaged library.
enum HTTP {
/// - Note:
/// This does not consider HTTP status into success/failure.
/// Returning result can be non 2xx status.
static func get(address:String, query: [URLQueryItem] = []) throws -> Data {
let u = URL(string: address)!
var reply = Data()
/// We need to make a session object.
/// This is key to make this work. This won't work with shared session.
@eonil
eonil / slice-hash.swift
Last active September 16, 2019 01:03
Swift slices computes hashes based on their contents.
do {
let a = "ABCABC"
let i = a.index(a.startIndex, offsetBy: 3)
let b = a[a.startIndex..<i]
let c = a[i...]
var s = Set<Substring>()
s.insert(b)
s.insert(c)
print(b.hashValue)