Skip to content

Instantly share code, notes, and snippets.

View justdoit0823's full-sized avatar

余森彬 justdoit0823

View GitHub Profile
@justdoit0823
justdoit0823 / llama2_py_code_ui.py
Created August 28, 2023 15:41
Llama2 python code completion web ui
from threading import Event, Thread
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer, GenerationConfig
model_name = "codellama/CodeLlama-7b-Python-hf"
@justdoit0823
justdoit0823 / ffmpeg_examples.sh
Last active August 13, 2023 15:14
ffmpeg video and audio transformation examples.
# make video with pictures
ffmpeg.exe -framerate 0.375 -i .\photos\%d.png -i .\audio_3886dab2976147ad8046875a45f5b8cc.wav -c:v libx264 -pix_fmt yuv420p -c:a aac -strict experimental -b:a 192k output-1.mp4
# extract audio from video
ffmpeg.exe -i input.mp4 -vn -acodec copy output.aac
# audio aac to mp3
ffmpeg.exe -i output1.aac -c:a libmp3lame -ar 16000 -q:a 2 output1.mp3
@justdoit0823
justdoit0823 / translation_demo.py
Created July 15, 2023 16:00
A simple translation demo for chinese to english with gradio.
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Setup the gradio Demo.
import gradio as gr
tokenizer = AutoTokenizer.from_pretrained("Helsinki-NLP/opus-mt-zh-en")
model = AutoModelForSeq2SeqLM.from_pretrained("Helsinki-NLP/opus-mt-zh-en")
#!/bin/bash
function show_haproxy_socket_info(){
ret=$(ss -tnlp|grep haproxy)
echo $ret
pstr=$(echo $ret | awk -F'\t' '{split($NF, a, ","); split(a[2], b, "="); split(a[3], c, "="); split(c[2], d, ")"); print b[2], d[1]}')
IFS=' '
read -r -a array <<< "$pstr"
#!/bin/bash
RES=$(find ~/Documents/collections|awk -F'@@@' '{a=a"@@@"$1;} END {print a;}')
echo $RES
IFS='@@@' read -ra DATA <<< "$RES"
@justdoit0823
justdoit0823 / stat_g1_eden_heap_size.awk
Created January 15, 2021 15:33
Stat g1 eden heap size after gc in jvm8 with awk.
awk '/Eden:/ {split($2, a, ")"); split(a[2], b, "("); print substr(b[2], 1, length(b[2])-1)}' gc.log
@justdoit0823
justdoit0823 / stat_g1_gc_interval_in_jvm8.awk
Last active March 20, 2021 14:34
Stat g1 gc interval in jvm 8 with awk.
# pipe
awk '/GC pause/ {split($2, a, ":"); print a[1]}'|awk 'NR % 2 == 1 {t1 = $1}; NR % 2 == 0 {d = $1 - t1; print d; next}'
# gc log file
awk '/GC pause/ {split($2, a, ":"); print a[1]}' gc.log|awk 'NR % 2 == 1 {t1 = $1}; NR % 2 == 0 {d = $1 - t1; print d; next}'
@justdoit0823
justdoit0823 / summary_stat.awk
Last active January 24, 2021 14:21
Simple summary stat with awk.
// min, mean, max, p50, p90, p99, p999
sort -k1 -n|awk '{s[NR]=$1} END {print "min:"s[1], "mean:"s[int(NR * 0.5)], "p90:"s[int(NR * 0.9)], "p95:"s[int(NR * 0.95)], "p99:"s[int(NR * 0.99)], "p999:"s[int(NR * 0.999)], "max:"s[NR]}'
@justdoit0823
justdoit0823 / stat_g1_jni_stall_in_jvm8.awk
Last active January 26, 2021 15:09
Stat g1 jni stall in jvm 8 with awk.
// jni stall
awk '/Setting _needs_gc/ || /is performing GC after exiting critical section/ {split($1, a, ":"); if($0 ~ /Setting _needs_gc/) {print "b", a[1];} else {print "e", a[1];}}' gc.log|awk '{if($1 == "b") {t1 = $2; next} if(t1 != 0) {d = $2 - t1; t1 = 0; print d; next}}'
// safepoint synchronization stall
grep 'GCLocker Initiated GC' -B 1 gc.log |grep -v '\-\-'|grep -v Times|awk 'NR % 2 == 1 {split($1, a, ":"); t1 = a[1]; cs=1; if ($0 ~ /GCLocker Initiated GC/) {cs=0}}; NR % 2 == 0 {split($2, a, ":"); t2 = a[1]; if(cs == 1) {duration = t2 - t1} else {duration = 0}; print duration; next}'|awk '$1 > 0'
@justdoit0823
justdoit0823 / stat_g1_allocation_rate_in_jvm8.awk
Last active January 4, 2021 06:58
Stat g1 allocation rate in jvm 8 with awk.
awk '/GC pause/ || /Heap:/ {if($0 ~ /GC pause/) {split($2, a, ":"); print a[1];} else {print $NF}}' gc.log|awk 'NR % 4 == 1 {s1 = $0}; NR % 4 == 2 {split($NF, a, "("); split(a[2], b, "->"); h1 = substr(b[2], 1, length(b[2]) -1); if(b[2] ~ /G$/) {h1 = h1 * 1024}}; NR % 4 == 3 {s2 = $0}; NR % 4 == 0 {split($NF, a, "("); h2 = substr(a[1], 1, length(a[1]) -1); if(a[1] ~ /G$/) {h2 = h2 * 1024}; duration = s2 - s1; heap = h2 - h1; print s2, duration, heap / duration; next}'