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 / mjpg_streamer.sh
Last active April 1, 2023 17:19
raspberry pi mjpg_streamer startup script
#!/bin/sh
# /etc/init.d/mjpg_streamer.sh
# v0.2 phillips321.co.uk
### BEGIN INIT INFO
# Provides: mjpg_streamer.sh
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: mjpg_streamer for webcam
@fishkingsin
fishkingsin / build.sh
Created July 25, 2016 08:05
script to build ffmpeg and x264 for android
#!/bin/bash
#
# Author: Renato L. F. Cunha <renatoc@gmail.com>
# This file is available according to the MIT license. Please refer to the
# LICENSE file for details.
#
# This script builds a version of FFmpeg with h.264 support enabled by means of
# the libx264 library.
#
@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) }