Skip to content

Instantly share code, notes, and snippets.

View NikCapko's full-sized avatar
🏠
Working from home

Nikolay Capko NikCapko

🏠
Working from home
View GitHub Profile
// Api
interface CommandReceiver {
fun <R, T : Command<R>> processCommand(command: T) {
command.execute(this as R)
}
}
interface Command<R : CommandReceiver> {
fun execute(receiver: R)
@NikCapko
NikCapko / useCase template
Created September 15, 2023 19:46
UseCase Template
package ${PACKAGE_NAME};
import javax.inject.Inject
internal class ${NAME}UseCase @Inject constructor(
) {
operator fun invoke() {
}
@NikCapko
NikCapko / test file template
Last active September 15, 2023 19:45
Test File Tepmplate
@file:Suppress("NonAsciiCharacters")
package ${PACKAGE_NAME};
import org.junit.Test
/**
* Tests for [${NAME}]
*/
internal class ${NAME}Test {
@NikCapko
NikCapko / test method template
Created September 15, 2023 19:43
Test method live template
@Test
fun `$END$`() {
//given
// when
// then
}
@NikCapko
NikCapko / sort_mirrorlist.sh
Last active August 10, 2023 12:57
Sort mirrorlist by connection speed on Arch
sudo reflector --verbose -l 5 -p https --sort rate --save /etc/pacman.d/mirrorlist && sudo pacman -Syyu
@NikCapko
NikCapko / Test class for unit testing.kt
Last active August 1, 2023 16:28
Test class for unit testing
@RunWith(JUnit4::class)
class $TestClassName$Test {
@get:Rule
val mockitoRule: MockitoRule = MockitoJUnit.rule()
@Before
fun setUp() {
}
@NikCapko
NikCapko / Mock creation.kt
Last active August 1, 2023 16:29
Mock creation
@Mock
private var $variable$: $variableType$
@NikCapko
NikCapko / Single unit test.kt
Last active August 1, 2023 16:28
Single unit test
@Test
fun `$TestDescription$`() {
// ARRANGE
val sut: $TestModule$ = $TestModule$($Parameters$)
$END$
// ACTION
// CHECK
}
@NikCapko
NikCapko / ViewVisibilityExtensions.kt
Created March 21, 2023 21:09
Change view visibility
import android.view.View
fun View.gone() = run { visibility = View.GONE }
fun View.visible() = run { visibility = View.VISIBLE }
fun View.invisible() = run { visibility = View.INVISIBLE }
infix fun View.visibleIf(condition: Boolean) =
run { visibility = if (condition) View.VISIBLE else View.GONE }