This file contains hidden or 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
| #!/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.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion | |
| # Check if $FOO is unset | |
| test -z ${FOO+x} && echo FOO is unset |
This file contains hidden or 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
| // Make a string safe to put into html | |
| // https://stackoverflow.com/a/6234804/1478566 | |
| // | |
| // Consider using https://github.com/mathiasbynens/he for production | |
| function html_escape(s) | |
| { | |
| return s | |
| .replace(/&/g, '&') | |
| .replace(/</g, '<') | |
| .replace(/>/g, '>') |
This file contains hidden or 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
| // Make a string safe to put into RegExp | |
| // https://stackoverflow.com/a/6969486 | |
| // https://stackoverflow.com/a/3561711 | |
| function js_escape_regexp(s) | |
| { | |
| return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); | |
| } |
This file contains hidden or 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
| // Shortcuts for making ranges of numbers | |
| function range(begin, end) | |
| { | |
| return Array(end - begin).fill(0).map((v,i) => i + begin); | |
| } | |
| function range_step(begin, end, step) | |
| { | |
| const length = Math.ceil((end - begin)/step); |
This file contains hidden or 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
| #!/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 | |
| url='https://www.youtube.com/watch?v=u2oKnsiXBr8' | |
| # Using `-o-` instead of `-o /dev/stdout` might lead to | |
| # curl: (23) Failed writing body (4096 != 16384) |
This file contains hidden or 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
| #!/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 | |
| # usage: cat input.html | ./shell_docker_browserless_htmlpdf > a.pdf | |
| html=`base64 -w0` |
This file contains hidden or 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
| <?php | |
| # Create an alias to a function | |
| function foobar($a) | |
| { | |
| echo 'hello ', $a, PHP_EOL; | |
| } | |
| function foobar_alias() |
This file contains hidden or 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
| <?php | |
| # Generate UUID in PHP | |
| # http://en.wikipedia.org/wiki/Universally_unique_identifier | |
| # http://www.php.net/manual/en/function.uniqid.php#94959 | |
| function uuid_v4() | |
| { | |
| return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', |
This file contains hidden or 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
| <?php | |
| # Default options in functions | |
| function foobar($opt = []) | |
| { | |
| $opt += [ | |
| 'name' => 'default_name', | |
| 'title' => 'Default Title', | |
| ]; |
This file contains hidden or 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
| <?php | |
| # Use a function as an scope for variables | |
| $foo = call_user_func(function () { | |
| $aa = 'Fusce vitae orci lorem.'; | |
| $bb = 'In cursus nisi malesuada.'; | |
| $cc = 'Etiam auctor, lectus eu lacinia condimentum.'; | |
| return implode("\n", [$aa, $bb, $cc]); | |
| }); |