Skip to content

Instantly share code, notes, and snippets.

@Hackforid
Hackforid / get_deps.gradle
Created January 5, 2023 13:08
获取模块的依赖
task runGetDeps() {
doLast {
project.getConfigurations().each { configuration ->
// println("conf $configuration.name")
if (configuration.name == "debugCompileClasspath" && configuration.canBeResolved) {
println("conf $configuration.name")
configuration.incoming.resolutionResult.getAllDependencies().each { dep ->
println("dep => $dep")
}
}
@Hackforid
Hackforid / Kotlin
Created August 19, 2019 07:25
ButterKnife-Reflection
import org.gradle.api.Plugin
import org.gradle.api.Project
class ButterKnifePlugin: Plugin<Project> {
private val KAPT_NAME = "kapt"
private val APT_NAME = "annotationProcessor"
private val KOTLIN_KAPT_PLUGIN_ID = "org.jetbrains.kotlin.kapt"
private val BUTTER_KNIFE_PLUGIN_ID = "com.jakewharton.butterknife"
@Hackforid
Hackforid / FrescoHttpDNSInterceptor.kt
Created August 10, 2018 06:44
Fresco HTTP DNS Interceptor
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException
/**
* Fresco无法直接设置request的header来传递Hostname
* 通过提供Interceptor来添加和video相同的httpdns支持
* 同时图片下载的成功与否也会用来对host进行评分
@Hackforid
Hackforid / java
Created November 23, 2017 11:32
ua
builder.header("X-AppEngine-Country", DeviceUtils.getCountryISO())
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.header("User-Agent", SMAuthUtilsProxy.getUserAgent() + ConnectionManager.getConnectType())
.header("app-language", DeviceUtils.getLanguageCodeWithCountry())
.header("locale", DeviceUtils.getLanguageCodeWithCountry())
.header("country", DeviceUtils.getCountryISO())
.header("cpu-abi", SystemUtils.getMostPreferredABI())
.header("unique-key", getUniqueKey());
@Hackforid
Hackforid / ProcessName.java
Created November 15, 2017 15:59
[Android] Get Process Name
// High performance
public static String getProcessName() {
try {
File file = new File("/proc/" + android.os.Process.myPid() + "/" + "cmdline");
BufferedReader mBufferedReader = new BufferedReader(new FileReader(file));
String processName = mBufferedReader.readLine().trim();
mBufferedReader.close();
return processName;
} catch (Exception e) {
e.printStackTrace();
@Hackforid
Hackforid / deeplink.html
Created September 22, 2017 02:47
Deeplink兼容实现
Analysic Version 6.1.3
Total: 67931 Fail: 10008(14.73%) Multi Fail: 439(0.65%)
createRecord failed: 687 (6.86%, 1.01%)
Good 0 0.00%
Normal 0 0.00%
Poor 0 0.00%
None 0 0.00%
compose Error: 1508 (15.07%, 2.22%)
Good 0 0.00%
@Hackforid
Hackforid / CompatCollapsingToolbarLayout.java
Created March 30, 2017 13:04
CompatCollapsingToolbarLayout
public class CompatCollapsingToolbarLayout extends CollapsingToolbarLayout {
private boolean mLayoutReady;
public CompatCollapsingToolbarLayout(Context context) {
this(context, null);
}
public CompatCollapsingToolbarLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@Hackforid
Hackforid / gist:b6662052db1bf8a7446b780a6aee5e7b
Created August 22, 2016 03:45 — forked from dalethedeveloper/gist:1503252
Mobile Device Detection via User Agent RegEx

#Mobile Device Detection via User Agent RegEx

Yes, it is nearly 2012 and this exercise has been done to death in every imaginable language. For my own purposes I needed to get the majority of non-desktop devices on to a trimmed down, mobile optimized version of a site. I decided to try and chase down an up-to-date RegEx of the simplest thing that could possibly work.

I arrived at my current solution after analyzing 12 months of traffic over 30+ US based entertainment properties (5.8M+ visitors) from Jan - Dec 2011.

The numbers solidified my thoughts on the irrelevancy of including browsers/OSes such as Nokia, Samsung, Maemo, Symbian, Ipaq, Avant, Zino, Bolt, Iris, etc. The brass tacks of the matter is that you certainly could support these obscure beasts, but are you really going to test your site on them? Heck, could you even find one?! Unless the folks that pay you are die hard Treo users my guess is "No".

Interestingly enough my research shows that /Mobile/ is more efficient than **/iP(

@Hackforid
Hackforid / WidgetUtils.kt
Created August 15, 2016 14:37
Google Support Lib那些坑
/**
* 解决Snackbar只能使用RootView的问题 防止Fragment切换后Snackbar依旧显示
*/
fun makeSnackbar(parent: ViewParent, text: CharSequence, duration: Int) : Snackbar {
val constructor = Snackbar::class.java.getDeclaredConstructor(ViewGroup::class.java)
constructor.isAccessible = true
val snackbar = constructor.newInstance(parent)
snackbar.setText(text)
snackbar.duration = duration
return snackbar