Skip to content

Instantly share code, notes, and snippets.

View Sajjon's full-sized avatar
🦀
Rust, Swift, Zig | SDK, Embedded, Mobile | Crypto, Fintech, Space

Alexander Cyon Sajjon

🦀
Rust, Swift, Zig | SDK, Embedded, Mobile | Crypto, Fintech, Space
View GitHub Profile
@Sajjon
Sajjon / WordLengthLine.swift
Created August 15, 2020 14:37
A line which word has suitable length
/// A line which word has suitable length
struct WordLengthLine: LineFromCorpusFromLine, Hashable {
typealias FromLine = ParsedLine
let line: FromLine
}
@Sajjon
Sajjon / ParsedLine.swift
Created August 15, 2020 13:47
A parsed line from the Swedish corpus at Språkbanken.
/// A parsed line from some scanned line in the corpus.
struct ParsedLine: Codable, Hashable {
let wordForm: WordForm
let partOfSpeechTag: PartOfSpeech
let lemgrams: Lemgrams
let isCompoundWord: Bool
let numberOfOccurencesInCorpus: Int
let relativeFrequencyPerOneMillion: Int
@Sajjon
Sajjon / analyze_pos_tags.py
Created August 14, 2020 13:26
POS Tag analysis of BIP39 list
import nltk
from collections import defaultdict
class POSInfo(object):
def __init__(self, pos, word):
self.pos = pos
self.count = 1
self.words = [word]
self.percentage = 0.0
@Sajjon
Sajjon / LetterToApple.txt
Created April 19, 2020 20:15
Request to Apple to create real world navigation tutorial for SwiftUI
I've been developing iOS apps for 7 years now, Swift development since 2014 and SwiftUI since last summer. The biggest challenge for any iOS developer is navigation. But at least with UIKit we had control over the navigation stack, using UINavigationController. We could implement the "Coordinator pattern" and have somewhat control. This allows for implementation of animatable replacable modal flows. Which almost every app on earth needs/uses - at least those with logins (which most have?).
Imagine this super common scenario:
Start: goto Onboarding-flow if not signed-in; else goto Main-flow.
Onboarding-flow: goto TermsOfService-flow if not acceptedToS; else (goto Tutorial-flow if not seenTutorial; else goto SignInOrSignUp)
TermsOfService-flow: // display view with link to terms & conditions and link to privacy policy. Both will open modal webview content, need to check both Toggle views, should persist this data. Goto Tutorial-flow when done
Tutorial-flow: // display multiple views steppable between
SignInOr
@Sajjon
Sajjon / Combine.Publisher.firstN.swift
Last active October 31, 2019 18:00
A Combine equivalence of RxSwift `take(_ n: Int)`
public extension Publisher where Failure == Never {
/// Publishes the first `n` elements of a stream, then finishes.
func first(_ numberOfElements: Int) -> AnyPublisher<Output, Failure> {
collect(numberOfElements) // "Buffer"
.first() // "release and complete (finish)"
// Publisher<[Output]> -> Publisher<Output>
.map { $0.publisher }.switchToLatest()
.eraseToAnyPublisher()
}
@Sajjon
Sajjon / AddressShardTest.swift
Created October 21, 2019 14:09
Mocking of 'Shard' of 'Address' in RadixDLT Swift library using awesome 'StubKit'
import Foundation
@testable import RadixSDK
import XCTest
import StubKit
extension Address: Stubbable {
public static func stub() -> Address {
"JF5FTU5wdsKNp4qcuFJ1aD9enPQMocJLCqvHE2ZPDjUNag8MKun"
}
}
@Sajjon
Sajjon / AutoEquatable.swift
Last active October 11, 2019 15:57
Auto Synthesizer for Equatable
// MARK: - Compare + Mirror
private func compareSome<T>(lhs: T, rhs: T, beSatisfiedWithSameAssociatedTypeIfTheirValuesDiffer: Bool) -> Bool {
compareAny(lhs: lhs, rhs: rhs, beSatisfiedWithSameAssociatedTypeIfTheirValuesDiffer: beSatisfiedWithSameAssociatedTypeIfTheirValuesDiffer)
}
private func compareAny(lhs: Any, rhs: Any, beSatisfiedWithSameAssociatedTypeIfTheirValuesDiffer: Bool = true) -> Bool {
let lMirror = Mirror(reflecting: lhs)
let rMirror = Mirror(reflecting: rhs)
@Sajjon
Sajjon / TransactionTestOldFormat.swift
Created August 14, 2019 12:55
Swift Unit test self contained functions
import Foundation
import XCTest
@testable import RadixSDK
class TransactionTestOldFormat: XCTestCase {
func testTransactionWithSingleCreateTokenActionWithInitialSupply() {
// GIVEN identity alice and a RadixApplicationClient
let app = RadixApplicationClient.localhostAliceSingleNodeApp
@Sajjon
Sajjon / TransactionTestNewFormat.swift
Created August 14, 2019 12:54
Swift Unit test nested closures
import Foundation
import XCTest
@testable import RadixSDK
class TransactionTestNewFormat: XCTestCase {
func test_transaction_with_single_create_token_action_with_initial_supply() {
given_identity_alice_and_a_radix_application_client { (aliceApp) in
when_alice_observes_her_transactions_after_creating_token(withSupply: .mutable(initial: 123), given: aliceApp) { transaction in
@Sajjon
Sajjon / ChangeAccountChangeUniverse.swift
Last active June 14, 2019 13:48
ChangeAccount ChangeUniverse
public enum NodeFinding {
case anySuitableNode(discovery: NodesDiscovery)
case connectToSpecific(urlToNodes: [URL], ifAllSpecifiedNodesAreUnsuitable: StrategyWhenSpecifiedNodesAreUnsuitable)
}
public extension NodeFinding {
struct StrategyWhenSpecifiedNodesAreUnsuitable {
let strategyWhenSpecifiedNodesAreOffline: StrategyWhenSpecifiedNodesAreOffline
let strategyWhenSpecifiedNodesDontServeShard: StrategyWhenSpecifiedNodesDontServeShard