Skip to content

Instantly share code, notes, and snippets.

John Mark Mitchell jmmitchell

Block or report user

Report or block jmmitchell

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
jmmitchell /
Last active Jun 1, 2018
capture standard out, standard error and return code in bash
# #!/bin/bash
# based on posts from stackexchange:
function example_function {
printf 'example output to stdout %d\n' {1..10}
echo >&2 'example output to stderr'
jmmitchell /
Last active Jun 17, 2019
converting from decimal value to the ascii character and from the ascii character to the ordinal number in bash
# chr() - converts decimal value to its ASCII character representation
# ord() - converts ASCII character to its decimal value
chr() {
printf \\$(printf '%03o' $1)
ord() {
printf '%d' "'$1"
jmmitchell /
Created Apr 5, 2016
One liner for adding or removing trailing slash of a string in Bash
# Add a trailing slash to a string if there is not one already
echo "${STR}$(printf \\$(printf '%03o' $(($(printf '%d' "'${STR:(-1)}")==47?0:47))))"
# remove a (single) trailing slash on a string if there is one
echo "${STR%/}"
View gist:c9d64d04b42639be149a

Whether you use 2 spaces or 4 spaces, there are a few simple things that can make your node.js code easier to read. We've been using them in all the hapi modules for over 4 years now to great results. This list is by no means complete but it highlights the most useful elements that will give you immediate value in reducing bugs.

Required modules

JavaScript makes it harder than most languages to know where variables are coming from. Variables assigned required modules are particularly important because they represent a singleton object shared with the entire application. There are also globals and module globals, along with function variables and arguments.

Traditionally, variables starting with an uppercase letter represent a class that must be instantiated using new. This was an important semantic in the early days of JavaScript but at this point, if you don't know Date requires new Date() you are probably very new. We have adopted CamelCase variable names for all module global variables which a

You can’t perform that action at this time.