Skip to content

Instantly share code, notes, and snippets.

View iamchiwon's full-sized avatar
💭
I'm awake

Song Chiwon iamchiwon

💭
I'm awake
View GitHub Profile
@iamchiwon
iamchiwon / ImageDownloadExample+Combine.swift
Last active June 27, 2019 15:55
RxToCombine: Image Download Example
//
// ViewController.swift
// RxToCombine
//
// Copyright © 2019 iamchiwon. All rights reserved.
//
import Combine
import RxSwift
import UIKit
@iamchiwon
iamchiwon / retryInterval.kt
Last active February 25, 2019 11:25
RxJava retry interval with condition
fun <T> Observable<T>.retryInterval(intervals: List<Long>, filter: (Throwable) -> Boolean): Observable<T> {
return this.retryWhen { throwable ->
throwable
.flatMap { e ->
if (!filter(e)) return@flatMap Observable.error<Throwable>(e)
return@flatMap Observable.just(e)
}
.zipWith(Observable.fromIterable(intervals)) { _, i -> i }
.flatMap { Observable.timer(it, TimeUnit.MILLISECONDS, Schedulers.newThread()) }
}
@iamchiwon
iamchiwon / retryInterval.swift
Last active May 24, 2020 13:38
RxSwift retry interval with condition
extension ObservableType {
public func retryInterval(_ intervals: [RxTimeInterval], when f: @escaping (Error) -> Bool) -> Observable<Self.Element> {
return retryWhen { error -> Observable<Int> in
error.flatMap { e -> Observable<Void> in
guard f(e) else { return .error(e) }
return .just(())
}
.zip(with: Observable<RxTimeInterval>.from(intervals)) { $1 }
.flatMap { Observable<Int>.timer($0, scheduler: Schedulers.background) }
}
@iamchiwon
iamchiwon / RxViewController.swift
Created January 26, 2019 04:21
methodInvoked Example
import RxCocoa
import RxSwift
public extension Reactive where Base: UIViewController {
public var viewDidLoad: ControlEvent<Void> {
let source = self.methodInvoked(#selector(Base.viewDidLoad)).map { _ in }
return ControlEvent(events: source)
}
public var viewWillAppear: ControlEvent<Bool> {
@iamchiwon
iamchiwon / UIPickerController+Rx.swift
Last active November 30, 2022 10:46
DelegateProxy example
// MARK:- UIImagePickerController.rx
import UIKit
import RxSwift
import RxCocoa
// picker.rx.didFinishPickingMediaWithInfo
// ~~~~~~ ~~
// Base Reactive
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>FILEHEADER</key>
<string>
// ========================================
//
// Lorem Ipsum is simply dummy text of the
// printing and typesetting industry.
@iamchiwon
iamchiwon / run_command.sh
Last active October 11, 2018 15:22
Xcode behavior 용: 쉘명령어 실행하기
#!/bin/bash
# move project dir
PROJECT_HOME=`pwd`
echo "cd $PROJECT_HOME" > /tmp/tmp.sh
# input command via dialog
read -r -d '' applescriptCode <<'EOF'
set commands to text returned of (display dialog "Shall Command" default answer "")
return commands
@iamchiwon
iamchiwon / open_terminal.sh
Created October 8, 2018 11:42
Xcode behavior 용: 터미널 열기
#!/bin/bash
open -a Terminal `pwd`
@iamchiwon
iamchiwon / pod_update.sh
Last active February 2, 2023 05:51
Xcode behavior 용: pod 업데이트 하기
#!/bin/bash
# move project dir
PROJECT_HOME=`pwd`
echo "cd $PROJECT_HOME" > /tmp/tmp.sh
# pod init & update
echo "pod update" >> /tmp/tmp.sh
chmod +x /tmp/tmp.sh
@iamchiwon
iamchiwon / pod_init.sh
Last active February 2, 2023 05:51
Xcode behavior 용: pod init 하기
#!/bin/bash
# move project dir
PROJECT_HOME=`pwd`
echo "cd $PROJECT_HOME" > /tmp/tmp.sh
# search .xcodeproj file and strip filename
PROJECT_NAME=""
for f in *.xcodeproj; do
PROJECT_NAME="${f%.*}"