Skip to content

Instantly share code, notes, and snippets.

View Hasiy's full-sized avatar
🤒
something something

Hasiy Hasiy

🤒
something something
View GitHub Profile
@bennyhuo
bennyhuo / init.gradle.kts
Last active July 1, 2024 07:34
How to config mirrors for repositories in Gradle without changing the source code of your project?
fun RepositoryHandler.enableMirror() {
all {
if (this is MavenArtifactRepository) {
val originalUrl = this.url.toString().removeSuffix("/")
urlMappings[originalUrl]?.let {
logger.lifecycle("Repository[$url] is mirrored to $it")
this.setUrl(it)
}
}
}
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
@JoseAlcerreca
JoseAlcerreca / EventObserver.kt
Created April 26, 2018 12:14
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
@AndyBowes
AndyBowes / TreeNode.kt
Created August 2, 2017 11:20
Kotlin TreeNode (Draft)
fun idSequence(seed:Int=0) : Sequence<Int>{
return generateSequence(seed,{it + 1})
}
class TreeNode<T>(val id: T){
val childNodes = mutableListOf<TreeNode<T>>()
fun addChild(node: TreeNode<T>) = childNodes.add(node)
fun removeChild(node: TreeNode<T>) = childNodes.remove(node)
fun children() = childNodes.asIterable()
@yanngx
yanngx / FragmentArgumentDelegate.kt
Last active January 19, 2023 09:26
Fragment arguments without hassle !
package be.brol
import android.os.Binder
import android.os.Bundle
import android.support.v4.app.BundleCompat
import android.support.v4.app.Fragment
/**
* Eases the Fragment.newInstance ceremony by marking the fragment's args with this delegate
* Just write the property in newInstance and read it like any other property after the fragment has been created
@igorlukanin
igorlukanin / Wtf.kt
Created August 22, 2016 05:31
wtf-kotlin
package Wtf
// Primitives
operator fun Int.plus(that: String) = "$this$that"
operator fun String.plus(that: Int) = "$this$that"