Skip to content

Instantly share code, notes, and snippets.

View vdakalov's full-sized avatar

Viktor vdakalov

View GitHub Profile
@vdakalov
vdakalov / video_cutter.sh
Last active February 1, 2023 16:45
Find all video of the series, trim splash screen for each of them, keep and reorder two audio streams and make first by default
#!/usr/bin/env bash
source="/home/user/source"
target="/home/user/target"
find "$source" -type f -name "*.mkv" -print0 | while read -d $'\0' f; do
name=$(basename "$f" .mkv)
echo "$name"
ss=$(ffprobe -i "$f" 2>&1 | grep "Chapter #0:1" | grep -Eo "[0-9.]+" | head -3 | tail +3)
@vdakalov
vdakalov / tiktok-dl.sh
Last active January 22, 2022 06:32
Download tiktok video in bash
#!/bin/bash
videoPageUrl=$1 # first argument must has page url
# request html page with gzip encoding only! coz it can be Brotli encoding
html=$(curl \
-H "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" \
-H "accept-encoding: gzip" \
-H "accept-language: en-US,en;q=0.9,ru;q=0.8" \
-H "cache-control: max-age=0" \
@vdakalov
vdakalov / node-repl
Created November 30, 2018 11:31
REPL Terminal for Node.js
#!/bin/bash
getUid() {
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1
}
. "$HOME/.bashrc"
if [ -z "$NVM_DIR" ]; then
if [ -d "$HOME/.nvm" ] && [ -f "$HOME/.nvm/nvm.sh" ]; then
@vdakalov
vdakalov / sort.txt
Created October 24, 2018 02:24
ASC и DESC
ASC | DESC
1 | 3
2 | 2
3 | 1
@vdakalov
vdakalov / flush.sh
Created September 12, 2018 08:18
Flush linux memory and swop
#!/bin/bash
# Flush the file system buffer
sync
# Clear PageCache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches
# Restart swap
swapoff -av && swapon -av
@vdakalov
vdakalov / index.sh
Created September 5, 2018 03:59
Retrieve ssl certificate from website
# @see https://serverfault.com/questions/129503/save-remote-ssl-certificate-via-linux-command-line
sudo bash -c "openssl s_client -servername remote.server.net -connect remote.server.net:443 </dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /usr/local/share/ca-certificates/my-cert.crt"
# @see https://thomas-leister.de/en/how-to-import-ca-root-certificate/
sudo update-ca-certificates
@vdakalov
vdakalov / index.js
Created July 24, 2018 13:31
Разбивка числа по порядкам с помощью регулярного выражения
// еле вспомнил, так что положу тут, что бы не забыть!
1e8.toString().replace(/(\d{1,3})(?=(\d{3})+$)/g, '$1 '); // "100 000 000"
@vdakalov
vdakalov / mem.complete.sh
Last active June 1, 2018 14:18
Return total memory usage of processes by name
#!/bin/bash
###
# Save as /etc/bash_completion.d/mem.complete.sh
##
_complete_mem() {
commands=`ps --no-headers -e -o command | grep -Eo "^[a-zA-Z0-9_\.\-\/]+" | { while read line; do basename $line; done; } | sort -u`
current="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${commands}" "${current}") )
@vdakalov
vdakalov / bigint.js
Created December 19, 2017 05:30
Алгоритм вычитания очень больших чисел на JavaScript
#!/usr/bin/env node
function sub(a, b) {
let prefix = '0'.repeat(Math.abs(a.length - b.length));
let flip = false;
if (prefix.length) {
if (a.length > b.length) {
b = `${prefix}${b}`;
} else if (b.length > a.length) {
@vdakalov
vdakalov / circle.sh
Created April 3, 2017 15:36
Цикличное выполнение команды
#!/usr/bin/env bash
command_timeout=$1
command_line=$2
command_next=$3
timeout="${command_timeout}"
logname="/tmp/run.$(date +%Y%m%d%H%M%S).log"
function hasNext {