Skip to content

Instantly share code, notes, and snippets.

@sebastiancarlos
sebastiancarlos / gutenberg-dl.bash
Created March 28, 2024 19:56
gutenberg-dl - download text books from Project Gutenberg
#! /usr/bin/env bash
# All my gist code is licensed under the MIT license.
# gutenberg-dl <search-term>
# - Download books from Project Gutenberg in plain text format
# - Actually uses "gutendex" to search for the download link. It seems to be
# the current best third-party Gutemberg API
# - Source: https://github.com/garethbjohnson/gutendex
@sebastiancarlos
sebastiancarlos / bkp.bash
Last active March 9, 2024 14:38
bkp - toggle ".bkp" extension
#! /usr/bin/env bash
# All my gist code is licensed under the MIT license.
# Add this somewhere in your .bashrc
# bkp
# - toggle a ".bkp" extension to a file(s)
function bkp () {
# print usage on -h/--help or no arguments
@sebastiancarlos
sebastiancarlos / term2plain.bash
Last active January 23, 2024 10:49
term2plain - Record an interactive terminal session, and convert it to plain text.
#! /usr/bin/env bash
# All my gist code is licensed under the MIT license.
# term2plain
# - Convert a text file containing terminal escape sequences to plain text.
# - This plain text is close to the visual result of running the file in a
# terminal.
# - This is achieved by running the file in a virtual terminal (tmux) and
# capturing it's buffer output.
@sebastiancarlos
sebastiancarlos / sqlite3h
Last active March 22, 2024 20:18
sqlite3h - Wrapper around sqlite3 which saves interactive session to a history file
#! /usr/bin/env bash
# All my gist code is licensed under the MIT license.
### UPDATE!
# I noticed that this entire solution is unnecessary, as the following
# produces the same result, and can be put in the sqlite start file.
# ```
# .echo on
# .output "| tee -a history.txt"
@sebastiancarlos
sebastiancarlos / minimal_dir.py
Last active August 8, 2024 04:17
Like dir(), but filters out __*__ attributes, standard library packages, and built-ins, to give a better idea of the object's custom attributes.
# explicitly define the interface
__all__ = ["minimal_dir"]
from functools import cache
@cache
def get_stdlib_packages():
""" Get list that should include all stdlib package/module names.
Not perfect. Has false positives.
@sebastiancarlos
sebastiancarlos / pretty_print.py
Created January 19, 2024 15:30
Pretty printer with color, label and value (value defaults to evaluation of label)
# explicitly define the interface
__all__ = ["pretty_print"]
def is_package_available(package_name):
import importlib.util
package_spec = importlib.util.find_spec(package_name)
return package_spec is not None
def pretty_print(label: str, value: any = "") -> None:
""" Prints "label". Followed by pretty printed "value".
@sebastiancarlos
sebastiancarlos / groff-preview.bash
Last active August 7, 2024 19:13
groff-preview
#! /usr/bin/env bash
# All my gist code is licensed under the MIT license.
# Add this somewhere in your .bashrc
# groff-preview-terminal
# - previews roff file in the terminal
# - uses grog to figure out needed preprocessor and macros
# - sends to terminal output by passing -Tutf8 and then to a pager
@sebastiancarlos
sebastiancarlos / sway-popup-listener.bash
Last active December 18, 2023 17:30
sway-popup-listener
#!/usr/bin/env bash
# This script listens for new windows and makes them floating if it thinks they
# are popups. Meant to be used when regular i3 criteria are not enough to
# identify popup windows. It uses hardcoded dimensions.
# print usage on --help/-h
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
echo "Usage: $0"
echo "This script listens for new windows and makes them floating if it thinks they"
@sebastiancarlos
sebastiancarlos / sway-track-prev-focus.bash
Last active December 7, 2023 17:35
sway-track-prev-focus - Add transparency to unfocused windows
#!/usr/bin/env bash
# Source: https://gitlab.com/wef/dotfiles/-/blob/master/bin/i3-track-prev-focus
# https://gitlab.com/wef/dotfiles/-/blob/master/bin/sway-track-prev-focus
# shellcheck disable=SC2034
TIME_STAMP="20231126.172745"
# Copyright (C) 2020-2021 Bob Hepple <bob dot hepple at gmail dot com>
@sebastiancarlos
sebastiancarlos / sway-print-tree.bash
Last active February 19, 2024 15:18
sway-print-tree.bash (Pretty print Sway/i3 tree, color output, 'jq' is the only dependency)
#! /usr/bin/env bash
# ansi colors
bold='\033[1m'
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[1;33m'
blue='\033[0;34m'
reset='\033[0m'