Skip to content

Instantly share code, notes, and snippets.

View hoc081098's full-sized avatar
✝️
Glory to God

Petrus Nguyễn Thái Học hoc081098

✝️
Glory to God
View GitHub Profile
@file:Suppress("RedundantSuspendModifier")
import arrow.core.Either
import arrow.core.computations.either
import arrow.fx.coroutines.parTraverseEitherN
import kotlinx.coroutines.delay
import java.io.IOException
import kotlin.time.ExperimentalTime
import kotlin.time.TimeSource
extension Result {
public func `catch`(_ handler: () throws -> Success) -> Result<Success, Error> {
flatMapError { _ in
.init { try handler() }
}
}
public func `catch`(_ handler: (Failure) throws -> Success) -> Result<Success, Error> {
flatMapError { error in
.init { try handler(error) }
@schultek
schultek / nested_will_pop_scope.dart
Last active March 26, 2024 15:24
An improved WillPopScope widget to allow for nested navigators. See https://github.com/flutter/flutter/issues/47088
import 'package:flutter/material.dart';
class NestedWillPopScope extends StatefulWidget {
const NestedWillPopScope({
Key? key,
required this.child,
required this.onWillPop,
}) : super(key: key);
final Widget child;
@truizlop
truizlop / Wave.swift
Created September 10, 2020 14:41
Wave animation using SwiftUI
import SwiftUI
let LINE_LENGTH: Double = 500.0
let N = 720
let LINES = 18
let WAVES: Double = 18.0
let WAVE_HEIGHT: Double = 20
let SPACING: Double = 27.0
let CURL_AMOUNT: Double = 12.0
@manuelvicnt
manuelvicnt / AnAndroidApp.kt
Last active January 1, 2023 17:05
Hilt and AssistedInject working together in Hilt v2.28-alpha times - ViewModel version
// IMPORTANT! READ THIS FIRST
// Assisted Injection doesn't work with @HiltViewModel or @ViewModelInject
// Read more about the issue here: https://github.com/google/dagger/issues/2287
//
//
// AssistedInject and Hilt working together in v2.28-alpha times
// Example of a ViewModel using AssistedInject injected in a Fragment by Hilt
// As AssistedInject isn't part of Dagger yet, we cannot use in
// conjuction with @ViewModelInject
@varunon9
varunon9 / AlwaysRunningAndroidService.md
Last active April 20, 2024 23:38
How to create an always running service in Android

Full Source Code: https://github.com/varunon9/DynamicWallpaper/tree/always_running_service

Steps-

  1. Create a Foreground Service (MyService.java)
  2. Create a Manifest registered Broadcast Receiver (MyReceiver.java) which will start your Foreground Service
  3. In onDestroy lifecycle of MyService, send a broadcast intent to MyReceiver
  4. Launch the MyService on app start from MainActivity (see step 8)
  5. With above 4 steps, MyService will always get re-started when killed as long as onDestroy of Service gets called
  6. onDestroy method of Service is not always guaranteed to be called and hence it might not get started again
import UIKit
import PlaygroundSupport
protocol Weakifiable: AnyObject { }
extension NSObject: Weakifiable { }
extension Weakifiable {
func weakify(_ block: @escaping (Self) -> Void) -> () -> Void {
{ [weak self] in self.map(block) }
@PhBastiani
PhBastiani / # ArrowFreePrograms.md
Last active February 5, 2024 02:59
[Arrow-kt] For-Comprehension Free Monads in Kotlin

For-Comprehension Free Monads in Kotlin - Mini Howto

Copyright © 2020, Philippe Bastiani.
License: CC BY-NC-SA 4.0 with this restriction: this GIST could be, all or part, updated, copied, diffused for documentary purposes in the Λrrow project.

This GIST is an attempt to describe a repeatable, and automatable, process for building an embedded Domain Specific Language (DSL) with the help of a Free monad.
As material, i'll use Λrrow, the functional companion to Kotlin's Standard Library.

Disclaimer: This GIST assumes that you are roughly familiar with the concept of Free monad.

@micimize
micimize / tab_navigating_scaffold.dart
Last active April 3, 2024 19:52
Approach for tab-local navigators in flutter. Generalized from https://stackoverflow.com/a/57627826/2234013
import 'package:flutter/material.dart';
class AppScaffold extends StatefulWidget {
final List<WidgetBuilder> pages;
final List<BottomNavigationBarItem> navItems;
const AppScaffold({
Key key,
@required this.pages,
@required this.navItems,
@fteychene
fteychene / build.gradle.kts
Last active July 29, 2020 06:42
Hexagonal architecture as polymorphic monad stack in Kotlin with Arrow
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.3.21"
kotlin("kapt") version "1.3.21"
}
repositories {
mavenCentral()
}