Skip to content

Instantly share code, notes, and snippets.

@b0bu
Created May 25, 2021 11:28
Show Gist options
  • Save b0bu/96d764d797b7ff83bebf749d77cdf3d8 to your computer and use it in GitHub Desktop.
Save b0bu/96d764d797b7ff83bebf749d77cdf3d8 to your computer and use it in GitHub Desktop.
daft_timer_in_python

Maybe the daftest of all gists. Indeed for timing anything timeout n or sleep n are what you should absolutely use in bash. But I thought the visual was cool for this one.

timer () {
t=${1:-60}
python -c '
import time
import sys
t = int(sys.argv[1])
for i in range(t):
    print(f"\r {t-i}", end="")
    time.sleep(1)
' ${t}
}
> timer # defaults to 60 seconds
> timer 120 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment