Skip to content

Instantly share code, notes, and snippets.

Jorge Garrido FireZenk

Block or report user

Report or block FireZenk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pablisco
pablisco / Coroutine_scope_functions.kt
Last active Jul 11, 2019
Simple way to jump into a separate context
View Coroutine_scope_functions.kt
suspend fun <T, R> T.letOn(
context: CoroutineContext,
block: suspend CoroutineScope.(T) -> R
): R = withContext(context) { block(this@letOn) }
suspend fun <T> T.alsoOn(
context: CoroutineContext,
block: suspend CoroutineScope.(T) -> Unit
): T = also { withContext(context) { block(this@alsoOn) } }
@sergiocasero
sergiocasero / DaoGenerator.kt
Created Apr 25, 2019
DaoGenerator code template for IntelliJ/AS
View DaoGenerator.kt
package ${PACKAGE_NAME}
#parse("File Header.java")
import androidx.room.Dao
import androidx.room.Insert
import androidx.room.Update
import androidx.room.Query
@Dao
View DialogNavigator.kt
package com.geekorum.geekdroid.navigation
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import androidx.core.content.res.use
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
View ScopedViewModel.kt
open class ScopedViewModel : ViewModel() {
private val job = Job()
protected val scope: CoroutineScope = job + Dispatchers.Main
override fun onCleared() {
super.onCleared()
job.cancel()
}
}
View usecase.kt
/**
* (C) Copyright 2018 Paulo Vitor Sato Open Source Project
*
* 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
@sbelloz
sbelloz / ViewStubExt.java
Last active Nov 27, 2018
Deflate the lazy view previously inflated, and reinflate a new ViewStub
View ViewStubExt.java
public class ViewStubExt {
/**
* Deflates the view inflated by {@link ViewStub#inflate()}
* and replace it with a new {@link ViewStub} in its parent.
*
* @param view the view lazily inflated previously
* @return the new ViewStub with backed parameters
*
*/
@pablisco
pablisco / Logger.kt
Last active May 17, 2018
Fluent Logging with Kotlin
View Logger.kt
inline fun <A> A.logWith(logger: Logger, block: Logger.(A) -> Unit) : A =
this.also { logger.block(it) }
// With interface injection
interface HasLog {
val log: Logger
fun <A> A.log(block: Logger.(A) -> Unit) : A =
logWith(logger, block)
}
@sfeatherstone
sfeatherstone / ArrayCat.kt
Last active Jun 21, 2018
Exploring different ways to add/concatenate two arrays in Kotlin
View ArrayCat.kt
//Copy using arraycopy
fun catTwoIntArrays1(array1 :IntArray, array2 :IntArray) : IntArray {
val newArray = IntArray(array1.size + array2.size)
System.arraycopy(array1, 0, newArray, 0 , array1.size)
System.arraycopy(array2, 0, newArray, array1.size , array2.size)
return newArray
}
//Copy using for loops
fun catTwoIntArrays2(array1 :IntArray, array2 :IntArray) : IntArray {
@alorma
alorma / CalendarDsl.kt
Last active Feb 8, 2018
Kotlin calendar DSL
View CalendarDsl.kt
import java.util.*
@DslMarker
annotation class CalendarDsl
@CalendarDsl
class CalendarBuilder(val calendar: Calendar) {
fun dayOfMonth(function: () -> Int) = calendar.apply { set(Calendar.DAY_OF_MONTH, function()) }
fun dayOfMonth(value: Int) = calendar.apply { set(Calendar.DAY_OF_MONTH, value) }
@hrules6872
hrules6872 / Base64.kt
Last active Oct 6, 2019
Base64.kt for Kotlin
View Base64.kt
fun String.encodeBase64ToString(): String = String(this.toByteArray().encodeBase64())
fun String.encodeBase64ToByteArray(): ByteArray = this.toByteArray().encodeBase64()
fun ByteArray.encodeBase64ToString(): String = String(this.encodeBase64())
fun String.decodeBase64(): String = String(this.toByteArray().decodeBase64())
fun String.decodeBase64ToByteArray(): ByteArray = this.toByteArray().decodeBase64()
fun ByteArray.decodeBase64ToString(): String = String(this.decodeBase64())
fun ByteArray.encodeBase64(): ByteArray {
val table = (CharRange('A', 'Z') + CharRange('a', 'z') + CharRange('0', '9') + '+' + '/').toCharArray()
You can’t perform that action at this time.