Skip to content

Instantly share code, notes, and snippets.

this += repository.getImages(params)
.compose(applySingleAsync())
.subscribe { result ->
result.fold(
onSuccess = { },
onFailure = { }
)
}
internal class ImagesRepositoryImpl(private val source: ImageDataSource) : ImagesRepository {
override fun getImages(params: Map<String, String>): Single<Result<ImagesResponse>> {
return source.getImages(params)
.map { Result.success(it) }
.compose(applyRetryPolicy(TIMEOUT, maxRetries = 5, interval = 2, unit = TimeUnit.SECONDS) { Single.just(Result.failure(it)) })
}
}
internal typealias RETRY_PREDICATE = (Throwable) -> Boolean
internal const val MAX_RETRIES = 3L
internal const val DEFAULT_INTERVAL = 1L
internal val TIMEOUT: RETRY_PREDICATE = { it is SocketTimeoutException }
internal val NETWORK: RETRY_PREDICATE = { it is IOException }
internal val SERVICE_UNAVAILABLE: RETRY_PREDICATE = { it is HttpException && it.code() == 503 }
internal fun <T> applyRetryPolicy(
@munho
munho / customPainter.dart
Created December 16, 2021 06:27 — forked from OPY-bbt/customPainter.dart
draw network image in CustomPainter and save content to file
import 'dart:io';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:path_provider/path_provider.dart';
void main() => runApp(MyApp());
String FILENAME = 'timg.jpeg';
@munho
munho / 101-rx-samples.md
Created December 9, 2021 03:21 — forked from minhhungit/101-rx-samples.md
101 Rx Samples in C#

101 Rx Samples in C#

This was taken from http://rxwiki.wikidot.com/101samples, because I wanted to be able to read it more comfortable with syntax highlighting.

Here's the unedited original, translated to Github Markdown glory:

101 Rx Samples - a work in progress

@munho
munho / KeyboardAccessoryView.swift
Created June 8, 2021 08:55 — forked from Winchariot/KeyboardAccessoryView.swift
UIToolbar with a right-aligned "Done" button, for use as a keyboard accessory view
lazy var accessoryToolbarWithDoneButton: UIToolbar = {
let toolbar = UIToolbar(frame: CGRect.zero)
//only needs to be flexible in the dimension(s) you want it to be
//https://stackoverflow.com/questions/31822504/how-can-i-increase-the-height-of-an-inputaccessoryview
toolbar.autoresizingMask = [.flexibleWidth, .flexibleHeight]
let leftSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(keyboardDoneButtonTapped(_:)))
toolbar.items = [leftSpace, doneButton]
@munho
munho / makeImage.sh
Created March 2, 2021 00:56 — forked from bitboxer/makeImage.sh
create a sparsebundle for mac os backups
#!/bin/bash
# A bash script to create a time machine disk image suitable for
# backups with OS X 10.6 (Snow Leopard)
# This script probably only works for me, so try it at your own peril!
# Use, distribute, and modify as you see fit but leave this header intact.
# (R) sunkid - September 5, 2009
#
# This will create a time machine ready disk image named with your
# computer's name with a maximum size of 600GB and copy it to
# /Volumes/backup. The image "file" (it's a directory, really) will
@munho
munho / default
Last active February 23, 2021 06:27 — forked from dtomasi/default
Brew Nginx PHP7
server {
listen 80;
server_name localhost;
root /Users/YOUR_USERNAME/Sites;
access_log /usr/local/var/log/nginx/default.access.log main;
location / {
include /usr/local/etc/nginx/conf.d/php-fpm;
}
apply plugin: 'kotlin-kapt'
// ...(중략)...
dependencies {
// for async logic
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
// Room
implementation "androidx.room:room-runtime:2.2.2"
@munho
munho / UIViewController+Rotation.m
Created January 11, 2021 01:57 — forked from macguru/UIViewController+Rotation.m
Forcing a rotation on a UIViewController.
//
// UIViewController+Rotation.m
// Ulysses
//
// Created by Götz Fabian on 12.10.17.
// Copyright © 2017 Ulysses GmbH & Co. KG. All rights reserved.
//
#import "UIViewController+Rotation.h"