This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Utility function to sort elements by some nested property or another calculated value. Meant to fix JavaScript | |
* missing a built-in `sortedBy` function like Kotlin has. | |
* @example | |
* people.sort(by(person => person.age)) | |
* @param accessor a function that should return the value to sort by if called on an element | |
*/ | |
export const by: <T>(accessor: (element: T) => string | number) => (a: T, b: T) => number = (accessor) => | |
(a, b) => { | |
const aValue = accessor(a) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun styled(style: AnsiStyle, str: String) = style.code + str + AnsiStyle.RESET | |
interface AnsiStyle { | |
val code: String | |
companion object { | |
const val RESET = "\u001B[0m" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.Dispatchers | |
import kotlinx.coroutines.async | |
import kotlinx.coroutines.suspendCancellableCoroutine | |
import kotlinx.coroutines.withContext | |
import java.io.File | |
class UploadFilesUseCase : BaseBusyObservable<UploadFilesUseCase.Listener>() { | |
interface Listener { | |
fun onFilesUploaded() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
configurations { | |
// Creating testOutput configuration to bundle test dependencies and sources so other projects can depend on them | |
testOutput.extendsFrom(testCompile) | |
} | |
dependencies { | |
testOutput sourceSets.test.output | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<application> | |
<component name="RainbowSettings"> | |
<option name="darkRoundBracketsColors"> | |
<array> | |
<option value="0x4f5b62" /> | |
<option value="0x718792" /> | |
<option value="0x8eacbb" /> | |
<option value="0xc1d5e0" /> | |
<option value="0xfefefe" /> | |
</array> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.UUID | |
/** | |
* Superclass for classes that wrap a single value for type safety purposes. | |
*/ | |
abstract class WrapperType<T : Any>(val value: T) { | |
override fun toString() = value.toString() | |
override fun equals(other: Any?) = other is WrapperType<*> && value == other.value | |
override fun hashCode() = value.hashCode() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns a new List with the element at [fromIndex] moved to [toIndex] | |
*/ | |
private fun <T> List<T>.move(fromIndex: Int, toIndex: Int) = this.mapIndexed { index, element -> when { | |
index == toIndex -> this[fromIndex] | |
fromIndex < toIndex && index in fromIndex..toIndex -> this[index + 1] | |
fromIndex > toIndex && index in toIndex..fromIndex -> this[index - 1] | |
else -> element | |
} } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T, U> memoized(function: (T) -> U): (T) -> U { | |
val cache = mutableMapOf<T, U>() | |
return { t -> cache.getOrPut(t) { function(t) } } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseActivity : Activity { | |
val permissionHandler: PermissionRequestHandler | |
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) { | |
val handled = permissionHandler.onRequestPermissionsResult(requestCode, permissions, grantResults) | |
if(!handled) { | |
super.onRequestPermissionsResult(requestCode, permissions, grantResults) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.support.v7.util.DiffUtil | |
open class DiffUtilCallback<T>(val oldList: List<T>, val newList: List<T>) : DiffUtil.Callback() { | |
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int) | |
= oldList[oldItemPosition] == newList[newItemPosition] | |
override fun getOldListSize() | |
= oldList.size |
NewerOlder