Skip to content

Instantly share code, notes, and snippets.

View TuenTuenna's full-sized avatar
😍
Happy coding 👏

개발하는 정대리 TuenTuenna

😍
Happy coding 👏
View GitHub Profile
@ollieatkinson
ollieatkinson / Publishers+RetryDelay.swift
Last active November 5, 2022 18:39
Add a delay in-between each Combine retry, offering a timing function and default implementations for none, constant seconds and exponential backoff
import Combine
import Foundation
extension Publisher {
public func retry<S: Scheduler>(
_ max: Int = Int.max,
delay: Publishers.RetryDelay<Self, S>.TimingFunction,
scheduler: S
) -> Publishers.RetryDelay<Self, S> {
/*
Here's our goal:
let localDataStore = UserDataStore()
let remoteDataStore = UserApi()
let dataStore = CacheBackedDataStore(localDataStore, remoteDataStore)
dataStore.fetch(userID) { result in
// handle result
}
import Combine
struct ZipMany<Element, Failure>: Publisher where Failure: Error {
typealias Output = [Element]
private let underlying: AnyPublisher<Output, Failure>
init<T: Publisher>(publishers: [T]) where T.Output == Element, T.Failure == Failure {
let zipped: AnyPublisher<[T.Output], T.Failure>? = publishers.reduce(nil) { result, publisher in
if let result = result {
@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
@rommansabbir
rommansabbir / UsagesOfSealedClass.kt
Created December 9, 2020 18:37
How to use Kotlin's Sealed Class in Android Development for better & clean code
sealed class AppFailure {
/**
* Global Failure classes
* These failures will be used across all over the app including Data Layer, Domain Layer, Framework Layer
*/
class GeneralFailure(var message: String, var errorCode: Int? = null) : AppFailure()
class UnauthorizedFailure(var message: String = "Unauthorized", errorCode: Int? = null) : AppFailure()
class LoginFailure(var message: String = "Unable to login", errorCode: Int? = null) : AppFailure()
class ServerFailure(var message: String = "Unable to connect to the server side", errorCode: Int? = null) : AppFailure()
class NoInternetFailure(var message: String = "Device is not connected to the internet", errorCode: Int? = null) : AppFailure()
// https://sarunw.com/posts/swiftui-circular-progress-bar/
//
// CircularProgressView.swift
// SwiftUI30WWDC2021
//
// Created by Mateo on 5/6/22.
//
@stevenojo
stevenojo / ObjectiveCDebounce.md
Last active May 6, 2023 23:56
Objective-C Debounce Example Using GCD Dispatch Sources / Timer

##Debouncing using GCD on iOS

The idea of "Debouncing" is to limit the rate a function or task can execute by waiting a certain amount of time before executing it. In the example below, if a user rapidly enters input, it will only execute once, 1 second after all that input. This is the implementation of a sample class showing how to do so, while using Grand Central Dispatch to create a timer. The timer fires on a global queue in this example - but you can change the queue to any queue where you want the timer to execute, regardless of where you set it up.

#import <Foundation/Foundation.h>

@interface DebounceExample : NSObject
@nolanw
nolanw / URLRequest+FormURLEncoded.swift
Last active May 11, 2023 20:38
Swift x-www-form-urlencoded
// Public domain - https://gist.github.com/nolanw/14b277903a2ba446f75202a6bfd55977
import Foundation
extension URLRequest {
/**
Configures the URL request for `application/x-www-form-urlencoded` data. The request's `httpBody` is set, and values are set for HTTP header fields `Content-Type` and `Content-Length`.
- Parameter queryItems: The (name, value) pairs to encode and set as the request's body.
@WrathChaos
WrathChaos / UriToBitmap.md
Last active July 6, 2023 19:29
Android: How to convert Bitmap to Uri?
fun getImageUriFromBitmap(context: Context, bitmap: Bitmap): Uri{
    val bytes = ByteArrayOutputStream()
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes)
    val path = MediaStore.Images.Media.insertImage(context.contentResolver, bitmap, "Title", null)
    return Uri.parse(path.toString())
 }
@piruin
piruin / BitmapFromMediaUri.java
Created October 2, 2015 17:21
How to get bitmap from URI
InputStream is = getContentResolver().openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(is);
is.close();