Skip to content

Instantly share code, notes, and snippets.

View shamasis's full-sized avatar

Shamasis Bhattacharya shamasis

View GitHub Profile
@shamasis
shamasis / check-unix-directory.js
Last active December 30, 2015 08:39
Function to test whether a path has any hidden folder in it or whether a file is hidden or not using regular expressions and not using the file-system. I find it particularly useful to validate a path that is user-provided and does not actually exist on disk. For unix based systems only.
/**
* Tests whether a path is a directory or possibly a file reference.
*
* @param {string} path
* @returns {boolean}
*/
isUnixDirectory: function (path) {
return (/(^\.+$)|(\/$)/).test(path);
}
@shamasis
shamasis / directed-graph.js
Last active December 29, 2015 18:09
Directed graph data structure
var Graph = function () {
this.vertices = {};
this.edges = [];
this.length = 0;
};
Graph.Vertex = function (name, value) {
this.name = name;
this.edges = [];
this.value = value;
@shamasis
shamasis / check-unix-hidden-path.js
Last active December 29, 2015 17:29
Check whether a path has hidden directory or whether a file/directory is hidden.http://stackoverflow.com/questions/8905680/nodejs-check-for-hidden-files/
/**
* 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`.
*/
var isUnixHiddenPath = function (path) {
return (/(\/|^)\.[^\/\.]/g).test(path);
};