Skip to content

Instantly share code, notes, and snippets.

View Nimrodda's full-sized avatar

Nimrod Dayan Nimrodda

View GitHub Profile
@Nimrodda
Nimrodda / KodeinDI-environmentScope.kt
Created December 21, 2020 11:54 — forked from SalomonBrys/KodeinDI-environmentScope.kt
Example that shows how to create a scope registry according to a server environment.
import org.kodein.di.*
import org.kodein.di.bindings.Scope
import org.kodein.di.bindings.ScopeRegistry
import org.kodein.di.bindings.StandardScopeRegistry
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicReference
enum class Environment(val baseUrl: String) {
DEBUG("http://localhost"),
PROD("https://api.awesome-service.com")
@Nimrodda
Nimrodda / security.kt
Last active November 17, 2020 09:53
App signing verification
object SecurityManager {
fun isPackageNameAllowed(
context: Context,
packageName: String,
allowedApps: Map<String, String>
): Boolean {
return if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
isPackageNameAllowedApi27Down(context, packageName, allowedApps)
} else {
isPackageNameAllowedApi28Up(context, packageName, allowedApps)
@Nimrodda
Nimrodda / Play core in-app updates.txt
Created September 28, 2020 12:38
Google Play Internal App Sharing
* To test in-app updates the app must be released at least once before to any track
* The application ID must match, but the signature doesn't since Play Store has its own signature for apps shared via Internal App Sharing links
* If the app has custom country availability, which happens to not include the country of the tester, a new track must be create
with a custom country availability that includes also the country of the tester. In case this is not followed, the tester will
see an error related to purchase not available in his country.
* When using test tracks, the testers Google account must be in the testers list and they must opt-in.
* Upload the test build to https://play.google.com/console/internal-app-sharing
* The tester must download and install the app at least once from the Internal App Sharing before testing in-app update
* Once the app is installed at least once, the tester should open the new link, but not install the update from there. Instead
he should navigate to the app and test the in-
@Nimrodda
Nimrodda / zshrc
Last active April 25, 2022 14:59
Zsh config for Android and Flutter
# Path to your oh-my-zsh installation.
export ZSH="$HOME/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"
@Nimrodda
Nimrodda / Redux.kt
Created June 11, 2020 20:05
Redux Kotlin draft
/*
* Copyright 2020 Nimrod Dayan nimroddayan.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
class WorkoutSummaryController : TypedEpoxyController<WorkoutSummaryViewState>(
EpoxyAsyncUtil.getAsyncBackgroundHandler(),
EpoxyAsyncUtil.getAsyncBackgroundHandler()) {
override fun buildModels(viewState: WorkoutSummaryViewState) {
addLikes(viewState)
addLoadingIndicatorIfNeed(viewState)
}
class WorkoutSummaryActivity : AppCompatActivity() {
private lateinit var binding: WorkoutSummaryActivityBinding
private val viewModel: WorkoutSummaryViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// We use View Binding here
binding = WorkoutSummaryActivityBinding.inflate(layoutInflater)
setContentView(binding.root)
class WorkoutSummaryViewModel : ViewModel() {
private val _viewState = MutableLiveData<WorkoutSummaryViewState>()
val viewState: LiveData<WorkoutSummaryViewState> = _viewState
// Conflated channel makes sure that we always keep only the last emitted item
// other channels have been omitted for brevity
private val likesItemChannel = ConflatedBroadcastChannel<ViewState<LikesItem>>()
fun loadData(workoutId: Int) {
viewModelScope.launch {
data class WorkoutSummaryViewState(
val workoutId: Int,
val coverImagesItem: ViewState<CoverImagesItem>,
val likesItem: ViewState<LikesItem>,
val commentsItem: ViewState<CommentsItem>,
val workoutSummaryItem: ViewState<WorkoutSummaryItem>
)
typealias OnClickHandler = (workoutId: Int) -> Unit
sealed class ViewState<T>(val data: T? = null) {
class Loading<T>(data: T? = null) : ViewState<T>(data)
class Error<T>(val throwable: Throwable, data: T? = null) : ViewState<T>(data)
class Loaded<T>(data: T? = null) : ViewState<T>(data)
fun isLoading(): Boolean = this is Loading
}