Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
vbarbarosh / shell_bash_spawn_wait
Last active April 10, 2019 17:33
shell_bash_spawn_wait – Create 100 parallel jobs and wait until they are done https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# https://www.percona.com/blog/2017/10/01/one-million-tables-mysql-8-0/
function long_run
{
@vbarbarosh
vbarbarosh / shell_escape_html
Last active April 11, 2019 18:18
shell_escape_html – Make a string safe to put into html https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Make a string safe to put into html
# https://stackoverflow.com/a/12873723/1478566
sed 's/&/\&amp;/g; s/</\&lt;/g; s/>/\&gt;/g; s/"/\&quot;/g; s/'"'"'/\&#39;/g'
@vbarbarosh
vbarbarosh / shell_awk_parse_columns
Last active April 12, 2019 17:17
shell_awk_parse_columns – Parse columns separated by spaces https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Parse columns separated by spaces
docker ps | awk '{print $2}'
@vbarbarosh
vbarbarosh / shell_awk_parse_ssh_config
Last active April 13, 2019 16:54
shell_awk_parse_ssh_config – Parse ~/.ssh/config file with awk https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Parse ~/.ssh/config file with awk
# usage: shell_awk_parse_ssh_config
# usage: shell_awk_parse_ssh_config | column -t
@vbarbarosh
vbarbarosh / shell_lines_count
Last active April 14, 2019 14:19
shell_lines_count – Count lines https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Count lines
find | wc -l
@vbarbarosh
vbarbarosh / shell_lines_prefix_time
Last active October 3, 2020 22:05
shell_lines_prefix_time – Add a timestamp to beginning of each line https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Add a timestamp to beginning of each line
# The fastest
# https://unix.stackexchange.com/a/26797/121657
@vbarbarosh
vbarbarosh / shell_docker_browserless_screencast
Last active April 16, 2019 18:17
shell_docker_browserless_screencast – Make a screencast of a page using Browserless https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Make a screencast of a page usign Browserless
curl -sf https://chrome.browserless.io/screencast \
-H Content-Type:application/javascript \
@vbarbarosh
vbarbarosh / shell_docker_browserless_parse_showmyip
Last active April 17, 2019 15:00
shell_docker_browserless_parse_showmyip – Parse a website using css selectors on the example of showmyip.gr https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Parse a website using css selectors on the example of showmyip.gr
docker run --rm -i browserless/chrome bash << 'EOF'
node build/index.js &
@vbarbarosh
vbarbarosh / shell_docker_browserless_markdownpdf
Last active April 18, 2019 18:17
shell_docker_browserless_markdownpdf – Convert markdown into pdf using Browserless https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Convert markdown into pdf using Browserless
# usage: cat input.md | ./shell_docker_browserless_markdownpdf > a.pdf
html=`base64 -w0 << EOF
@vbarbarosh
vbarbarosh / shell_docker_browserless_debug
Last active April 19, 2019 17:01
shell_docker_browserless_debug – Debugging Browserless https://codescreens.com
#!/bin/bash
# http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -o nounset -o errexit -o pipefail
# Debugging Browserless
# -e DEBUG=browserless* print only browserless messages
# -e DEBUG=puppeteer* print only puppeteer messages