Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
vbarbarosh / shell_files_list
Last active May 13, 2019 18:16
shell_files_list – Common options to use with ls command 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
# Common options to use with ls command
# How to sort
#
@vbarbarosh
vbarbarosh / js_pager_numerate_google.js
Last active May 12, 2019 19:17
js_pager_numerate_google – Generate page numbers like Google does https://codescreens.com
// Generate page numbers like Google does
function pager_numerate_google(active, total, display)
{
const begin = Math.max(1, active - Math.floor(display/2));
const length = Math.min(total, display);
const x = Math.min(0, total + 1 - begin - length);
return Array(length).fill(0).map((v,i) => begin + i + x)
.map(v => v == active ? `[${v}]` : v);
}
@vbarbarosh
vbarbarosh / shell_curl_post_multipart
Last active May 11, 2019 20:22
shell_curl_post_multipart – POST as multipart/form-data with curl 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
# POST as multipart/form-data with curl
# https://curl.haxx.se/docs/manpage.html
curl https://echo.vbarbarosh.com \
@vbarbarosh
vbarbarosh / shell_curl_post_json
Last active May 10, 2019 18:32
shell_curl_post_json – POST as application/json with curl 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
# POST as application/json with curl
# https://curl.haxx.se/docs/manpage.html
curl https://echo.vbarbarosh.com -H Content-Type:application/json
@vbarbarosh
vbarbarosh / shell_curl_post_urlencoded
Last active May 9, 2019 20:28
shell_curl_post_urlencoded – POST as application/x-www-form-urlencoded with curl 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
script=`realpath $0`
scriptdir=`dirname $script`
scriptname=`basename $script`
@vbarbarosh
vbarbarosh / shell_curl_post_javascript
Last active May 8, 2019 19:52
shell_curl_post_javascript – POST as application/javascript with curl 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
# POST as application/javascript with curl
# https://curl.haxx.se/docs/manpage.html
curl https://echo.vbarbarosh.com -H Content-Type:application/javascript \
@vbarbarosh
vbarbarosh / shell_curl_pipe
Last active May 7, 2019 20:26
shell_curl_pipe – A way to use curl in pipeline 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
# A way to use curl in pipeline
# https://curl.haxx.se/docs/manpage.html
# Input from stdin, output to stdout
@vbarbarosh
vbarbarosh / shell_curl_options
Last active May 6, 2019 17:58
shell_curl_options – Common options for curl 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
# Common options for curl
# https://curl.haxx.se/docs/manpage.html
# -s silent, -f fail --- should be used in shell scripts
@vbarbarosh
vbarbarosh / shell_curl_headers
Last active May 5, 2019 17:40
shell_curl_headers – Sending and receiving headers with curl 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
# Sending and receiving headers with curl
# https://curl.haxx.se/docs/manpage.html
# Show HTTP request and response headers
@vbarbarosh
vbarbarosh / shell_curl_head
Last active May 4, 2019 20:01
shell_curl_head – Sending HEAD requests with curl 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
# Sending HEAD requests with curl
# https://curl.haxx.se/docs/manpage.html
curl -I https://httpbin.org/status/400