Skip to content

Instantly share code, notes, and snippets.

View gtomek's full-sized avatar

Tomek Giszczak gtomek

  • Zurich, CH
View GitHub Profile
@mskoroglu
mskoroglu / LocaleSortingExtensions.kt
Last active July 6, 2022 09:34
Kotlin extension functions for sorting by locale(lang, country)
// Example: cities.sortedWithLocaleBy(Locale("tr")) { it.name }
inline fun <T, R : Comparable<R>> Iterable<T>.sortedWithLocaleBy(
locale: java.util.Locale,
crossinline selector: (T) -> R?
) = sortedWith(compareBy(java.text.Collator.getInstance(locale), selector))
// Example: cities.sortedWithLocaleByDescending(Locale("tr")) { it.name }
inline fun <T, R : Comparable<R>> Iterable<T>.sortedWithLocaleByDescending(
locale: java.util.Locale,
crossinline selector: (T) -> R?
@chrisbanes
chrisbanes / SystemUiHelper.java
Last active March 2, 2024 18:57
SystemUiHelper
/*
* Copyright (C) 2014 The Android 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
@JakeWharton
JakeWharton / Truss.java
Last active June 9, 2023 07:35
Extremely simple wrapper around SpannableStringBuilder to make the API more logical and less awful. Apache 2 licensed.
import android.text.SpannableStringBuilder;
import java.util.ArrayDeque;
import java.util.Deque;
import static android.text.Spanned.SPAN_INCLUSIVE_EXCLUSIVE;
/** A {@link SpannableStringBuilder} wrapper whose API doesn't make me want to stab my eyes out. */
public class Truss {
private final SpannableStringBuilder builder;
private final Deque<Span> stack;