Skip to content

Instantly share code, notes, and snippets.

View ZacSweers's full-sized avatar

Zac Sweers ZacSweers

View GitHub Profile
@saket
saket / AnimatedVideoFrameDecoder.kt
Last active September 4, 2023 19:01
A Coil decoder for generating animated previews of videos
import android.graphics.drawable.AnimationDrawable
import coil.ImageLoader
import coil.decode.DecodeResult
import coil.decode.Decoder
import coil.decode.VideoFrameDecoder
import coil.fetch.SourceResult
import coil.request.Options
import coil.request.Parameters
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
@adityabhaskar
adityabhaskar / dependencyGraph-mermaid.gradle
Last active May 17, 2023 17:32
Dependency graphs in a multi module project, in mermaid format for automatic rendering on Github
class GraphDetails {
LinkedHashSet<Project> projects
LinkedHashMap<Tuple2<Project, Project>, List<String>> dependencies
ArrayList<Project> multiplatformProjects
ArrayList<Project> androidProjects
ArrayList<Project> javaProjects
ArrayList<Project> rootProjects
// Used for excluding module from graph
public static final SystemTestName = "system-test"
@alexfu
alexfu / DateTimeExtensions.kt
Created July 22, 2022 17:29
Do you wish there was an easier way to write dates in Kotlin?
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.Month
import java.time.ZonedDateTime
import java.util.TimeZone
fun January(day: Int, year: Int) = LocalDate.of(year, Month.JANUARY, day)
fun February(day: Int, year: Int) = LocalDate.of(year, Month.FEBRUARY, day)
fun March(day: Int, year: Int) = LocalDate.of(year, Month.MARCH, day)
fun April(day: Int, year: Int) = LocalDate.of(year, Month.APRIL, day)
@dlew
dlew / thing.kt
Last active January 31, 2021 02:30
Gson -> Moshi name snafu detector
@Test
fun verifySerializedNameMatchesJsonName() {
// Reflections library
Reflections("com.foobar").getTypesAnnotatedWith(JsonClass::class.java)
.flatMap { clz ->
// FieldUtils is in Apache Commons
FieldUtils.getAllFieldsList(clz).filter { !Modifier.isStatic(it.modifiers) }
}
.forEach { field ->
val serializedNameAnnotation = field.declaredAnnotations.find { it is SerializedName } as? SerializedName
/**
* 1) Change agpVersion
* 2) Run './gradlew dumpSources'
* 3) Check changeset into source control
*/
def agpVersion = 'UPDATE_THIS'
repositories {
google()
jcenter()

Build "Sources for Android 29" so you can comfortably browse the Android API source in Android Studio.

  1. Collect source files
mkdir android-sdk-source-build
cd android-sdk-source-build

mkdir -p frameworks/base
@ShaishavGandhi
ShaishavGandhi / JavaPoetExt.kt
Last active May 2, 2022 21:14
Extensions to convert JavaPoet types to KotlinPoet and vice-versa
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.ParameterizedTypeName
import com.squareup.javapoet.TypeName
import com.squareup.javapoet.TypeVariableName
import com.squareup.javapoet.WildcardTypeName
import com.squareup.javapoet.ArrayTypeName
import com.squareup.kotlinpoet.ARRAY
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
fun ClassName.asKPClassName(): com.squareup.kotlinpoet.ClassName {
fun main(args: Array<String>) {
println("a" to "b")
println("a" to "b" tre "c")
println("a" to "b" tre "c" fo "d")
println("a" to "b" tre "c" fo "d" fi "e")
println("a" to "b" tre "c" fo "d" fi "e" sik "f")
println("a" to "b" tre "c" fo "d" fi "e" sik "f" seva "g")
}
infix fun <A, B, C> Pair<A, B>.tre(c: C) = Triple(first, second, c)
/*
* Copyright (C) 2018 Square, Inc.
*
* 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
@berikv
berikv / gifify
Last active December 21, 2021 16:51
Transform a movie file to a gif. Specialised for demo's of Mobile app screen recordings.
#!/bin/bash
FFMPEG=$(command -v ffmpeg)
INFILE=$1
OUTFILE="${INFILE}.gif"
TMPFILE="${INFILE}_gifify_palette.png"
if ! $FFMPEG -L > /dev/null 2>&1; then
echo "Run: brew install ffmpeg"
exit 1