Skip to content

Instantly share code, notes, and snippets.

View ericksli's full-sized avatar

Eric Li ericksli

View GitHub Profile
@ericksli
ericksli / ReactNativeExtensions.kt
Last active March 20, 2024 19:51
React Native Kotlin extension functions for creating WritableMap and WritableArray #android #react-native #kotlin
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.WritableArray
import com.facebook.react.bridge.WritableMap
fun writableMapOf(vararg values: Pair<String, *>): WritableMap {
val map = Arguments.createMap()
for ((key, value) in values) {
when (value) {
null -> map.putNull(key)
is Boolean -> map.putBoolean(key, value)
@ericksli
ericksli / build.gradle
Created August 29, 2016 04:09
Android app show Git commit hash as version name
import java.util.regex.Pattern
apply plugin: 'com.android.application'
/**
* Extract Git commit hash of HEAD with number of changed files
*/
def getGitHashVersionName = {
try {
def hashOutput = new ByteArrayOutputStream()
@ericksli
ericksli / Calendar Template.html
Created October 17, 2018 05:19
Google Apps Script create calendar events
<b>英文名:</b> <?= enTitle ?>
<br><b>中文名:</b> <?= zhTitle ?>
@ericksli
ericksli / AppLocale.kt
Created January 25, 2023 05:54
Android 13 Per-app Language Preferences
package net.swiftzer.metroride.common
enum class AppLocale {
SystemDefault,
English,
Chinese,
}
@ericksli
ericksli / AdMob.kt
Created July 26, 2022 05:50
AdMob AdView in Jetpack Compose
import android.view.ViewGroup
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@ericksli
ericksli / layout.xml
Last active April 10, 2021 03:28
Icon at the end of TextView with view at the end of layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<!-- Simple horizontal chain -->
@ericksli
ericksli / TimberJava.xml
Last active February 11, 2021 18:19
Timber Android Studio live template for Java and Kotlin #kotlin #android
<templateSet group="TimberJava">
<template name="timd" value="timber.log.Timber.d(&quot;$METHOD_NAME$: $content$&quot;);" description="Timber.d(String)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD_NAME" expression="methodName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
<context>
<option name="JAVA_STATEMENT" value="true" />
</context>
</template>
<template name="time" value="timber.log.Timber.e($exception$, &quot;$METHOD_NAME$: $content$&quot;);" description="Timber.e(Exception, String)" toReformat="true" toShortenFQNames="true">
<variable name="exception" expression="" defaultValue="e" alwaysStopAt="true" />
@ericksli
ericksli / FeatureFlag.kt
Last active April 29, 2020 15:35
Kotlin annotation processor example
package com.example.annotation.annotation
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.FUNCTION)
@MustBeDocumented
annotation class FeatureFlag(val key: String, val defaultValue: Boolean)
@ericksli
ericksli / README.md
Last active January 11, 2020 11:37
Move PNG files for Android and iOS project

movepng

Move PNG files for Android and iOS project.

Suppose you have these images exported from Avocode in ~/Downloads/test:

.
├── image_distance-hdpi.png
├── image_distance-mdpi.png
@ericksli
ericksli / nodes.csv
Created September 23, 2014 05:26
Data.One Traffic Speed Map Nodes
Node Latitude Longitude
722 22.28599466 114.1552444
724 22.28514213 114.1563129
752 22.27957768 114.1655361
756 22.27963564 114.1679961
760 22.27927381 114.1704165
762 22.27953399 114.1745641
781 22.27525639 114.1799562
786 22.28155011 114.1819768
787 22.2806696 114.1806507