Skip to content

Instantly share code, notes, and snippets.

View brandon-wallace's full-sized avatar
⌨️
coding

Brandon Wallace brandon-wallace

⌨️
coding
View GitHub Profile
@brandon-wallace
brandon-wallace / format-timedelta.go
Created May 8, 2023 02:58
Format time.Duration to Days, Hours, and Minutes
package main
import (
"fmt"
"time"
)
// formatTimedelta converts seconds into days, hours, and minutes.
func formatTimedelta(t time.Duration) string {
seconds := t * time.Second
@brandon-wallace
brandon-wallace / tmux_colors.sh
Last active April 1, 2023 13:54
Display Terminal Colors Available For Tmux Configuration
#!/bin/bash
for num in {0..255}; do
printf "%s\033[38;5;${num}mcolour${num}\033[0m \t";
if [ $(expr $((num+1)) % 8) -eq 0 ]; then
printf "\n"
fi
done
@brandon-wallace
brandon-wallace / bash_foreground_colors.sh
Last active July 16, 2022 13:20
Print Bash Foreground Colors
#!/bin/bash
# Print a range of Bash foreground colors.
c1=0
c2=30
# The first color is black. This will set the background to white.
c3=';47'
for i in {0..15}; do
@brandon-wallace
brandon-wallace / display_time_passed_since.py
Created December 17, 2021 21:03
Display Amount Of Time Passed Since A Date
from datetime import datetime, timedelta
def datetime_format(value, format="%Y-%m-%d %H:%M"):
'''Date time'''
time_passed = datetime.utcnow() - timedelta(years=value.year, months=value.month, days=value.day, hours=value.hour, minutes=value.minute)
return time_passed.strftime(format)
def convert_bytes(bytes, unit):
'''
Convert bytes to more human readable format.
For sizes above 1 KB display amount in kilobytes.
For sizes above 1 MB display amount in megabytes.
For sizes above 1 GB display amount in gigabytes.
For sizes above 1 TB display...
'''
unit = unit.lower()
@brandon-wallace
brandon-wallace / change_bash_prompt_color.sh
Last active April 29, 2024 22:52
Bash Prompt Color Change On Execution
# Add this to your .bashrc file.
count=232;
# Set the prompt to change colors on execution of each command.
function bash_prompt(){
PS1="\033[38;5;${count}m"' \W \$ '"\033[00m"
count=$((count+1));
[ $count -eq 255 ] && count=232;
}