Skip to content

Instantly share code, notes, and snippets.

View scraplesh's full-sized avatar
🕶️
RnD

Artem Tomilov scraplesh

🕶️
RnD
View GitHub Profile
class UdpActivity : AppCompatActivity(), NavigineNotification.Listener {
private lateinit var binding: ActivityMtsliveBinding
private var subLoc: SubLocation? = null
private val locationId = 98872
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMtsliveBinding.inflate(layoutInflater)
.apply { setContentView(root) }
initNavigine()
@scraplesh
scraplesh / SwitchMap.kt
Created September 2, 2021 16:08 — forked from sockeqwe/SwitchMap.kt
switchMap operator for Kotlin's Flow type.
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.Job
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
/**
@scraplesh
scraplesh / FooBarFragment.kt
Created November 11, 2020 15:51
Fragment arguments delegate
class FooBarFragment : Fragment() {
companion object {
fun newInstance(foo: String, bar: String?) = FooBarFragment().apply {
this.foo = foo
this.bar = bar
}
}
private var foo: String by argumentNotNull()
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import io.reactivex.functions.Consumer
class SharedEventBus : SharedEventOwner, Consumer<SharedEvent> {
private val sharedEvents = mutableMapOf<EventId, SharedEvent>()
private val sharedEventListeners = mutableMapOf<EventId, LifecycleAwareSharedEventListener>()
override fun accept(t: SharedEvent?) {
@scraplesh
scraplesh / MainActivity.java
Created August 1, 2019 23:00 — forked from Ahmed-Abdelmeged/MainActivity.java
Rounded Layout with specific corners rounded
package com.abdelmeged.ahmed.roundedlayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
public class MainActivity extends AppCompatActivity {
@scraplesh
scraplesh / NonNullAssertionDetector.kt
Created March 31, 2019 19:18 — forked from davidvavra/NonNullAssertionDetector.kt
Lint check for detecting non-null assertion (!!) in your code
import com.android.tools.lint.client.api.UElementHandler
import com.android.tools.lint.detector.api.*
import org.jetbrains.uast.UElement
import org.jetbrains.uast.UPostfixExpression
class NonNullAssertionDetector : Detector(), Detector.UastScanner {
override fun getApplicableUastTypes(): List<Class<out UElement>>? {
return listOf(UPostfixExpression::class.java)
}
@scraplesh
scraplesh / Sportsman.json
Last active March 25, 2019 14:55
Sportsman.json
{
"data": {
"attributes": {
"alias": "nikitin2",
"bio": null,
"birthdate": "09-22-1996",
"displayName": "nikitin",
"email": null,
"fullName": "nikitin",
"gender": "male",
@scraplesh
scraplesh / MVICore.swift
Last active July 3, 2023 17:27
Core functionality of MVICore library
import RxSwift
public typealias Bootstrapper<Action> = () -> Observable<Action>
public typealias WishToAction<Wish, Action> = (Wish) -> Action
public typealias Actor<State, Action, Effect> = (State, Action) -> Observable<Effect>
public typealias Reducer<State, Effect> = (State, Effect) -> State
public typealias PostProcessor<Action, Effect, State> = (Action, Effect, State) -> Action?
public typealias NewsPublisher<Action, Effect, State, News> = (Action, Effect, State) -> News?
open class Feature<Wish, Action, Effect, State, News> {
@scraplesh
scraplesh / Initializer.swift
Last active March 13, 2019 05:36
A better syntax for configurable initializations.
protocol InitConfigurable {
init()
}
extension InitConfigurable {
init(configure: (Self) -> Void) {
self.init()
configure(self)
}
}
@scraplesh
scraplesh / AccessTokenAuthenticator.kt
Created December 17, 2018 21:13 — forked from naturalwarren/AccessTokenAuthenticator.kt
An OkHttp Authenticator that performs token refreshes.
/**
* Authenticator that attempts to refresh the client's access token.
* In the event that a refresh fails and a new token can't be issued an error
* is delivered to the caller. This authenticator blocks all requests while a token
* refresh is being performed. In-flight requests that fail with a 401 are
* automatically retried.
*/
class AccessTokenAuthenticator(
private val tokenProvider: AccessTokenProvider
) : Authenticator {