Skip to content

Instantly share code, notes, and snippets.


Fredrik H. Larsen frel

View GitHub Profile
frel / TinyThumbDecoder.kt
Last active Aug 15, 2021
AirBrush Medium article example
View TinyThumbDecoder.kt
class TinyThumbDecoder(
private var context: Context,
private val bitmapPool: BitmapPool,
private val blurProvider: (source: Bitmap, options: BlurOptions?) -> Bitmap
) : ResourceDecoder<TinyThumb, BitmapDrawable> {
override fun handles(source: TinyThumb, options: Options) = source.base64.isNotEmpty()
override fun decode(
source: TinyThumb,
frel / TinyThumbDataFetcher.kt
Created Aug 15, 2021
AirBrush Medium article example
View TinyThumbDataFetcher.kt
class TinyThumbDataFetcher(private val thumb: TinyThumb) : DataFetcher<TinyThumb> {
override fun loadData(
priority: Priority,
callback: DataFetcher.DataCallback<in TinyThumb>
) = callback.onDataReady(thumb)
override fun getDataClass(): Class<TinyThumb> =
override fun getDataSource(): DataSource = DataSource.LOCAL
override fun cleanup() { /* Do nothing */ }
frel / TinyThumbLoader.kt
Created Aug 15, 2021
AirBrush Medium article example
View TinyThumbLoader.kt
class TinyThumbLoader : ModelLoader<TinyThumb, TinyThumb> {
override fun buildLoadData(
model: TinyThumb,
width: Int,
height: Int,
options: Options
) = ModelLoader.LoadData(
frel / ImageLoader.kt
Created Aug 15, 2021
AirBrush Medium article example
View ImageLoader.kt
val thumbnail = TinyThumb(base64 = "...")
frel / GlideModule.kt
Created Aug 15, 2021
AirBrush Medium article example
View GlideModule.kt
class GlideModule : AppGlideModule() {
override fun registerComponents(context: Context, glide: Glide, registry: Registry) {
// Register a ModelLoaderFactory for TinyThumb allowing the type to be loaded using Glide
registry.append(,, TinyThumbLoader.Factory())
// Register a ResourceDecoder for TinyThumb. Specifying the input and output type.
// Note that the tailing lambda is the blur provider. If we wanted to use another blur
// implementation we could replace it here.
View FragmentExt.kt
* Based on
* Refactored to use the preferred `DefaultLifecycleObserver` which does not rely on the annotation processor.
* See
* Usage:
* `private var binding: TheViewBinding by viewLifecycle()`
frel / MainActivity.kt
Last active Oct 23, 2018
This is an example of how log events can be defined using android resources files.
View MainActivity.kt
package com.subgarden.eventlogging
import android.os.Bundle
import android.util.Log
import java.util.*
class MainActivity : AppCompatActivity() {
View tus-js-client-upload-example.js
var fs = require("fs");
var tus = require("tus-js-client");
const ENDPOINT = "http://"
const FILE_NAME = "video.MOV"
const X_AUTH_KEY = ""
const file = fs.readFileSync( __dirname + "/"+ FILE_NAME)
if (file.err) {