Skip to content

Instantly share code, notes, and snippets.

// ==UserScript==
// @name Type Guard
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Chuang Yu
// @match *://*/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
// @grant none
// ==/UserScript==
@halilozercan
halilozercan / DrawGlyphs.kt
Created October 1, 2023 20:30
A Set of helper functions and classes to draw each individual glyph separately
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ImageBitmap
@alexjlockwood
alexjlockwood / TypedArrayUtils.kt
Created August 13, 2019 16:51
Kotlin helper functions for extracting ColorStateLists and Drawables from a TypedArray using AppCompatResources.
import android.content.Context
import android.content.res.ColorStateList
import android.content.res.TypedArray
import android.graphics.drawable.Drawable
import androidx.annotation.StyleableRes
import androidx.appcompat.content.res.AppCompatResources
/**
* Utility methods for extracting [ColorStateList]s and [Drawable]s from a [TypedArray].
/*
* 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
@domnikl
domnikl / build.gradle.kts
Last active April 12, 2024 22:34
Gradle Kotlin DSL: set main class attribute for jar
tasks.withType<Jar> {
manifest {
attributes["Main-Class"] = "com.example.MainKt"
}
}
@anestisb
anestisb / art_9.0_compact_dex_converter.patch
Last active December 20, 2023 07:36
Cdex to Dex converter utility using AOSP ART libdexlayout
diff --git a/dexlayout/Android.bp b/dexlayout/Android.bp
index 33ba58f..f3b2a7e 100644
--- a/dexlayout/Android.bp
+++ b/dexlayout/Android.bp
@@ -74,6 +74,13 @@ cc_defaults {
],
}
+cc_defaults {
+ name: "compact_dex_converter_defaults",
@aftabsikander
aftabsikander / ProjectUtils.java
Created June 20, 2018 14:27
MediaScanner Sample
public class ProjectUtils {
/***
* Force MediaScanner to update its media database for recently added files.
* @param context the calling context.
* @param filePathForScan File path which will request the media scanner to rescan and add it
* to the media database.
*/
public static void forceUpdateMediaScanner(Context context, String filePathForScan) {
if (context != null) {
new SingleMediaScanner(context, new File(filePathForScan));
@zhanghai
zhanghai / NaturalOrderComparator.java
Created June 16, 2018 09:57
Java Comparator for Natural Sort Order
/*
* Copyright (c) 2018 Zhang Hai <Dreaming.in.Code.ZH@Gmail.com>
*
* 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
@Takhion
Takhion / ExhaustiveWhen.kt
Last active July 28, 2021 19:19
Exhaustive `when` mapping in Kotlin
@file:Suppress("PackageDirectoryMismatch") // root package looks great when importing, ie. `import exhaustive`
/**
* Allows requiring an exhaustive mapping in a `when` block when used with the [rangeTo] operator.
* @sample [exhaustive_when_example]
*/
@Suppress("ClassName") // lowercase because it should look like a keyword
object exhaustive {
import android.support.v7.widget.RecyclerView
/**
* @author drakeet
*/
class QuickReturnDelegate(private val scrollSlop: Int = 12) : RecyclerView.OnScrollListener() {
private lateinit var callback: (hide: Boolean) -> Unit
private var scrollY: Int = 0