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")
@justdoit0823
justdoit0823 / netcat_examples.md
Last active April 15, 2023 20:23
A collection of examples about using netcat.

Netcat Examples

Establish TCP Connection

  • Connect to network host over TCP connection
@justdoit0823
justdoit0823 / sqlalchemy_session.py
Last active January 25, 2023 15:50
A simple sqlalchemy session decorator and context manager for db operation function.
session_engines = {}
def get_new_session(connection=None, autocommit=None):
connection = connection or 'default'
connection_settings = settings.DATABASES[connection]
connection_autocommit = ValueUtils.none_or(
connection_settings.get('autocommit'), False)
autocommit = ValueUtils.none_or(autocommit, connection_autocommit)
#!/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"
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"
pid="${array[0]}"
@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 / 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'