Skip to content

Instantly share code, notes, and snippets.

@slowpeek
slowpeek / nvidia-smi
Last active Jan 20, 2023
nvidia-smi 525 dmon adapter
View nvidia-smi
#!/usr/bin/env bash
# MIT license (c) 2022 https://github.com/slowpeek
# Homepage: https://gist.github.com/slowpeek/006680bb06e671bc489d4a3274ff3d19
# Output of 'nvidia-smi dmon' in nvidia driver 525 is not well aligned
# compared to 520. Because of that KDE system monitor cant parse the
# data for nvidia GPUs (at least in ubuntu 22.04). This tool realigns
# the printed fields correctly. It is a general wrapper for 'dmon'
# mode, not just for 'dmon -s pucm' KDE system monitor uses.
@slowpeek
slowpeek / ubuntu-sources
Last active Aug 14, 2021
Simple apt sources generator for ubuntu
View ubuntu-sources
#!/usr/bin/env bash
# MIT license (c) 2021 https://github.com/slowpeek
# Homepage: https://gist.github.com/slowpeek/beedb0c9c79638d4a7ec0099d0875ecb
# Simple apt sources generator for ubuntu.
set -eu
usage () {
@slowpeek
slowpeek / locate-exit.sh
Last active Aug 31, 2022
locate-exit.sh
View locate-exit.sh
# -*- mode: sh; sh-shell: bash; -*-
# shellcheck shell=bash
# MIT license (c) 2021 https://github.com/slowpeek
# Homepage: https://gist.github.com/slowpeek/7e2731b620d558f44841da6772743d38
# This script can help you find out which line and why (end of code,
# literal exit, 'set -e' violation, bash error) your bash script
# finished execution.
#
View temp.sh
# -*- mode: sh; sh-shell: bash; -*-
# shellcheck shell=bash
# MIT license (c) 2021 https://github.com/slowpeek
# Homepage: https://gist.github.com/slowpeek/f3e851f5c6fa6a7ba1f33d1e903bf4a9
# Temporarily assign a new value to a var and restore it
# later. Strings only. The code is simple on intention, use it
# correctly.
#
View comment.org

#!/usr/bin/bash is totally wrong

It should be either #!/bin/bash or #!/usr/bin/env bash. The latter is preferred.

There are better ways to parse options

Check out bash builtin getopts (it supports short options only) and getopt (long options as well but it is an external tool).

View stack.sh
# -*- mode: sh; sh-shell: bash; -*-
# shellcheck shell=bash
# MIT license (c) 2021 https://github.com/slowpeek
# Homepage: https://gist.github.com/slowpeek/3310c2f09b80d0b2e175122e8c8cae64
# bye.sh https://gist.github.com/slowpeek/6127166369d8abd230c30c20cc6a9152
# Simple stack for strings. It operates on var names:
#
View bye.sh
# -*- mode: sh; sh-shell: bash; -*-
# shellcheck shell=bash
# MIT license (c) 2021 https://github.com/slowpeek
# Homepage: https://gist.github.com/slowpeek/6127166369d8abd230c30c20cc6a9152
##############################################################
##############################################################
## THIS GIST IS OBSOLETE AND IS NO LONGER UPDATED.
## Use here-bye instead: https://github.com/slowpeek/here-bye
View shopt_ensure.sh
# -*- mode: sh; sh-shell: bash; -*-
# shellcheck shell=bash
# MIT license (c) 2021 https://github.com/slowpeek
# Homepage: https://gist.github.com/slowpeek/3e592af3395cfb0e2d20a57c50a87a4b
# bye.sh https://gist.github.com/slowpeek/6127166369d8abd230c30c20cc6a9152
# stack.sh https://gist.github.com/slowpeek/3310c2f09b80d0b2e175122e8c8cae64
# This is a wrapper around bash builtin shopt. It can be used to save