Get your bash scripts to sleep (halt execution) on Shippable and Travis

As I write this, it’s been about 36 hours without sleep for me — enough to relate to the importance of sleeping. However, this discussion is around getting a bash script or JavaScript on NodeJS to sleep for a specific duration.

#!/usr/bin/env bash

echo "Feeling drowsy...";
sleep 10;
echo "Woof! Back up after 10 seconds!";

The sleep command in unix allows one to pause execution of a script for a specified duration. It is a very handy tool in times where a script needs to wait for some other asynchronous work to complete. (Kindergarten talks for many!)

Continue reading “Get your bash scripts to sleep (halt execution) on Shippable and Travis”

Check if UNIX Path has Hidden Directory or File

This snippet of code uses regular expression to test if a path string contains any hidden directory. The use-case was derived from the difficulty in determining whether directory is hidden or not using NodeJS path module. Owing to the possibility of their existence within a long path string, this function returns false if any directory or the terminal file of a path has a name that starts with a dot.

/**
 * Checks whether a path starts with or contains a hidden file or a folder.
 *
 * @param {string} source - The path of the file that needs to be validated.
 * returns {boolean} - `true` if the source is blacklisted and otherwise `false`.
 *
 * @example
 * console.log(isUnixHiddenPath('~/documents')); // prints `false`
 * console.log(isUnixHiddenPath('~/documents/file.txt')); // prints `false`
 * console.log(isUnixHiddenPath('~/source/repo/.gitignore')); // prints `true`
 * console.log(isUnixHiddenPath('~/source/repo/.git/config')); // prints `true` 
 */ 
var isUnixHiddenPath = function (path) { 
    return (/(^|./).+[^/.]/g).test(path); 
};

A relevant StackOverflow question is located at http://stackoverflow.com/questions/8905680/nodejs-check-for-hidden-files/ and a gist is at https://gist.github.com/shamasis/7704671