Skip to content

Instantly share code, notes, and snippets.

View jimmyFlash's full-sized avatar
:atom:

Jamal jimmyFlash

:atom:
View GitHub Profile
@utkan
utkan / MusicNameType.java
Last active August 14, 2018 11:49
Typedef Annotations example
@StringDef({
POP,
ROCK,
JAZZ
})
@Retention(RetentionPolicy.SOURCE)
public @interface MusicNameType {}
private const val MIRROR = 180F
private const val INITIAL_DELAY = 0.15F
private val translucentBlack = Color.argb(50, 0, 0, 0)
fun speedDial(
anchor: View,
@ColorInt tint: Int = anchor.context.themeColorAt(R.attr.colorPrimary),
@StyleRes animationStyle: Int = android.R.style.Animation_Dialog,
layoutAnimationController: LayoutAnimationController = LayoutAnimationController(speedDialAnimation, INITIAL_DELAY).apply { order = ORDER_NORMAL },
@sconstantinides
sconstantinides / App.js
Created May 1, 2018 23:37
Sample Firebase task app
import React, { Component } from 'react';
import firebase from '@firebase/app';
import firestore from './firestore'; // Code: https://gist.github.com/sconstantinides/546a48ba183b1234f750ca6261440199
class App extends Component {
constructor(props) {
super(props);
this.state = {
userId: localStorage.getItem('userId') || '',
inline fun getValueAnimator(forward: Boolean = true, duration: Long, interpolator: TimeInterpolator,
crossinline updateListener: (progress: Float) -> Unit
): ValueAnimator {
val a =
if (forward) ValueAnimator.ofFloat(0f, 1f)
else ValueAnimator.ofFloat(1f, 0f)
a.addUpdateListener { updateListener(it.animatedValue as Float) }
a.duration = duration
a.interpolator = interpolator
return a
class ToolbarBehavior : CoordinatorLayout.Behavior<AppBarLayout>() {
/** Consume if vertical scroll because we don't care about other scrolls */
override fun onStartNestedScroll(coordinatorLayout: CoordinatorLayout, child: AppBarLayout,
directTargetChild: View, target: View, axes: Int, type: Int): Boolean {
getViews(child)
return axes == ViewCompat.SCROLL_AXIS_VERTICAL ||
super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, axes, type)
}
@Suppress("UNCHECKED_CAST")
class ViewModelFactory @Inject constructor(
private val creators: Map<Class<out ViewModel>, Provider<ViewModel>>
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
val creator = creators[modelClass]
?: creators.asIterable().find { (key, _) -> modelClass.isAssignableFrom(key) }?.value
?: throw IllegalArgumentException("Unknown ViewModel class $modelClass")
class OurViewModel(observeGithubReposUseCase: ObserveGithubReposUseCase): ViewModel {
val githubRepos: LiveData<List<GithubRepoItem>>
get() = observeGithubReposUseCase
.observe()
.map { reposList ->
reposList
.sortedByDescending { it.stars }
.map {
// domain
sealed class ErrorEntity {
sealed class ApiError: ErrorEntity() {
// .....
}
sealed class FileError: ErrorEntity() {
object NotFound: FileError()
class LogInModelTest : LogInListener {
private lateinit var successTask: Task<AuthResult>
private lateinit var failureTask: Task<AuthResult>
@Mock
private lateinit val mAuth: FirebaseAuth
private lateinit var logInModel: LogInModel
private var logInResult = UNDEF
@catalinsgh
catalinsgh / PasswordValidatorTest.kt
Created June 30, 2020 18:40
PasswordValidatorTest using dynamic tests
internal class PasswordValidatorTest {
private val validator = PasswordValidator()
@TestFactory
fun `given input password, when validating it, then is should return if it is valid`() =
listOf(
"Test123!" to true,
"#tesT12!" to true,
"12Es@t123" to true,