Skip to content

Instantly share code, notes, and snippets.

View smuuf's full-sized avatar

Přemysl Karbula smuuf

View GitHub Profile
@smuuf
smuuf / wavtomp3.sh
Last active March 28, 2020 10:33
WAV to MP3 bash function
# Best to put this in your .bashrc
# .wav extension will be replaced with .mp3 automatically.
# Usage: wavtomp3 lorem_ipsum.wav
function wavtomp3() {
ffmpeg -i "$1" -vn -ar 44100 -ac 2 -b:a 320k "${1/.wav/.mp3}"
}
@smuuf
smuuf / .bashrc
Last active May 15, 2023 21:57
Pretty prompt alá smuuf
# smuuf.bashrc
# Prompt formatting
# 10:20:49 /etc
# [smuuf@smuuf-xubuntu]$
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
}
NC="$(tput sgr0)"
@smuuf
smuuf / bestrsync.sh
Created April 4, 2019 21:00
Copy whole directories via rsync with resuming
rsync -e ssh -avzP --inplace (<src_host>:)<src_path> (<target_host>:)<target_path>
# Use this to enable debugging for current terminal session.
# export XDEBUG_CONFIG="idekey=whatever"
[XDebug]
xdebug.remote_enable=1
xdebug.remote_autostart=0
xdebug.profiler_output_dir=/mnt/d/_produkce/_xdebug_profiles/
xdebug.profiler_output_name=callgrind.%t.out
xdebug.profiler_enable_trigger=1
#xdebug.idekey="asd"
# Sets the color of next text output to be a random color based on hostname's md5 hash.
# (If the terminal supports true colour (RGB) colors.)
set_host_based_color() {
HOSTHASH=$(hostname | md5sum)
printf "\x1b[38;2;%d;%d;%dm" 0x${HOSTHASH:0:2} 0x${HOSTHASH:2:2} 0x${HOSTHASH:4:2}
}
# Example usage:
# PS1="[\$(set_host_based_color)\$(hostname)\033[0m]: "
@smuuf
smuuf / git_status_in_function.sh
Last active November 30, 2018 10:47
git status in prompt function
#!/bin/bash
get_git_status() {
git_status=$(git status -s -u -v 2>/dev/null)
if [[ -z "$git_status" ]]; then return 0; fi
modified=$(echo "$git_status" | grep '^ M ' | wc -l)
deleted=$(echo "$git_status" | grep '^ D ' | wc -l)
untracked=$(echo "$git_status" | grep '^?? ' | wc -l)
echo "(~$modified -$deleted +$untracked) "
}
@smuuf
smuuf / ssh-multi-copy-id.sh
Last active December 20, 2018 12:10
Small BASH script which iterates over all hosts defined in SSH config and tries to ssh-copy-id your SSH ID to all of them.
#!/bin/bash
cd $(dirname $0)
CONF_PATH=~/.ssh/config
function title() {
echo "█ $1"
}
@smuuf
smuuf / fblimit.php
Created November 10, 2017 17:11
Facebook Crawler Request Rate Limiter
<?php
// Number of requests permitted for facebook crawler per second.
const FACEBOOK_REQUEST_THROTTLE = 20;
const FACEBOOK_REQUESTS_JAR = __DIR__ . '/.fb_requests';
const FACEBOOK_REQUESTS_LOCK = __DIR__ . '/.fb_requests.lock';
$ua = $_SERVER['HTTP_USER_AGENT'] ?? false;
if ($ua && strpos($ua, 'facebookexternalhit') !== false) {
@smuuf
smuuf / docker-run
Last active September 22, 2017 05:25
Access Docker host IP as "localhost" inside container when using Docker on Windows Hyper-V backend
# Docker client inside WSL + Container running under Docker on Windows (tested on Hyper-V's VM)
docker run --add-host=localhost:$(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1) -it <...containerID...> /bin/bash
#!/bin/bash
if [[ -f $1 ]]; then
cat $1 | while read line
do
youtube-dl --no-mtime --no-post-overwrites --extract-audio --audio-format mp3 --audio-quality 192K $line
done
else