Skip to content

Instantly share code, notes, and snippets.

View smuuf's full-sized avatar

Přemysl Karbula smuuf

View GitHub Profile
# Echo number of GIT commits per year.
git log --pretty='format:%cd' --date=format:'%Y' | uniq -c | awk '{print "Year: "$2", commits: "$1}'
@smuuf
smuuf / darkize_git_gui.py
Created February 26, 2024 15:47
git-gui dark theme patcher
#!/bin/env python
import os
import subprocess
from sys import stderr
FORCED_GIT_GUI_PATH=None
# Do NOT modify anything below.
UNPATCHED_NEEDLE = 'pave_toplevel .'
# 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 / .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 / install_pypy.sh
Last active April 4, 2023 10:35
Simple install any version of pypy
# This is the name of archive taken from https://downloads.python.org/pypy/
PYPY_VER="pypy3.9-v7.3.11-linux64"
PYPY_VER_NUM=`echo ${PYPY_VER} | grep -oP "v(\d\.?)+" | sed -r 's/[v.]//g'`
cd ~
mkdir pypy
wget https://downloads.python.org/pypy/$PYPY_VER.tar.bz2 && tar -xvjf $PYPY_VER.tar.bz2
rm $PYPY_VER.tar.bz2
mv $PYPY_VER pypy/
sudo ln -s ~/pypy/$PYPY_VER/bin/pypy3 /usr/bin/pypy3-$PYPY_VER_NUM; chmod +x /usr/bin/pypy3-$PYPY_VER_NUM
@smuuf
smuuf / a2manage.sh
Created January 28, 2022 10:19
a2enmod and a2dismod for Alpine
#!/bin/sh
# Usage:
# ./a2manage.sh a2dismod proxy.*
# ./a2manage.sh a2enmod proxy proxy_fcgi ssl
MODS_A_CONF_PATH="/etc/apache2/*.conf"
MODS_B_CONF_PATH="/etc/apache2/conf.d/*.conf"
function a2enmod {
@smuuf
smuuf / gitdifffind.sh
Created January 13, 2023 09:27
Find string in git diff with info about function or class
#!/bin/bash
PREVIOUS="(@@.*function|class)" NEEDLE="getTraced" \
bash -c 'git diff | awk "(/$PREVIOUS/ && !/$NEEDLE/) {capture=1; buffer = \$0; next} capture==1 {buffer = buffer \$0 \"\n\"} (\$capture && /$NEEDLE/) {printf(\"%s\", buffer); capture=0}"'
@smuuf
smuuf / reorpyre.py
Created December 7, 2022 09:01
Re or Pyre2
import random
import logging
import re as module_re
import re2 as module_re2
USAGE_PROBABILITY = 0.5
USE_ONLY_PYRE2 = True
@smuuf
smuuf / settings.json
Created November 15, 2022 14:08
Settings for vscode highlight extension
{
// PHP highlights for https://github.com/fabiospampinato/vscode-highlight
"highlight.regexes": {
"(NOTE:)\s": {
"regexFlags": "g",
"filterLanguageRegex": "php",
"decorations": [
{
"color": "#CFC8A6",
"backgroundColor": "#CFC8A40",
@smuuf
smuuf / psleep.sh
Last active June 2, 2022 14:16
Bash sleep with countdown
#!/bin/bash
function psleep {
S="$1"
O="$S"
while [ $S -gt 0 ]; do
echo -ne "\r$S s (from $O) "
sleep 1
((S--))
done