Skip to content

Instantly share code, notes, and snippets.

@panpf
panpf / settings.gradle.kts
Created Jun 24, 2019
gradle local module reference
View settings.gradle.kts
include(":app", ":router", ":router-annotation", ":router-compiler", ":download", ":app-installer", ":app-packages")
project(":download").projectDir = File("../download/download")
project(":app-installer").projectDir = File("../app-installer/app-installer")
project(":app-packages").projectDir = File("../app-packages/app-packages")
@panpf
panpf / gist:564a2ea910e3f5afb43f7075ac1c6218
Created May 10, 2019
shell 转义字符串中的双引号
View gist:564a2ea910e3f5afb43f7075ac1c6218
originParams='"hello world"'
originParamsFormatted=`echo ${originParams//'"'/'\"'}` # 输出结果 \"hello world\"
@panpf
panpf / monitor
Last active May 10, 2019
shell 写一个监控脚本,可执行任意命令,命令执行失败退出码非 0 发送报警邮件
View monitor
#!/bin/bash
# 如果需要监控指定命令的执行结果,失败时自动发邮件,就只需在最前面用此命令执行即可,例如 monitor echo "hello world"
# 得到当前脚本文件所在的绝对路径
basePath=$(cd `dirname $0`; pwd)
# 执行并记录状态码
# 如果原本参数里有双引号或单引号的话,直接执行 '$@',会失败
# 用 echo "$@" 打印后看不到原本的双引号或单引号,例如 hive -e "select * from test" 就会变成 hive -e select * from test
@panpf
panpf / gist:c11a91b3b996e9c18b0a242e52bdc9c3
Created May 10, 2019
shell 获取当前脚本文件所在的绝对路径
View gist:c11a91b3b996e9c18b0a242e52bdc9c3
basePath=$(cd `dirname $0`; pwd)
View gist:eb32175e1a1fb94276037a2cabaf2da1
startTimeFormatted=`date '+%Y-%m-%d %a %H:%M:%S'`
@panpf
panpf / gist:652fab17869b6c332f2b7cdcc3bed968
Created May 9, 2019
shell 获取当前时间戳(精确到毫秒)代码
View gist:652fab17869b6c332f2b7cdcc3bed968
startTime=$[$(date +%s%N)/1000000]
@panpf
panpf / time_format.sh
Created May 9, 2019
shell 时间差(用时)格式化代码
View time_format.sh
usedTimeHourFormatted="`awk 'BEGIN{printf "%.1f\n",('${endTime}'-'${startTime}')/'3600000'}'`小时"
@panpf
panpf / ActivityEventRegistrar.kt
Created Aug 1, 2018
EventBus 事件注册器
View ActivityEventRegistrar.kt
package me.panpf.event
import android.annotation.TargetApi
import android.app.Activity
import android.app.Application
import android.os.Build
import android.os.Bundle
import android.support.annotation.RequiresApi
import android.support.v4.app.FragmentActivity
import android.view.View
@panpf
panpf / ArgsBinder.kt
Last active Jun 14, 2018
Android 参数注入 kotlin 扩展
View ArgsBinder.kt
@file:Suppress("unused")
package me.panpf.args.ktx
import android.app.Activity
import android.os.Build
import android.os.Bundle
import android.os.IBinder
import android.os.Parcelable
import android.support.annotation.RequiresApi
@panpf
panpf / ViewModelBinder.kt
Last active Jun 9, 2018
Android arch ViewModel kotlin bind
View ViewModelBinder.kt
@file:Suppress("RedundantVisibilityModifier")
package me.panpf.arch.ktx
import android.arch.lifecycle.ViewModel
import android.arch.lifecycle.ViewModelProviders
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentActivity
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KClass