Skip to content

Instantly share code, notes, and snippets.

@zhgqthomas
zhgqthomas / DelegatesExt.kt
Last active August 10, 2018 22:05
SharedPreference Delegate extension (Kotlin)
object DelegatesExt {
fun <T : Any> preference(context: Context, name: String, default: T)
= Preference(context, name, default)
}
class Preference<T>(val context: Context, val name: String,
val default: T) : ReadWriteProperty<Any?, T> {
companion object {
val PREF_NAME: String = "chameleon"
@zhgqthomas
zhgqthomas / ButterKnife.kt
Last active March 29, 2016 03:32
ButterKnife (Kotlin)
package butterknife
import android.app.Activity
import android.app.Dialog
import android.app.Fragment
import android.support.v7.widget.RecyclerView.ViewHolder
import android.view.View
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
import android.support.v4.app.Fragment as SupportFragment
@zhgqthomas
zhgqthomas / shadow.xml
Created March 31, 2016 03:16
shadow shape for android develop
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="90"
android:endColor="#40000000"
android:startColor="@android:color/transparent" />
</shape>
/******************************************************************************
* Copyright (c) 2011 GitHub Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Kevin Sawicki (GitHub Inc.) - initial API and implementation
*****************************************************************************/
#!/bin/bash
#FileName get-android.sh
PATH=./bin:$PATH
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-5.1.1_r38
repo sync
while [ $? = 1 ]; do
echo "============ sync failed, re-sync again ==============="
sleep 3
repo sync
done
@zhgqthomas
zhgqthomas / LogUtils.java
Last active June 15, 2017 03:16
Log util for Android
package com.zhgqthomas.rxjava.util;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.util.Log;
public class LogUtils {
private static String LOG_PREFIX = "github_";
@zhgqthomas
zhgqthomas / autodraw-cloud.js
Last active June 30, 2017 15:07
Auto Draw 小程序版 LeanCloud 代理脚本
const https = require('https');
AV.Cloud.define('stencils', function (request, response) {
const options = {
hostname: 'www.autodraw.com',
path: '/assets/stencils.json',
port: 443,
method: 'GET',
headers: {
@zhgqthomas
zhgqthomas / private.xml
Created September 5, 2017 05:00 — forked from KeeperPat/private.xml
Karabiner Configuration to Remap Surface Ergonomic Keyboard Alt and Windows Keys for Mac
<?xml version="1.0"?>
<root>
<devicevendordef>
<vendorname>Microsoft</vendorname>
<vendorid>0x045e</vendorid>
</devicevendordef>
<deviceproductdef>
<productname>SurfaceErgonomic</productname>
<productid>0x0817</productid>
@zhgqthomas
zhgqthomas / ShakeDetector.java
Created October 18, 2017 02:16
Shake algorithm from react native
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.common;
@zhgqthomas
zhgqthomas / htmldecode.js
Created December 8, 2017 07:35
decode HTML Entity
function htmlDecode(str) {
// 有 x 则表示是16进制,$1 就是匹配是否有 x,$2 就是匹配出的第二个括号捕获到的内容,将 $2 以对应进制表示转换
str = str.replace(/&#(x)?(\w+);/g, function($, $1, $2) {
return String.fromCharCode(parseInt($2, $1? 16: 10));
});
return str;
}