Skip to content

Instantly share code, notes, and snippets.

View ItzArty's full-sized avatar

Dávid Švihura ItzArty

View GitHub Profile
Array.prototype._sortObj = function(sortProp, sortLH, startAt, endAt) {
var returnArray = this;
if(!sortProp) {
console.error("Sorting property undefined");
return;
}
var numeric = false;
for(var i = 0; i < returnArray.length; i++) {
if(typeof returnArray[i][sortProp] == undefined) {
console.error("Not all objects have the requested property");
const $n = ( name, appendTo, additionalProps, innerHTML ) => {
const element = document.createElement( name );
if( typeof appendTo == 'object' ) appendTo.appendChild( element );
if( typeof appendTo == 'string' ) document.querySelector( appendTo ).appendChild( element );
if( typeof additionalProps == 'object' ) {
for( const i in additionalProps ) {
Object.prototype.switch = function( switchTo ) {
if( !switchTo ) return { };
if( !switchTo[this] && !switchTo.default ) return { };
if( !switchTo[this] && switchTo.default ) return switchTo.default;
return switchTo[this];
Number.prototype.placeFormat = function( places, limited ) {
if( !places || places < 2 ) places = 2;
if( !limited ) limited = true;
var number = this.toString( );
if( number.length > places && limited == true ) return number.slice( 0, places - number.length );
// Requires prototype found at https://gist.github.com/ItzArty/96e7439a63ac3800335ecb72a63d255c
console.clear( );
if( !fs.existsSync('./logs') ) fs.mkdirSync('./logs');
var d = new Date( );
var logName = d.getDate( ).placeFormat( 2 ) + '-' + ( d.getMonth( ) + 1 ).placeFormat( 2 ) + '-' + d.getFullYear( );
var lastOwnProcessID = 0;
var ownProcesses = [ ];
// Logging feature can be enabled with https://gist.github.com/ItzArty/3d2c9653e74d0de1975ce3ed88e53227
function proc( command, options, outputCallback ) {
lastOwnProcessID++;
this.id = lastOwnProcessID;
@ItzArty
ItzArty / parseList.js
Created July 11, 2022 12:48
A JavaScript function to parse an output of mostly windowses command line if formatted as a list
function parseList( input ) {
var result = { };
input = input.replaceAll("\r", "").replaceAll("\x00", "").split("\n");
input.forEach( ( line, index, object ) => {
line = line.replaceAll(" ", "");
@ItzArty
ItzArty / formatTime.js
Last active July 28, 2022 18:22
Simple function to format seconds into human-readable string
// Requires prototype found at https://gist.github.com/ItzArty/96e7439a63ac3800335ecb72a63d255c
function formatTime( seconds, minutes, hours, forceHours ) {
if( !seconds ) seconds = 0;
if( !minutes ) minutes = 0;
if( !hours ) hours = 0;
if( !forceHours ) forceHours = false;
Array.prototype.last = function( ) {
return this[ this.length - 1 ];
}
function parseList( input ) {
if( !input ) return;
let parsed = [ ];
let divCounter = 0;
let spaceCounter = 0;
input = input.replaceAll("\r", "").split("\n");