Skip to content

Instantly share code, notes, and snippets.

@BharatKalluri
Last active February 5, 2022 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BharatKalluri/a117542eb3aba1950325e2962b13a9b3 to your computer and use it in GitHub Desktop.
Save BharatKalluri/a117542eb3aba1950325e2962b13a9b3 to your computer and use it in GitHub Desktop.
Snippets on medium
# .profile
# Mute spotify on ad
while sleep 1; do mute_ad_spotify; done &
mute_ad_spotify() {
MEDIA_TITLE=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata 2>/dev/null | sed -n '/title/{n;p}' | cut -d '"' -f 2)
if [[ $MEDIA_TITLE = "Advertisement" ]]; then
amixer -q -D pulse sset Master mute
else
amixer -q -D pulse sset Master unmute
fi
}
# Mutes audio if spotify ad is playing
mute_ad_spotify() {
SPOTIFY_SINK_ID=$(pacmd list-sink-inputs | tr '\n' '\r' | perl -pe 's/ *index: ([0-9]+).+?application\.name = "([^\r]+)"\r.+?(?=index:|$)/\2:\1\r/g' | tr '\r' '\n' | grep spotify | cut -d ":" -f 2)
if [ ! -z "$SPOTIFY_SINK_ID" ]; then
MEDIA_TITLE=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata 2>/dev/null | sed -n '/title/{n;p}' | cut -d '"' -f 2)
IS_SPOTIFY_AD=0
[[ $MEDIA_TITLE == *Advertisement* ]] && IS_SPOTIFY_AD=1
if [[ $IS_SPOTIFY_AD == 1 ]]; then
pactl set-sink-input-mute ${SPOTIFY_SINK_ID} 1
elif [[ $IS_SPOTIFY_AD == 0 ]]; then
pactl set-sink-input-mute ${SPOTIFY_SINK_ID} 0
fi
fi
}
# Mutes audio if spotify ad is playing
mute_ad_spotify() {
MEDIA_TITLE=$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:org.mpris.MediaPlayer2.Player string:Metadata 2>/dev/null | sed -n '/title/{n;p}' | cut -d '"' -f 2)
IS_MUTE=0
[[ $(amixer get Master | sed "5q;d") == *off* ]] && IS_MUTE=1
IS_SPOTIFY_AD=0
[[ $MEDIA_TITLE == *Advertisement* ]] && IS_SPOTIFY_AD=1
if [ ! -z "$MEDIA_TITLE" ]; then
if [[ $IS_MUTE == 0 ]] && [[ $IS_SPOTIFY_AD == 1 ]]; then
amixer -q -D pulse sset Master mute
elif [[ $IS_MUTE == 1 ]] && [[ $IS_SPOTIFY_AD == 0 ]]; then
# unmutes if mixer is muted and no ad is playing, this ensures that after ad the music will continue
# But also this means that when spotify is playing, I cannot mute audio!
amixer -q -D pulse sset Master unmute
fi
fi
}
unSubBtnList = document.querySelectorAll("[aria-label^='Unsubscribe from']");
for (let i = 0; i < unSubBtnList.length; i++) {
setTimeout(() => {
unSubBtnList[i].click();
}, 1000);
setTimeout(() => {
document.querySelector('[aria-label="Unsubscribe"]').click();
}, 1000);
}

Hello, this is a repository of all the snippets I have on medium!

# Whiptail UI
STEP_LIST=(
'install_fonts' 'Install fonts'
'setup_ubuntu' 'Update and setup ubuntu'
'setup_macos' 'Update and setup macOS'
'setup_pi' 'Update and setup raspberry pi'
'setup_fedora' 'Update and setup fedora'
'setup_oh_my_zsh' 'Install oh my ZSH!'
'setup_git' 'Setup git email and name'
'setup_node' 'Install node using NVM'
'setup_rust' 'Install Rust'
'setup_docker' 'Install docker'
'setup_flutter' 'Install flutter and its toolchain'
'setup_miniconda' 'Setup python using miniconda'
'setup_albert' 'Install albert plugins'
'setup_fzf' 'Setup FZF'
'setup_ssh_keys' 'Create and setup ssh keys'
)
entry_options=()
entries_count=${#STEP_LIST[@]}
message='Choose the steps to run!'
for i in ${!STEP_LIST[@]}; do
if [ $((i % 2)) == 0 ]; then
entry_options+=($(($i / 2)))
entry_options+=("${STEP_LIST[$(($i + 1))]}")
entry_options+=('OFF')
fi
done
SELECTED_STEPS_RAW=$(
whiptail \
--checklist \
--separate-output \
--title 'Setup' \
"$message" \
40 50 \
"$entries_count" -- "${entry_options[@]}" \
3>&1 1>&2 2>&3
)
if [[ ! -z SELECTED_STEPS_RAW ]]; then
for STEP_FN_ID in ${SELECTED_STEPS_RAW[@]}; do
FN_NAME_ID=$(($STEP_FN_ID * 2))
STEP_FN_NAME="${STEP_LIST[$FN_NAME_ID]}"
echo "---Running ${STEP_FN_NAME}---"
$STEP_FN_NAME
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment