Skip to content

Instantly share code, notes, and snippets.

Avatar

Sebastiano Poggi rock3r

View GitHub Profile
@rock3r
rock3r / cleanup-rtf.sh
Created Sep 2, 2020
Remove background from RTF text (copied from IntelliJ/Android Studio) via a simple script [macOS only]
View cleanup-rtf.sh
#!/bin/sh
# Remove background from RTF text (copied from IntelliJ/Android Studio/...)
# By Sebastiano Poggi, Apache 2.0 license: https://www.apache.org/licenses/LICENSE-2.0
#
# Text is altered in-place in the clipboard. If copying from an IDE, make sure you have the
# "Copy a text fragment" preference set to "Rich text" in the IDE preferences Editor > General.
#
# Also available as a Quick Action to easily install on macOS from here:
# https://www.dropbox.com/s/8qboebourj3jkzo/Copy%20for%20Keynote.workflow.zip?dl=1
@rock3r
rock3r / c2webp.kts
Created Jul 23, 2020
Kscript program to convert a sequence of images to a webp animation, using img2webp
View c2webp.kts
#!/bin/bash
//usr/bin/env echo '
/**** BOOTSTRAP kscript ****\'>/dev/null
command -v kscript >/dev/null 2>&1 || curl -L "https://git.io/fpF1K" | bash 1>&2
exec kscript $0 "$@"
\*** IMPORTANT: Any code including imports and annotations must come after this line ***/
@file:DependsOn("com.github.ajalt:clikt:2.8.0")
@rock3r
rock3r / sebs-fancy-idea-editor-colour-scheme.icls
Last active Jan 28, 2020
Seb's Fancy Custom IJ IDEA/AS Hipster Colour Scheme — v1.0
View sebs-fancy-idea-editor-colour-scheme.icls
<scheme name="Seb's Fancy Custom Hipster Colour Scheme v1.0" version="142" parent_scheme="Darcula">
<option name="FONT_SCALE" value="1.0" />
<metaInfo>
<property name="created">2020-01-28T16:17:01</property>
<property name="ide">idea</property>
<property name="ideVersion">2020.1.0.0</property>
<property name="modified">2020-01-28T16:17:11</property>
<property name="originalScheme">Solarized Seeb</property>
</metaInfo>
<option name="LINE_SPACING" value="1.25" />
@rock3r
rock3r / findProjectGitRoot.kt
Created Nov 13, 2019
Extension property for Gradle's Project interface to figure out the Git root, if any
View findProjectGitRoot.kt
package dev.sebastiano.utils.gradle
import org.gradle.api.*
import java.io.*
// Note: you need to have a dependency on `gradleApi()` in your buildSrc project
val Project.gitRoot: File?
get() {
fun File.isGitRoot() = isDirectory && File(this, ".git").isDirectory
@rock3r
rock3r / build.gradle.kts
Created Jun 21, 2019
A Gradle Kotlin DSL task to enumerate the resolved Kotlin plugin version for all subprojects
View build.gradle.kts
tasks.register("kotlinPluginVersions") {
description = "Shows the resolved Kotlin plugin version for all subprojects"
group = "documentation"
doLast {
subprojects.forEach { subproject ->
System.err.println("****** Project ${subproject.name} plugins ******")
subproject.plugins.filterIsInstance<KotlinBasePluginWrapper>()
.forEach {
System.err.println("Kotlin plugin ${it.kotlinPluginVersion}")
}
View SideEffects.kt
package me.seebrock3r.util
/**
* Calls the specified function [block] as a side effect of a previous expression.
*
* This is similar to [run] in that it's used to chain side effects, but it
* doesn't return anything and the block doesn't have any parameters. If your
* side effects require either of those things, use [run] or [also] instead.
*
* @see run
@rock3r
rock3r / CacheableProperty.kt
Created Jan 8, 2019
A cacheable property in Kotlin — basically, a variant of Lazy that can be invalidated and will be reloaded on the next access
View CacheableProperty.kt
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 Sep 4, 2018
A simple yet fully featured RecyclerView ItemDecorator that draws a divider line between items. Only works with vertical LinearLayoutManagers!
View DividerItemDecorator.kt
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 Mar 24, 2019
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
View normalizeColorHex.kts
/*
* ----------------------------------------------------------------------------
* "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 Jun 22, 2018
RxKotlin's ofType() name is not very easy to remember, given Kotlin has filterIsInstance() for the same. This helps alleviate the pain.
View RxFilterIsInstance.kt
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")
)
You can’t perform that action at this time.