Skip to content

Instantly share code, notes, and snippets.

View wpyoga's full-sized avatar

William Poetra Yoga wpyoga

View GitHub Profile
@wpyoga
wpyoga / gist:ed239bdfcfa6c7ee446494aeb36e1b62
Created March 17, 2021 16:23
Linux virtual serial port pair connected by null modem
socat -d -d pty,raw,echo=0 pty,raw,echo=0
@wpyoga
wpyoga / gist:0ff19ff22d8a88f076a0cf7c9f6bfeb9
Last active March 17, 2021 16:26
Clear terminal emulator title
PS1='$ '
echo -e '\033]0; \007'
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0 }"
@wpyoga
wpyoga / gist:b8796d0366d5e755a56873dcf1028701
Created March 30, 2021 09:42
make a virtual ethernet connection between default ip namespace and myns namespace
ip link add name A type veth peer name B
ip addr add 10.0.0.1/24 dev A
ip link set A up
ip netns add myns
ip link set B netns myns
ip netns exec myns ip addr add 10.0.0.2/24 dev B
ip netns exec myns ip link set B up
@wpyoga
wpyoga / time_convert.c
Last active April 29, 2021 15:51
convert time string to struct tm
#define _XOPEN_SOURCE
#include <time.h>
#include <stdio.h>
// Simple-task-30036777
int main() {
char buf[] = "2021-04-28T21:29:10.279Z";
int len;
struct tm tmbuf;
char *c = NULL;
@wpyoga
wpyoga / gist:cbe7b20d1bc6e16491075c1d3168501d
Last active May 25, 2021 09:46
ffmpeg create video from single image
# image.png: image file
# video.mp4: video file
# -t 5: video duration in seconds
# -crf 20: (optional) compression, higher value higher compression rate and lower video quality
# using -crf 0 (lossless) sometimes leads to glitches, use -crf 1 for best results
# note: the order of the arguments matter
ffmpeg -loop 1 -i image.png -t 5 -crf 20 -vcodec libx264 -pix_fmt yuv420p video.mp4
@wpyoga
wpyoga / gist:a35e9e0416da7ebcffd3dfd509eb2e24
Last active May 25, 2021 07:01
Convert PNG to WebP (Lossless)
# -lossless
# create a lossless image
# you can use '-z 9' to really make a small image,
# but my tests show that it only produces around 1% better compression rate,
# with much longer compression times
#
# -resize 1080 1920
# (optional) resize the image
cwebp -lossless -resize 1080 1920 image.png -o image.webp
@wpyoga
wpyoga / gist:80581ffe82ed6d007f5c99e88e003d83
Last active February 9, 2023 14:41
FFmpeg split and concat videos
ffmpeg_concat() (
test "$#" -lt 1 && return
LISTFILE="`mktemp -p .`"
printf "file '%s'\n" "$@" > "$LISTFILE"
ffmpeg -f concat -safe 0 -i "$LISTFILE" -c copy concat.mp4
rm "$LISTFILE"
)
# to split video into multiple segments based on key frames
@wpyoga
wpyoga / gist:b984279eb717d0143e252d23adcfe535
Created May 25, 2021 07:17
ImageMagick crop then resize image
# -crop 2250x1518+0+0
# crop the image to 2250x1518
# without this, the image will be resized to
# - 800x541, if using the geometry transform
# - 799x540, if using the resize transform
#
# +repage
# reset the virtual canvas to the image size, which has been cropped
#
# -geometry 800
@wpyoga
wpyoga / gist:ad8c8cd047b1f80d7129ef217e970fcb
Created June 10, 2021 01:03
Show running processes with its command-line arguments
# Replace 'adb' with the desired process name
ps -o pid,args `pidof adb`