Skip to content

Instantly share code, notes, and snippets.

@cjgaliana
cjgaliana / RetryHelpers.kt
Created April 11, 2021 08:43
Retry Logic for Kotlin and Couroutines
package com.cjgaliana.utils
import kotlinx.coroutines.delay
import timber.log.Timber
suspend fun <T> retryWhen(
predicate: (cause: Exception, attempt: Int) -> Boolean,
delayInMilliseconds: Long = 0,
block: suspend () -> T
): T {
@cjgaliana
cjgaliana / ConcurrencyExtensions.kt
Last active April 27, 2021 08:51
Kotlin Await All Parallel
package com.cjgaliana.snippets
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.awaitAll
suspend fun <T> Collection<Deferred<T>>.awaitAll(parallelLimit: Int): List<T> {
if(this.isEmpty()) {
return emptyList()
}
@cjgaliana
cjgaliana / SecureStorage.cs
Created September 29, 2015 09:57
Secure Storage for Xamarin.iOS
using System;
using System.Threading.Tasks;
using Security;
using Foundation;
using System.Collections.Generic;
namespace SecureStorageTest
{
public class SecureStorage
{
// Licence: MIT X11
// Note: This is an Objective-C to C# translation by using code from: http://code.google.com/p/toast-notifications-ios/
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System;
using System.Drawing;
namespace Tabasco.iOS.Dialog
{
/// <summary>