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 / 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 / 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 / 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 / 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
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 / 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)
@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 / CompressUtil.java
Created October 29, 2015 15:28
compress util
package com.zc.logger.util;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@bitristan
bitristan / RecycleBitmap.java
Created October 16, 2015 08:58
Recycle ImageView Bitmap
//Recycle src of ImageView
private static void recycleImageViewBitMap(ImageView imageView) {
if (imageView != null) {
BitmapDrawable bd = (BitmapDrawable) imageView.getDrawable();
rceycleBitmapDrawable(bd);
}
}
private static void rceycleBitmapDrawable(BitmapDrawable bitmapDrawable) {
if (bitmapDrawable != null) {
@bitristan
bitristan / GetCurrentProcessName.java
Created September 7, 2015 08:42
Get current process name.
private String getCurrentProcessName() {
String processName = "";
int pid = android.os.Process.myPid();
ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
for (ActivityManager.RunningAppProcessInfo processInfo : manager.getRunningAppProcesses()) {
if (processInfo.pid == pid) {
processName = processInfo.processName;
break;
}
}