Skip to content

Instantly share code, notes, and snippets.

View bitristan's full-sized avatar
😀
happy coding everyday

Ting Sun bitristan

😀
happy coding everyday
View GitHub Profile
@bitristan
bitristan / AppUtil.java
Created December 1, 2015 07:02
Check whether app is in background.
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.os.Build;
import java.util.List;
public class AppUtil {
private static final int KITKAT_WATCH = 20;
@bitristan
bitristan / change_package.groovy
Created January 11, 2016 05:48
Replace str in file with groovy.
import groovy.io.FileType
def source = "import android.support.wearable"
def dest = "import ticwear.support.wearable"
def dir = new File("res")
dir.eachFileRecurse (FileType.FILES) { f ->
def fileText = f.text
fileText = (fileText =~ /${source}/).replaceAll(dest)
f.write(fileText)
apply plugin: 'android'
def getVersionCode = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-list', '--first-parent', '--count', 'master'
standardOutput = stdout
}
return Integer.parseInt(stdout.toString().trim())
@bitristan
bitristan / install.sh
Created November 14, 2016 11:28
Install sourrce code pro font on ubuntu.
wget https://github.com/adobe-fonts/source-code-pro/archive/2.030R-ro/1.050R-it.zip
unzip 1.050R-it.zip
mkdir ~/.fonts
mv source-code-pro-2.030R-ro-1.050R-it/OTF/*.otf ~/.fonts/
rm -r source-code-pro-2.030R-ro-1.050R-it/ 1.050R-it.zip
fc-cache -f -v
@bitristan
bitristan / tinify.py
Created June 2, 2017 02:30
批量递归压缩指定目录下的jpg或者png文件,使用tinify库
# -*- coding: utf-8 -*-
"""
批量递归压缩指定目录下的jpg或者png文件,使用tinify库进行压缩实现。
注意:新生成的压缩文件会替换之前的源文件,请在运行脚本之前做好备份,或者使用git之类的版本管理工具将源文件加入版本仓库!
运行脚本前需确保以下库已经安装
1. pip install tinify
2. pip install click
"""
@bitristan
bitristan / screenshot_by_adb.py
Last active January 15, 2018 06:31
使用adb进行手机屏幕截图
# -*- coding: utf-8 -*-
"""
手机屏幕截图,参考 https://github.com/wangshub/wechat_jump_game
"""
import subprocess
import os
import sys
from PIL import Image
@bitristan
bitristan / ZipUtils.java
Created August 28, 2019 11:49
Use okio to zip file.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import okio.BufferedSink;
import okio.BufferedSource;
import okio.GzipSink;
import okio.Okio;
public class ZipUtil {
@bitristan
bitristan / .ideavimrc
Last active May 17, 2020 14:35
Idea vim config.
let mapleader = "," " leader is comma
let localleader = "," " leader is comma
set tabstop=4 " number of visual spaces per TAB
set softtabstop=4 " number of spaces in tab when editing
set shiftwidth=4 " spaces in newline start
set expandtab " tabs are spaces
set number " show line numbers
set rnu " show relative line numbers
set showcmd " show command in bottom bar
@bitristan
bitristan / .vimrc
Created October 30, 2019 14:33
Vim config
imap fd <Esc>
package com.leaf.library;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;