Few little scripts
19 Dec, 2021
Just a few little scripts I have that help me with everyday life.
dev server
npx parcel pubilc/index.html
No config file required and the app automatically updates in the browser without refreshing the page.
deployment
rsync -a --stats -e "ssh -i /path/to/rsa_key" public/* user@host:/var/www/project
Sync a local directory with the remote server by making a recursive copy with respect to symlinks. Works great with static web sites.
download video description
yt-dlp -o "%(title)s--%(id)s--%(upload_date)s" \
--playlist-start 1 \
--playlist-end 5 \
--write-description \
--skip-download \
https://www.youtube.com/playlist?list=PLtHtm5qCHV23Z7HVycqXBwKS8Y-jZ2d4S
Go through the last five episodes in a playlist and download their video description.
I run this script in a crontab job everyday to keep the list of podcast episodes on a website in sync with the original youtube channel.
crontab -e
00 12 * * * sh /buharog.live/download
10 12 * * * sh /buharog.live/release
By the way, I switched from youtube-dl
to yt-dlp
as it's actively maintained and less buggy.
download audio file
yt-dlp -f 'ba' -x --audio-format mp3 https://www.youtube.com/watch?v=Vnpp5NRi1Dg
or
yt-dlp -x https://www.youtube.com/watch?v=Vnpp5NRi1Dg
ffmpeg -i file.ogg file.mp3
30ms of silence
ffmpeg -i -acodec copy $1 -af "adelay=30ms:all=true" out.mp3
remove duplicates in mongodb collection
var ids = [];
db.collection.aggregate([
{
$group: {
// group entries by "foo" attribute
_id: { foo "$foo" },
dups: { "$addToSet": "$_id" },
count: { "$sum": 1 }
}
}, {
// entries with same "foo" attribute values are duplicates
$match: { count: { "$gt": 1 } }
}
], {
allowDiskUse: true
}).forEach(function (doc) {
doc.dups.shift();
doc.dups.forEach(function (dupId) {
ids.push(dupId);
})
})
printjson(duplicatesIds);
db.feed.remove({ _id:{$in:ids} });
two github users on one machine
# ~/.ssh/config
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
Host github.com-woopwoop
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_woopwoop
IdentitiesOnly yes
# ~/woopwoop/re/po/.git/config
[remote "origin"]
url = git@github.com-woopwoop:re/po.git
fetch = +refs/heads/*:refs/remotes/origin/*
Note woopwoop
suffix — that's your second github user.