This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
// formatTimedelta converts seconds into days, hours, and minutes. | |
func formatTimedelta(t time.Duration) string { | |
seconds := t * time.Second |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; | |
} |