*How to get available disk space to check if server still has free disk space?
// -----------------------------------------------------------------------------------------------------
// Function: getDiskSpace
// Purpose: Return available space in the server drive
// Arg(s): (String) commandLine - command to be executed
// Return(s): (String) freeBytes - free disk space
// -----------------------------------------------------------------------------------------------------
function getDiskSpace(commandLine)
{
var output = Clib.system(commandLine); //to be tested (can't share the function I used here originally due to security issues)
var splitRes = output.split(' ');
if (!splitRes)
{ //print or log or alert error
return false;
}
var freeBytes = parseStringBytes(splitRes);
if(!freeBytes)
{
//print or log or alert error
return false;
}
else
{
//print or log or alert error
return freeBytes;
}
}
// -----------------------------------------------------------------------------------------------------
// Function: parseStringBytes
// Purpose: Return parsed free space string to a float
// Arg(s): (String) splitRes - string free bytes
// Return(s): (String) numBytes - float free bytes
// -----------------------------------------------------------------------------------------------------
function parseStringBytes(splitRes)
{
var freeBytes = "";
for (var i=0; i< splitRes.length; i++)
{
var str = splitRes[i];
if (str === "bytes")
{
freeBytes = splitRes[i-1];
}
}
var numBytes = parseFloat(freeBytes.replace(/,/g, ""));
return numBytes;
}
===========================================================
*where commandLine = 'dir|find "bytes free"';
Friday, August 26, 2016
Thursday, August 11, 2016
Javascript Sorting Algo
Javascript Sorting Algo
var arrObj = new Array(); // or [];
var temp = new Object();
temp.num = 3.58;
arrObj.push(temp); //add more of this; can loop through array of objects
....
arrObj.sort(sortByObjNumber);
function sortByObjNumber(a, b)
{
var a = parseInt(a.num);
var b = parseInt(b.num);
if(a < b)
{
return -1;
}
else if(a == b)
{
return 0;
}
else
{
return 1;
}
}
var arrObj = new Array(); // or [];
var temp = new Object();
temp.num = 3.58;
arrObj.push(temp); //add more of this; can loop through array of objects
....
arrObj.sort(sortByObjNumber);
function sortByObjNumber(a, b)
{
var a = parseInt(a.num);
var b = parseInt(b.num);
if(a < b)
{
return -1;
}
else if(a == b)
{
return 0;
}
else
{
return 1;
}
}
Subscribe to:
Posts (Atom)