Skip to content

Instantly share code, notes, and snippets.

View tw-Frey's full-sized avatar

Frey tw-Frey

  • Taipei, Taiwan
View GitHub Profile
@tw-Frey
tw-Frey / InputType_for_EditText.md
Last active February 10, 2022 21:59 — forked from lopspower/README.md
All InputType for EditText

All InputType for EditText

Twitter

Constant Description
none There is no content type. The text is not editable.
@tw-Frey
tw-Frey / yyyyMMdd .md
Last active February 5, 2022 02:03
日期 yyyyMMdd 的 Regex
@tw-Frey
tw-Frey / gist:5544def03471c1f761b51e710289e6e7
Created January 20, 2022 10:40 — forked from kaochenlong/gist:1889703
台灣公司統一編號判斷規則
# encoding: utf-8
def company_serial_no_checker(serial)
# 共八位,全部為數字型態
at_least_8_digits = /^\d{8}$/
return false unless at_least_8_digits.match(serial)
# 各數字分別乘以 1,2,1,2,1,2,4,1
# 例:統一編號為 53212539
@tw-Frey
tw-Frey / StateFlow_support_DataBinding.md
Created January 12, 2022 08:06
StateFlow support (Android DataBinding) is a preview feature that requires version 7.0.0-alpha04 or higher of the Android Gradle plugin.
@tw-Frey
tw-Frey / fullBackupOnly.md
Created January 9, 2022 07:45
Android Auto Backup and whatever android:fullBackupOnly is true/false

Why android:fullBackupOnly default value is false?


Cheok Yan Cheng 問道:

In https://developer.android.com/guide/topics/manifest/application-element,

android:fullBackupOnly

>This attribute indicates whether or not to use Auto Backup on devices where it is available. If set to true, then your app performs Auto Backup when installed on a device running Android 6.0 (API level 23) or higher. On older devices, your app ignores this attribute and performs Key/Value Backups. The default value is "false".

@tw-Frey
tw-Frey / User_Events_in_RecyclerViews.md
Created January 7, 2022 04:24
User events in RecyclerViews

If the action is produced further down the UI tree, like in a RecyclerView item or a custom View, the ViewModel should still be the one handling user events.

For example, suppose that all news items from NewsActivity contain a bookmark button. The ViewModel needs to know the ID of the bookmarked news item. When the user bookmarks a news item, the RecyclerView adapter does not call the exposed addBookmark(newsId) function from the ViewModel, which would require a dependency on the ViewModel. Instead, the ViewModel exposes a state object called NewsItemUiState which contains the implementation for handling the event:

data class NewsItemUiState(
    val title: String,
    val body: String,
    val bookmarked: Boolean = false,
    val publicationDate: String,
    val onBookmark: () -> Unit
@tw-Frey
tw-Frey / log4j_rce_detection.md
Created December 14, 2021 04:25 — forked from Neo23x0/log4j_rce_detection.md
Log4j RCE CVE-2021-44228 Exploitation Detection

log4j RCE Exploitation Detection

You can use these commands and rules to search for exploitation attempts against log4j RCE vulnerability CVE-2021-44228

Grep / Zgrep

This command searches for exploitation attempts in uncompressed files in folder /var/log and all sub folders

sudo egrep -I -i -r '\$(\{|%7B)jndi:(ldap[s]?|rmi|dns|nis|iiop|corba|nds|http):/[^\n]+' /var/log
@tw-Frey
tw-Frey / git_commits.md
Last active December 8, 2021 07:49
計算 git commit 數

Windows 版

for /f "tokens=*" %i in ('git ls-files') do @(
  for /f %j in ('git log --oneline "%i" ^| find /c /v ""') do @echo "%j", "%i"
) >> git-ls-files-log-count-commits.txt
@tw-Frey
tw-Frey / play-services-cloud-messaging-17.0.0.md
Last active November 23, 2021 02:43
Fatal Exception: java.lang.SecurityException without permission com.google.android.c2dm.permission.RECEIVE

https://stackoverflow.com/questions/53954114

Fatal Exception: java.lang.SecurityException: Not allowed to bind to service Intent { act=com.google.android.c2dm.intent.REGISTER pkg=com.google.android.gms }
       at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1741)
       at android.app.ContextImpl.bindService(ContextImpl.java:1651)
       at android.content.ContextWrapper.bindService(ContextWrapper.java:705)
       at com.google.android.gms.common.stats.ConnectionTracker.zza(ConnectionTracker.java:41)
       at com.google.android.gms.common.stats.ConnectionTracker.zza(ConnectionTracker.java:10)
       at com.google.android.gms.common.stats.ConnectionTracker.bindService(ConnectionTracker.java:43)
@tw-Frey
tw-Frey / ProcessLifecycleOwner.md
Last active November 16, 2021 09:45
How to detect when an Android app goes to the background and come back to the foreground... (十年問題)

https://stackoverflow.com/questions/4414171
這問題歷經十年
解決方案也有變化...


比較優雅的做法是使用:

ProcessLifecycleOwner

https://developer.android.com/reference/android/arch/lifecycle/ProcessLifecycleOwner.html

ProcessLifecycleOwner will dispatch ON_START, ON_RESUME events, as a first activity moves through these events. ON_PAUSE, ON_STOP, events will be dispatched with a delay after a last activity passed through them. This delay is long enough to guarantee that ProcessLifecycleOwner won't send any events if activities are destroyed and recreated due to a configuration change.