Skip to content

Instantly share code, notes, and snippets.

@vbarbarosh
vbarbarosh / shell_templ
Last active March 28, 2019 21:06
shell_templ – A template for shell scripts 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_find
Last active March 28, 2019 21:07
shell_find – Searching for files 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
# Find files modified more than 1 month ago (31 days)
find -mtime 31 -type f
# Find files accessed more than 1 month ago (31 days)
@vbarbarosh
vbarbarosh / shell_youtube
Last active March 28, 2019 21:07
shell_youtube – Downloading videos from youtube 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
# Download all videos from channel
youtube-dl https://www.youtube.com/channel/UCVqD-Rd1nMmvbvf-AvQvgZw
# Download a list of videos using urls
@vbarbarosh
vbarbarosh / shell_imagemagick_thumbnails
Last active March 28, 2019 21:07
shell_imagemagick_thumbnails – Create thumbnails for a folder of images 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
# http://www.imagemagick.org/Usage/resize/#shrink
# Create a `-thumb.jpg` for each of .jpg, .png, and .gif in current dir
for orig in `ls | grep -E '\.(jpg|png|gif)$'`; do
@vbarbarosh
vbarbarosh / shell_docker_adminer
Last active March 28, 2019 21:06
shell_docker_adminer – Run dockerized Adminer with access to localhost 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
# From inside of a Docker container, how do I connect to the localhost
# of the machine?
# https://stackoverflow.com/q/24319662/1478566
@vbarbarosh
vbarbarosh / shell_bash_range
Last active March 28, 2019 21:08
shell_bash_range – Generate range of numbers in bash 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/
# 1 2 3 4 5 6 7 8 9 10
echo {1..10}
@vbarbarosh
vbarbarosh / php_templ_cli.php
Last active March 27, 2019 17:50
php_templ_cli – A template for simple php cli scripts https://codescreens.com
<?php
// https://stackoverflow.com/a/2071048/1478566
set_error_handler(function ($code, $message, $filename, $lineno) {
throw new ErrorException($message, $code, 0, $filename, $lineno);
});
// The above code is necessary to terminate program in all of the
// following cases:
@vbarbarosh
vbarbarosh / php_array_merge.php
Last active March 28, 2019 20:56
php_array_merge – Three ways to merge arrays https://codescreens.com
<?php
// https://stackoverflow.com/a/2071048/1478566
set_error_handler(function ($code, $message, $filename, $lineno) {
throw new ErrorException($message, $code, 0, $filename, $lineno);
});
$a = [1 => 'a', 2 => 'b', 3 => 'c', 'str' => 'hello'];
$b = [ 2 => 'x', 4 => 'y'];
$c = ['str' => 'welcome'];
@vbarbarosh
vbarbarosh / shell_bash_lines_wrap
Last active March 29, 2019 20:26
shell_bash_lines_wrap – Wrapping lines in Bash 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://serverfault.com/a/72749/323502
ls | awk '{print "PREFIX-" $0 "-SUFFIX"}'
@vbarbarosh
vbarbarosh / js_gotcha_string_replace.js
Last active March 30, 2019 19:25
js_gotcha_string_replace – Special chars in replacement string https://codescreens.com
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/
// Global_Objects/String/replace#Specifying_a_string_as_a_parameter
// I faced with this problem trying to insert user input into html
// document:
//
// template_html.replace('{{{xxx}}}', html_escape(input))
//
// ls | grep -E '\.(jpg|png|gif)$' original
// ls | grep -E &#39;\.(jpg|png|gif)$&#39; after html escape