Skip to content

Instantly share code, notes, and snippets.

View fangzhzh's full-sized avatar
🎯
Focusing

zhangzhenfang fangzhzh

🎯
Focusing
View GitHub Profile
@fangzhzh
fangzhzh / d3.js_draw_line_chart
Created March 25, 2014 04:11
d3.js 绘制线图
var svg = d3.select("d3_chart");
var data = [4, 8, 15, 16, 23, 42];
var width = 420, barHeight = 20;
var svg = d3.select("d3_chart").append("svg:svg")
.attr("width", width)
.attr("height", barHeight);
@fangzhzh
fangzhzh / d3-piechart-legend
Created March 27, 2014 03:23
d3.js 绘制饼图+说明
var w = 400,
h = 400,
r = 180,
inner = 70,
color = d3.scale.category20c();
data = [{"label":"ONE", "value":194},
{"label":"TWO", "value":567},
{"label":"THREE", "value":1314},
{"label":"FOUR", "value":793},
@fangzhzh
fangzhzh / log
Last active August 29, 2015 14:26 — forked from zhuomingliang/log
Git
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %Cblue<%an>%Creset' --abbrev-commit --date=relative
@fangzhzh
fangzhzh / setupvim.sh
Created November 26, 2015 14:53
setup vim for new environment
cd ~
git clone git@github.com:fangzhzh/.vim.git
ln -s ~/.vim/.vimrc ~/.vimrc
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
vim +PluginInstall +qall
d ~/.vim/bundle/YouCompleteMe && ./install.py --clang-completer
0 1 * * * curl https://gist.githubusercontent.com/fangzhzh/7f9ed840948e81b7fc76/raw/30f2bf8dc7606ed6d8746ec8db745fb57f42c7c5/journal_with_remind.py | python
0 1 * * 1 curl https://gist.githubusercontent.com/fangzhzh/7f9ed840948e81b7fc76/raw/30f2bf8dc7606ed6d8746ec8db745fb57f42c7c5/journal_with_remind.py | python /dev/stdin week
0 1 1 * * curl https://gist.githubusercontent.com/fangzhzh/7f9ed840948e81b7fc76/raw/30f2bf8dc7606ed6d8746ec8db745fb57f42c7c5/journal_with_remind.py | python /dev/stdin month
@fangzhzh
fangzhzh / simple_args_parsing.sh
Created November 27, 2015 08:54 — forked from jehiah/simple_args_parsing.sh
a simple way to parse shell script arguments
#!/bin/sh
#
# a simple way to parse shell script arguments
#
# please edit and use to your hearts content
#
ENVIRONMENT="dev"
@fangzhzh
fangzhzh / bitmap_overlay.java
Last active July 28, 2016 11:49
android, java, draw two bitmaps with Picasso.
Picasso.with(getContext())
.load(CONST.IMAGE_SERVER + cover.image_url)
.into(new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
Bitmap bmOverlay = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
Bitmap play= BBAppResource.bitmap(R.drawable.btn_me_account);
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bitmap, new Matrix(), null);
float left = (float)((bitmap.getWidth()-play.getWidth())/2.0);
@fangzhzh
fangzhzh / gradle_task_grant_permission
Last active October 3, 2017 06:46
gradle task to grant permission to device
android.applicationVariants.all { variant ->
def applicationId = variant.applicationId
def adb = androidadbExe. as String
def variantName = variant.name.capitalize()
def grantPermissionTask = task.create("create${variantName}Permissions") << {
"${adb} devices".execute().text.eachLine {
if(it.endsWith("device")){
def device = it.split()[0]
println "Granting permissions on devices ${device}"
"${adb} -s ${devices} shell pm grant ${applicationId} android.permission.ACCESS_FINE_LOCATION".execute()
@fangzhzh
fangzhzh / readFileNWait.java
Last active July 21, 2016 02:36
Java read and wait file, BufferedReader, also ffmpeg progress calculation, try catch, finally, FileReader
BufferedReader br = null;
try {
br = new BufferedReader(
new FileReader(output.getAbsolutePath() + ".log"));
String line;
double totalSecs = 0;
double totalFps = 0;
while (keepReading) {
line = br.readLine();
if (line == null) {
@fangzhzh
fangzhzh / ffmpeg.logcat
Last active July 21, 2016 03:37
ffmpeg compressing log file
ffmpeg started on 2016-07-20 at 23:25:03
Report written to "/storage/emulated/0/Android/data/com.garena.videodemo/cache/comp_VID_20160703_172409.mp4.log"
Command line:
ffmpeg -y -i /storage/emulated/0/Download/VID_20160703_172409.mp4 -crf 33 -preset ultrafast -loglevel trace /storage/emulated/0/Android/data/com.garena.videodemo/cache/comp_VID_20160703_172409.mp4
ffmpeg version 3.0.1 Copyright (c) 2000-2016 the FFmpeg developers
built with gcc 4.9 (GCC) 20140827 (prerelease)
configuration: --target-os=linux --arch=x86 --cpu=i686 --enable-yasm --enable-cross-compile --cross-prefix=i686-linux-android- --prefix=/Users/zhangzf/android/libs/gcodec/external/build/x86 --sysroot=/Users/zhangzf/android/libs/gcodec/external/build/x86/toolchain/sysroot --enable-small --enable-static --disable-shared --enable-pic --enable-asm --enable-inline-asm --enable-gpl --enable-libx264 --disable-doc --disable-symver --disable-gray --disable-swscale-alpha --disable-hwaccels --disable-iconv --disable-programs --disable-ffmpeg --d