Skip to content

Instantly share code, notes, and snippets.

View UdaraWanasinghe's full-sized avatar

UdaraWanasinghe UdaraWanasinghe

View GitHub Profile
@UdaraWanasinghe
UdaraWanasinghe / keymap.json
Created October 15, 2026 12:40
Zed keymap
// Zed keymap
//
// For information on binding keys, see the Zed
// documentation: https://zed.dev/docs/key-bindings
//
// To see the default key bindings run `zed: open default keymap`
// from the command palette.
[
{
"context": "Workspace",
const solids = [
"#FF8A80",
"#FF5252",
"#FF1744",
"#D50000",
"#FF80AB",
"#FF4081",
"#F50057",
"#C51162",
@UdaraWanasinghe
UdaraWanasinghe / CMakeLists.txt
Last active May 30, 2023 08:36
Find JNI include directories in Android
# find jni include directories
find_package(JNI)
if (NOT JAVA_INCLUDE_PATH)
message(FATAL_ERROR "Failed to find Java include path.")
endif()
# For CMake 3.24 and higher versions
find_package(JNI REQUIRED)
@UdaraWanasinghe
UdaraWanasinghe / ScrollingViewAssertions.kt
Last active May 5, 2023 10:01
Android ScrollingView Espresso assertions
import android.view.View
import androidx.core.view.ScrollingView
import androidx.test.espresso.NoMatchingViewException
import androidx.test.espresso.ViewAssertion
object ScrollingViewAssertions {
fun hasScrolledVertically(): ViewAssertion {
return HasScrolledVerticallyAssertion()
}
@UdaraWanasinghe
UdaraWanasinghe / ViewActions.kt
Last active May 5, 2023 09:54
Espresso view actions
import android.view.View
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import androidx.test.espresso.PerformException
import androidx.test.espresso.UiController
import androidx.test.espresso.ViewAction
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.espresso.util.HumanReadables
import androidx.test.espresso.util.TreeIterables
import androidx.viewpager2.widget.ViewPager2
@UdaraWanasinghe
UdaraWanasinghe / disable-usb.sh
Created April 20, 2023 04:11
Disabling USB device temporarily on Linux
# See device info
cat /sys/bus/usb/devices/1-2/product
# Set authorized to 0
echo 0 | sudo tee /sys/bus/usb/devices/1-2/authorized
@UdaraWanasinghe
UdaraWanasinghe / SpacingItemDecoration.kt
Last active March 24, 2022 07:24
Add space between RecyclerView list items. Works with both LinearLayoutManager and GridLayoutManager. VERTICAL and HORIZONTAL orientations are also supported.
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.StaggeredGridLayoutManager
class SpacingItemDecoration(
private val spacing: Int,
private val includeEdge: Boolean,
import android.content.res.Resources
import android.util.TypedValue
class DimensionExtensions {
companion object {
val Int.dp: Int
get() = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
this.toFloat(),
Resources.getSystem().displayMetrics
fun Path.forEach(callback: (Path) -> Unit) {
val pathMeasure = PathMeasure(this, false)
do {
val pathLength = pathMeasure.length
val pathSegment = Path()
pathMeasure.getSegment(0f, pathLength, pathSegment, true)
callback(pathSegment)
} while (pathMeasure.nextContour())
}
@UdaraWanasinghe
UdaraWanasinghe / BouncyEdgeEffectFactory.kt
Created August 20, 2021 14:29
Android RecyclerView Bouncing Scroll Effect
import android.graphics.Canvas
import android.view.View
import android.widget.EdgeEffect
import androidx.dynamicanimation.animation.SpringAnimation
import androidx.dynamicanimation.animation.SpringForce
import androidx.recyclerview.widget.RecyclerView
class BouncyEdgeEffectFactory : RecyclerView.EdgeEffectFactory() {
companion object {