Skip to content

Instantly share code, notes, and snippets.

Přemysl Karbula smuuf

Block or report user

Report or block smuuf

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@smuuf
smuuf / .bashrc
Created Jul 24, 2019
Pretty prompt alá smuuf
View .bashrc
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
}
NC="$(tput sgr0)"
export PS1="\e[90m\$(parse_git_branch)"
export PS1=$PS1"\[\033[38;5;7m\]\t\[$\]\[\033[38;5;15m\] \[$\]\[\033[38;5;30m\]\w\[$\]\[\033[38;5;15m\]\n\[$\]\[\033[38;5;7m\][\[$\]\[\033[38;5;202m\]\u\[$\]\[\033[38;5;15m\]@\[$\]\[\033[38;5;33m\]\h\[$\]\[\033[38;5;7m\]]\[$\]\[\033[38;5;15m\]\\$ \[$\]"
View gist:317dae6878d93e979b39eb8472bdbeca
# Best to put this in your .bashrc
# .wav extension will be replaced automatically.
# Usage: wavtomp3 lorem_ipsum.wav
function wavtomp3() {
ffmpeg -i "$1" -vn -ar 44100 -ac 2 -b:a 320k "${1/.wav/.mp3}"
}
@smuuf
smuuf / bestrsync.sh
Created Apr 4, 2019
Copy whole directories via rsync with resuming
View bestrsync.sh
rsync -e ssh -avzP --inplace (<src_host>:)<src_path> (<target_host>:)<target_path>
View terminal_host_color.sh
# 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 Nov 30, 2018
git status in prompt function
View git_status_in_function.sh
#!/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 Dec 20, 2018
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.
View ssh-multi-copy-id.sh
#!/bin/bash
cd $(dirname $0)
CONF_PATH=~/.ssh/config
function title() {
echo "$1"
}
@smuuf
smuuf / fblimit.php
Created Nov 10, 2017
Facebook Crawler Request Rate Limiter
View fblimit.php
<?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 Sep 22, 2017
Access Docker host IP as "localhost" inside container when using Docker on Windows Hyper-V backend
View docker-run
# 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
View youtube download
#!/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
View lines of output as progress dots
function lines_as_progress {
echo -ne "█ ("$@") "
stdbuf --output=L --error=L "$@" 2>&1 |
while IFS= read -r line
do
printf "."
done
printf " Done"
echo
}
You can’t perform that action at this time.