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
#!/usr/bin/env bash | |
# Description: Retry a command until it succeeds. | |
# Author: James Cherti | |
# License: MIT | |
# URL: https://gist.github.com/jamescherti/995add1dcbf3080dfa25cf372287cca9 | |
echo "[RUN] $*" >&2 | |
while true; do | |
if "$@"; then | |
break |
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
#!/usr/bin/env python | |
# License: MIT | |
# URL: https://gist.github.com/jamescherti/47e0cd74505147911b483cee11e256b1 | |
import hashlib | |
def sha512sum(filename): | |
"""Return the SHA512 hash of a file.""" | |
sha512 = hashlib.sha512() | |
with open(filename, 'rb') as fhandler: |
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
#!/usr/bin/env python | |
# Author: James Cherti | |
# License: MIT | |
# URL: https://gist.github.com/jamescherti/53e5d3bb4da597f24f4fe8c42fe49ea1 | |
"""Which() is a Python method that returns the full path of a (shell) command.""" | |
from pathlib import Path | |
import os | |
def which(command: str) -> Path: |
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
#!/usr/bin/env python | |
# Author: James Cherti | |
# License: MIT | |
# URL: https://gist.github.com/jamescherti/b8badae104576edc082f5095bfe0652f | |
"""Return the human-readable size of a file.""" | |
from typing import Union | |
def human_readable_file_size(file_size: Union[int, float]) -> str: | |
"""Return the human-readable size of a file.""" |
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
#!/usr/bin/env python | |
# License: MIT | |
# Author: James Cherti | |
# URL: https://gist.github.com/jamescherti/1f7d9adc428db00f9104312a24537d52 | |
"""Ask the user a yes/no question.""" | |
import sys | |
import signal | |
import select |
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
" Language: Vim script | |
" Author: James Cherti | |
" License: MIT | |
" URL: https://gist.github.com/jamescherti/42d7995184a6ac01175c5e9190763772 | |
" Decsription: Vim input() function: auto-complete from a predefined list | |
function! AutoCompleteInput(arglead, cmdline, cursorpos) | |
return ["first_answer", "second_answer"] | |
endfunction |
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
" Language: Vim script | |
" Author: James Cherti | |
" URL: https://gist.github.com/jamescherti/07aa562b0b263ba414655a5701a3868d | |
" License: MIT | |
" Description: NetrwSwitch() will allow you switch between the currently | |
" edited file and netrw (the local-directory browser), | |
" and vice versa (keyboard mapping: '<Leader>e'). | |
function! NetrwSwitch() | |
if &filetype !=# 'netrw' && exists('w:netrw_switch_previous_buffer') |
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
" Language: Vim script | |
" Author: James Cherti | |
" URL: https://gist.github.com/jamescherti/d552078af417a9c3c84c71d7db30f06a | |
" License: MIT | |
" Description: Close the buffer of all Vim terminals (Vim's built-in terminals) | |
function! CloseAllTerminals() abort | |
let l:buflist = getbufinfo() | |
for l:buf in l:buflist | |
if getbufvar(l:buf.bufnr, '&buftype', '') ==# 'terminal' |
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
" Language: Vim script | |
" Author: James Cherti | |
" URL: https://gist.github.com/jamescherti/c36c975aad4802a0e47a4a8274d55684 | |
" License: MIT | |
" Description: Return the Git root directory / folder (Git top level). | |
" let toplevel = GitRootDir() | |
" let toplevel = GitRootDir("/path/to/dir") | |
function! GitRootDir(...) abort | |
if len(a:000) > 0 |
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
#!/usr/bin/env sh | |
# Description: extract all download links from a URL. | |
# Usage: get_urls "https://domain.com/page" | |
# Requirements: lynx, sed, grep, and bash. | |
# Author: James Cherti | |
# URL: https://gist.github.com/jamescherti/8ee95c52d283671ab314afb09feab9dc | |
# License: MIT | |
get_urls() { | |
if [ $# -lt 1 ]; then |
OlderNewer