Skip to content

Instantly share code, notes, and snippets.

View Xinkle's full-sized avatar
👨‍💻
Newbie coder

Sunook Choi(Xinkle) Xinkle

👨‍💻
Newbie coder
View GitHub Profile
fun Long.toReadableDate(
format: String = "yyyy-MM-dd HH:mm",
locale: Locale = Locale.KOREA
): String {
return SimpleDateFormat(format, locale).format(Date(this))
}
@Xinkle
Xinkle / SortingWithGivenOrder.kt
Last active April 23, 2020 09:41
Kotlin custom high order functions
/**
* Sort collection with given order(list)
*/
class SortingWithGivenOrder<T>(
private val selector: (T) -> String,
private val orders: List<String>
) : Comparator<T> {
constructor(selector: (T) -> String, vararg orders: String) : this(selector, orders.toList())
private val ordersMap = HashMap<String, Int>().apply {
// Get current date with formatting
SimpleDateFormat("yyyyMMdd", Locale.KOREA).format(Calendar.getInstance().time)