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 / WebViewServer.kt
Created October 23, 2019 14:56 — forked from ErikHellman/WebViewServer.kt
A simple "web server" for handling intercepted WebView requests on Android and deliver local content.
/*
MIT License
Copyright (c) 2019 Erik Hellman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@tw-Frey
tw-Frey / BDD.md
Created October 25, 2019 22:40
討厭寫文件?那就改用 BDD (Behavior-Driven Development)

重寫的專案我會要求用 BDD 來開發,原因無它:因為寫好的文件就可以拿來驗證程式碼。如果你覺得寫文件很浪費時間,不如寫程式一次搞定,那麼 BDD 絕對會是你應該試試的開發模式。因為常見的 BDD 框架通常是採用 Gherkin 語法來描寫功能 (feature) ,這使得文件本身很好讀,又容易轉換成驗證用的 context 程式,所以也很適合用在 PM 與開發者合作;也就是 PM 寫 feature ,讓開發者用 feature 來驗證自己寫的程式碼。

BDD 通常是以情境來當驗證案例,所以前面收集到的規格和情境很適合用在這裡,也因此 BDD 通常會結合 e2e 測試來進行。這麼一來文件的更新,也會影響到測試是否能夠通過,就不會再發生文件和程式碼不一致的情況了。

@tw-Frey
tw-Frey / psychopath_coder.md
Last active March 23, 2022 08:33
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
@tw-Frey
tw-Frey / Android_Youtube.md
Last active October 26, 2019 09:11
探究 Android 手機 播放 Youtube 載入前出現破圖

Android 手機 播放 Youtube 載入前出現破圖

不是 VideoPoster

(Android 6.0 WebChromeClient 要實作非空 getDefaultVideoPoster 否則會 NP crash)

打開瀏覽器調試

翻來翻去

@tw-Frey
tw-Frey / AOSP-WebView.md
Last active November 12, 2019 04:03
部分 Android L 使用 WebView 會 crash 的問題

在最近的項目引用 WebViewSupportFragmentX
結果在 Android L 模擬器上 會 crash
因為該項目使用 Android Studio 3.6-beta 加 Kotlin 1.3.50
以為該不會無法支援 Android L
又以為 WebViewSupportFragmentX 會不會哪裡有錯
後來發現
在直接 new WebView 就會 crash (在 Android L 模擬器上)
錯誤如下

android.content.res.Resources$NotFoundException: String resource ID #0x2040002
@tw-Frey
tw-Frey / push_to_emulator_system.md
Last active July 28, 2022 06:00
如何 push 檔案到 Android Emulator 的 /system (USE -writable-system)

因為項目需要
要調整 /system/framework/framework-res.apk
網路上可以查到很多方法寫入 /system (下面會再補充)
但因為 Android Emulator 不斷更新
很多方法已經失效 (有的方法以前有用過能 work, 現在已經不行了)
後來注意到 這篇 (Read only file system on Android) 回應
才想起 Emulator 有個參數: -writable-system
為了寫入 system partition 新增的
要注意是

-writable-system

@tw-Frey
tw-Frey / replace-android-system-webview-package-name.md
Last active November 21, 2025 03:01 — forked from maokwen/replace-android-system-webview.md
替换 Webview 預設 Package Name, e.g. [com.android.webview] → [com.google.android.webview]
  1. 安装最新的 Android System Webview (com.google.android.webview)
  2. 拷贝 (pull) 一份 /System/framework/framework-res.apk 的副本到任意位置
  3. 搜索在其中搜索 webview, 将 /android/string/config_webViewPackageName 的值改为 com.google.android.webview
  4. 将修改后的文件覆盖回 (push) 原位置
  5. 重启
@tw-Frey
tw-Frey / BriefLogFormatter.kt
Created November 12, 2019 10:33 — forked from mikehearn/BriefLogFormatter.kt
BriefLogFormatter
// A couple of inlined utility functions: the first is just a syntax convenience, the second lets us use
// Kotlin's string interpolation efficiently: the message is never calculated/concatenated together unless
// logging at that level is enabled.
inline fun <reified T : Any> loggerFor(): org.slf4j.Logger = LoggerFactory.getLogger(T::class.java)
inline fun org.slf4j.Logger.trace(msg: () -> String) {
if (isTraceEnabled) trace(msg())
}
/**
* A Java logging formatter that writes more compact output than the default.
@tw-Frey
tw-Frey / Koin_vs_Dagger2.md
Last active November 20, 2019 17:52
Koin vs Dagger (Service Locator vs D.I.)

Koin vs Dagger (Service Locator vs D.I.)

By Brian Plummer ● droidcon New York City 2019 ● 2019/09/27
[連結] [VIMEO] [YOUTUBE]

With Koin 2.0 it’s time for us to evaluate this age old debate. What exactly do we mean by service locator vs dependency injection? Does it matter in a modern age? I will discuss this topic along with how both libraries are implemented with an emphasis on their differences and how that affects us. By the end of this talk you will have an understanding of their implementations and the knowledge to assess which one is right for you!


Transcript

@tw-Frey
tw-Frey / Getting_big_payouts_with_Koin.md
Last active November 20, 2019 18:34
Getting big payouts with Koin

Getting big payouts with Koin

By Rick Busarow ● droidcon New York City 2019 ● 2019/09/27
[連結][VIMEO][YOUTUBE]

Thanks to its clean design, Koin is quickly gaining popularity as a service locator framework. Highlights include its excellent documentation, accessible api, and the pure Kotlin source code.

In this talk, we’ll go over basic usage like factories, singles, and modules. We’ll talk about scoping and lazy-loading modules, and we’ll look at its integration with Android screens and ViewModels. Then, and most importantly, we’ll see how we can use Koin to quickly and easily generate mocked dependencies for clean and hermetic tests.