Skip to content

Instantly share code, notes, and snippets.

View rock3r's full-sized avatar

Sebastiano Poggi rock3r

View GitHub Profile
@rock3r
rock3r / CacheableProperty.kt
Created January 8, 2019 13:54
A cacheable property in Kotlin — basically, a variant of Lazy that can be invalidated and will be reloaded on the next access
package me.seebrock3r.util
import me.seebrock3r.util.CacheableProperty.CachedValue.*
import kotlin.properties.*
import kotlin.reflect.*
import kotlin.reflect.jvm.*
fun <T> cache(producer: () -> T): CacheableProperty<T> = CacheableProperty(producer)
class CacheableProperty<out T>(val producer: () -> T) : ReadOnlyProperty<Any, T> {
@rock3r
rock3r / DividerItemDecorator.kt
Created September 4, 2018 11:25
A simple yet fully featured RecyclerView ItemDecorator that draws a divider line between items. Only works with vertical LinearLayoutManagers!
package me.seebrock3r.common.widget
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.view.View
import androidx.annotation.ColorInt
import androidx.annotation.Px
import androidx.core.graphics.withTranslation
import androidx.core.view.children
@rock3r
rock3r / normalizeColorHex.kts
Last active February 7, 2023 17:53
A Kotlin script to normalize hex colour representations ("#RGB", "#ARGB", "#RRGGBB", "#AARRGGBB") into "#AARRGGBB", useful for when you're trying to find all unique colours in your app
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Sebastiano Poggi wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Seb
* ----------------------------------------------------------------------------
* Feel free to attribute this code in compiled products if you feel like it,
* but it's not required.
*/
@rock3r
rock3r / RxFilterIsInstance.kt
Last active June 22, 2018 12:34
RxKotlin's ofType() name is not very easy to remember, given Kotlin has filterIsInstance() for the same. This helps alleviate the pain.
package me.seebrock3r.extensions.reactivex
import io.reactivex.Flowable
import io.reactivex.Observable
import io.reactivex.rxkotlin.ofType
@Deprecated(
message = "This is just a shorthand for RxKotlin's ofType()",
replaceWith = ReplaceWith("ofType<R>()", "io.reactivex.rxkotlin.ofType")
)
@rock3r
rock3r / gw-update.sh
Last active June 30, 2023 01:27
Simple script to update Gradle from the command line (*NIX)
#!/bin/sh
# License for any modification to the original (linked below):
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# Sebastiano Poggi wrote this file. As long as you retain
# this notice you can do whatever you want with this stuff. If we meet some day,
# and you think this stuff is worth it, you can buy us a beer in return.
#### SETUP/USAGE INSTRUCTIONS ####

Keybase proof

I hereby claim:

  • I am rock3r on github.
  • I am rock3r (https://keybase.io/rock3r) on keybase.
  • I have a public key ASAFs_czYB4sp1Df7-lZ0TUdAT-5jye6IxjyE9OKPIVoIwo

To claim this, I am signing this object:

@rock3r
rock3r / AndroidOSVersionCheckerTest.kt
Created October 5, 2017 16:44
Testable Kotlin Android OS version checker, with tests
package me.seebrock3r.utils
import android.os.Build.VERSION_CODES.JELLY_BEAN_MR1
import android.os.Build.VERSION_CODES.JELLY_BEAN_MR2
import android.os.Build.VERSION_CODES.KITKAT
import android.os.Build.VERSION_CODES.LOLLIPOP
import android.os.Build.VERSION_CODES.LOLLIPOP_MR1
import android.os.Build.VERSION_CODES.M
import android.os.Build.VERSION_CODES.N
import org.assertj.core.api.Assertions.assertThat
@rock3r
rock3r / find_in_dependencies.gradle
Last active July 19, 2021 18:29
Utility Gradle task to find where duplicate classes come from (for Gradle 4.1+)
// H/t to https://github.com/ethankhall/scripts/blob/master/gradle/find-file.gradle for the idea;
// this re-written version actually works in modern Gradle and Android Gradle plugins.
task findInDependencies {
doLast {
println()
def resolvableConfigs = project.getConfigurations()
.stream()
.filter { it.isCanBeResolved() }
@rock3r
rock3r / avd_flush_anim.xml
Last active January 20, 2017 13:20
Standardised Japanese Toilet 🚽 Big Flush 🌀 pictogram - as Animated Vector Drawable
<!-- All copyright to the original owners. The AVD version is free to use; please give attribution if you redistribute/modify -->
<animated-vector
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt">
<aapt:attr name="android:drawable">
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="693dp"
android:height="693dp"
android:viewportWidth="693"
@rock3r
rock3r / gfonts.py
Last active October 19, 2016 13:20
Rip fonts from Google Fonts for self-hosting, EZ
#!/usr/bin/python
#coding: utf-8
import argparse, os, tinycss, requests
def parse_cli_arguments():
parser = argparse.ArgumentParser(description='Downlads all available variants of a font from Google Fonts')
parser.add_argument('fontname', type=str, help='The name of the font. E.g., "Roboto", "Product Sans"')
return parser.parse_args()