Skip to content

Instantly share code, notes, and snippets.

View FireZenk's full-sized avatar
🌍
Improving the world

Jorge Garrido FireZenk

🌍
Improving the world
View GitHub Profile
@bgauduch
bgauduch / multiple-repository-and-identities-git-configuration.md
Last active April 25, 2024 00:57
Git config with multiple identities and multiple repositories

Setup multiple git identities & git user informations

/!\ Be very carrefull in your setup : any misconfiguration make all the git config to fail silently ! Go trought this guide step by step and it should be fine 😉

Setup multiple git ssh identities for git

  • Generate your SSH keys as per your git provider documentation.
  • Add each public SSH keys to your git providers acounts.
  • In your ~/.ssh/config, set each ssh key for each repository as in this exemple:
@chrisbanes
chrisbanes / ScopedViewModel.kt
Last active October 25, 2022 21:29
ScopedViewModel
open class ScopedViewModel : ViewModel() {
private val job = Job()
protected val scope: CoroutineScope = job + Dispatchers.Main
override fun onCleared() {
super.onCleared()
job.cancel()
}
}
/**
* (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
@paolop
paolop / LogExtensions.kt
Last active November 20, 2023 09:55
Android logging utilities.
import android.util.Log
import com.paolo
import kotlin.reflect.KClass
/* Convenient wrappers over Android Log.* static methods */
/** Wrapper over [Log.i] */
inline fun <reified T> T.logi(message: String, onlyInDebugMode: Boolean = true, enclosingClass: KClass<*>? = null) =
@sbelloz
sbelloz / ViewStubExt.java
Last active September 3, 2021 16:21
Deflate the lazy view previously inflated, and reinflate a new ViewStub
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 10:35
Fluent Logging with Kotlin
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 June 21, 2018 13:39
Exploring different ways to add/concatenate two arrays in Kotlin
//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 February 8, 2018 16:33
Kotlin calendar DSL
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 May 31, 2021 12:41
Base64.kt for Kotlin
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()
@sgdan
sgdan / gzip.kts
Last active April 4, 2024 06:02
Kotlin code to compress/uncompress a string with gzip
import java.io.ByteArrayOutputStream
import java.io.File
import java.nio.charset.StandardCharsets.UTF_8
import java.util.zip.GZIPInputStream
import java.util.zip.GZIPOutputStream
fun gzip(content: String): ByteArray {
val bos = ByteArrayOutputStream()
GZIPOutputStream(bos).bufferedWriter(UTF_8).use { it.write(content) }
return bos.toByteArray()