Skip to content

Instantly share code, notes, and snippets.

View fangzhzh's full-sized avatar
🎯
Focusing

zhangzhenfang fangzhzh

🎯
Focusing
View GitHub Profile
```javascript
export const useApi = (apiRequest, initialData, depend) => {
// const [url, setUrl] = useState(initialUrl);
const [isLoading, setIsLoading] = useState(true);
const [hasError, setHasError] = useState(false);
const [errorCode, setErrorCode] = useState(200);
const [errorMessage, setErrorMessage] = useState("");
const [fetchedData, setFetchedData] = useState(initialData);
useEffect(() => {
@fangzhzh
fangzhzh / gist:9299957f84dab8afe18f0a919455dda8
Created October 3, 2019 21:31
放诸古今皆准的权力规则
  (《东方早报·上海书评》,2013年3月10日)
  十九世纪末的比利时国王利奥波德二世完全有理由成为一些人心中的偶像。他大力推动民主自由,在四十多年的任期内,把比利时从一个专制独裁国家成功变成了一个现代民主国家。他赋予每个成年男子选举权,甚至比美国提前半个世纪立法允许工人罢工。他对妇女儿童的保护领先于整个欧洲。比利时1881年就普及了基础教育,确保每个女孩都能上到初中,并且在1889年通过法律禁止十二岁以下儿童工作。在利奥波德二世治下,国家的经济像政治一样获得了大发展,他比罗斯福更早采取建设公路和铁路基础设施的手段来减少失业和刺激经济。
  然而在非洲刚果这个比利时殖民地,确切的说是利奥波德二世本人的殖民地,他完全是另外一个形象。刚果人,包括妇女儿童,在奥波德二世的统治下没有任何人权,完全是奴隶。他们在警察部队的强制下劳动,动辄被施以断手之类的酷刑,有超过一千万人被迫害致死,而这一切都是为了保证利奥波德二世在橡胶贸易中获得巨额利润。
  为什么同样一个人可以在一个国家推行民主却在另一个国家施行最残暴的独裁?有人可能立即会说这是制度问题。但“制度”在这里与其说是答案还不如说是问题本身。为什么比利时的制度越来越民主,而同一时期,同一领导人的刚果,却越来越独裁?难道是因为利奥波德二世只爱本国人或者有种族歧视?但后来刚果自己“选”出来的领导人并没有做得更好,仍然是一个糟糕的独裁者。在The Predictioneer’s Game(《预测师的博弈论》)这本书里,斯坦福大学胡佛研究所和纽约大学的政治学教授Bruce Bueno de Mesquita指出,真正原因是在刚果,利奥波德二世只需要让少数人高兴就足以维持自己的统治;而在比利时,他必须让很多人满意才行。我认为这个答案跟“制度论”的区别在于必须让多少人满意,这个人数不是制度“规定”出来的,而是实力的体现。
  Bueno de Mesquita和合作者研究多年,得出了一个能够相当完美地解释很多政治现象的理论。这个理论认为不管是国家、公司还是国际组织,其政治格局不能简单地以“民主”和“独裁”来划分,而必须用三个数字来描写。以国家为例,这个“三围”就是层层嵌套的三种人的人数:

flow from android developer

`Long running HTTP download?`
❓️
⬇️✅️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️️➡️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️➡️️️️➡️ DownloadManager
❎
⬇️
⬇️➡️
`Deferrable Work?`
@fangzhzh
fangzhzh / jacocoConfig.gradle
Last active September 10, 2019 09:00
create jacoco related tasks for Android app
// https://engineering.rallyhealth.com/android/code-coverage/testing/2018/06/04/android-code-coverage.html
ext.enableJacoco = { Project project, String variant ->
project.plugins.apply('jacoco')
final capVariant = variant.capitalize()
StringBuilder folderSb = new StringBuilder(variant.length() + 1)
for (int i = 0; i < variant.length(); i++) {
char c = variant.charAt(i)
@fangzhzh
fangzhzh / observable-extension.txt
Created June 5, 2018 22:18 — forked from halcyonmobiledev/observable-extension.txt
Data Binding observables and Kotlin
// with just a simple extension function for the Data Binding ObservableField
inline fun <R> ObservableField<R>.observe(crossinline callback: (R) -> Unit) {
this.addOnPropertyChangedCallback(object : Observable.OnPropertyChangedCallback() {
override fun onPropertyChanged(p0: Observable?, p1: Int) {
callback(get())
}
})
}
...
@fangzhzh
fangzhzh / sum6.kt
Created September 27, 2017 20:36
check sum 6
fun checkToSix() {
val list = ArrayList<String>()
// val src = listOf(2,2,2)
(2..9)
.map {
System.out.println(it)
listOf(it, it, it)
}
.forEach {
list.clear()
@fangzhzh
fangzhzh / introrx.md
Created August 31, 2016 01:18 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@fangzhzh
fangzhzh / ffmpeg.logcat
Last active July 21, 2016 03:37
ffmpeg compressing log file
ffmpeg started on 2016-07-20 at 23:25:03
Report written to "/storage/emulated/0/Android/data/com.garena.videodemo/cache/comp_VID_20160703_172409.mp4.log"
Command line:
ffmpeg -y -i /storage/emulated/0/Download/VID_20160703_172409.mp4 -crf 33 -preset ultrafast -loglevel trace /storage/emulated/0/Android/data/com.garena.videodemo/cache/comp_VID_20160703_172409.mp4
ffmpeg version 3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.9 (GCC) 20140827 (prerelease)
configuration: --target-os=linux --arch=x86 --cpu=i686 --enable-yasm --enable-cross-compile --cross-prefix=i686-linux-android- --prefix=/Users/zhangzf/android/libs/gcodec/external/build/x86 --sysroot=/Users/zhangzf/android/libs/gcodec/external/build/x86/toolchain/sysroot --enable-small --enable-static --disable-shared --enable-pic --enable-asm --enable-inline-asm --enable-gpl --enable-libx264 --disable-doc --disable-symver --disable-gray --disable-swscale-alpha --disable-hwaccels --disable-iconv --disable-programs --disable-ffmpeg --d
@fangzhzh
fangzhzh / readFileNWait.java
Last active July 21, 2016 02:36
Java read and wait file, BufferedReader, also ffmpeg progress calculation, try catch, finally, FileReader
BufferedReader br = null;
try {
br = new BufferedReader(
new FileReader(output.getAbsolutePath() + ".log"));
String line;
double totalSecs = 0;
double totalFps = 0;
while (keepReading) {
line = br.readLine();
if (line == null) {
@fangzhzh
fangzhzh / gradle_task_grant_permission
Last active October 3, 2017 06:46
gradle task to grant permission to device
android.applicationVariants.all { variant ->
def applicationId = variant.applicationId
def adb = androidadbExe. as String
def variantName = variant.name.capitalize()
def grantPermissionTask = task.create("create${variantName}Permissions") << {
"${adb} devices".execute().text.eachLine {
if(it.endsWith("device")){
def device = it.split()[0]
println "Granting permissions on devices ${device}"
"${adb} -s ${devices} shell pm grant ${applicationId} android.permission.ACCESS_FINE_LOCATION".execute()