Skip to content

Instantly share code, notes, and snippets.

View fishkingsin's full-sized avatar
✈️

James Kong fishkingsin

✈️
View GitHub Profile
package com.example.delayemitter
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test
import java.lang.Thread.sleep
import java.util.*
@fishkingsin
fishkingsin / TaskGroupPlayground.swift
Created November 30, 2022 07:35
testing withUnsafeThrowingContinuation
import UIKit
func printMessage() async {
let max: UInt32 = 4
let min: UInt32 = 0
let myRange: Range = min..<max
let string = await withTaskGroup(of: String.self) { group -> String in
group.addTask {
sleep(UInt32.random(in: myRange))
return "Hello"
@fishkingsin
fishkingsin / PageControl.swift
Last active October 14, 2022 17:26
SwiftUI Pager Demo
struct PageControl: View {
@Binding var selectedPage: Int
var pages: Int
var circleDiameter: CGFloat
var circleMargin: CGFloat
var body: some View {
@fishkingsin
fishkingsin / CardView.swift
Created September 2, 2022 15:38
SwiftUI + ViewModel + Redux
import SwiftUI
// Move me to MDL
struct CardView: View {
let record: Record
var body: some View {
VStack(alignment: .leading) {
@fishkingsin
fishkingsin / USDFRenewalPopupViewModelTests.swift
Created July 27, 2022 05:30
USDFRenewalPopupViewModelTests.swift
//
// USDFRenewalPopupViewModelTests.swift
// ChiefTests
//
// Created by on_luk on 26/7/2022.
//
import XCTest
import Combine
@testable import ChiefMT
@fishkingsin
fishkingsin / pad.dart
Last active November 10, 2021 13:49
sample
import 'dart:collection';
void main() {
// Q1
bool ret = fx(2, 20, 200, 301);
print(" ${ ret ? "meet" : "not meet" }");
ret = fx(2, 20, 4, 400);
print(" ${ ret ? "meet" : "not meet" }");
print("O(?) step $step");
@fishkingsin
fishkingsin / TwoStreamSolution.swift
Created August 7, 2021 15:52
Two Stream Solution
import RxSwift
import RxCocoa
//func ignoreNil<A>(x: A?) -> Observable<A> {
// return x.map { Observable.just($0) } ?? Observable.empty()
//}
func ignoreNil<A>(x: A?) -> Driver<A> {
return x.map { Driver.just($0) } ?? Driver.empty()
import RxSwift
import RxCocoa
func ignoreNil<A>(x: A?) -> Observable<A> {
return x.map { Observable.just($0) } ?? Observable.empty()
}
// If there are values return from stream A, B and C then I emit an event on stream X (boolean)
func allEmitedValue<A, B, C>(_ a: Observable<A?>, _ b: Observable<B?>, _ c: Observable<C?>) -> Observable<Bool> {
Observable.combineLatest(a, b, c) { allContainValue($0, $1, $2) }
@fishkingsin
fishkingsin / ChildProblem.swift
Last active August 7, 2021 08:52
ChildProblem
import RxSwift
import RxCocoa
//func ignoreNil<A>(x: A?) -> Observable<A> {
// return x.map { Observable.just($0) } ?? Observable.empty()
//}
func ignoreNil<A>(x: A?) -> Driver<A> {
return x.map { Driver.just($0) } ?? Driver.empty()
}
@fishkingsin
fishkingsin / TwoStream.swift
Created August 7, 2021 06:19
Two Rx Steam
import RxSwift
import RxCocoa
func ignoreNil<A>(x: A?) -> Observable<A> {
return x.map { Observable.just($0) } ?? Observable.empty()
}
var stream: BehaviorRelay<String?> = BehaviorRelay(value: nil)