Monday, 25 October 2021

PHP chgrp function

 https://www.php.net/manual/en/function.chgrp.php


chgrp(string $filenamestring|int $group): bool

Attempts to change the group of the file filename to group.

Only the superuser may change the group of a file arbitrarily; other users may change the group of a file to any group of which that user is a member.

PHP or syntax function

 https://stackoverflow.com/questions/9535255/php-or-syntax



Let's just say that:

$result = first() || second();

will evaluate to:

if (first()) {
    $result = true;
} elseif (second()) {
    $result = true;
} else {
    $result = false;
} 

while:

$result = first() or second();

will evaluate to:

if ($result = first()) {
    // nothing
} else {
    second();
}

In other words you may consider:

$result = first() || second();

$result = (first() || second());

and:

$result = first() or second();

to be:

($result = first()) || second();

It is just matter of precedence.

Thursday, 21 October 2021

JavaScript = Check if array contains at least one element of another array

 https://stackoverflow.com/questions/16312528/check-if-an-array-contains-any-element-of-another-array-in-javascript

    // Check if arra1 contains at least 1 element of arr2

const found = arr1.some(r=> arr2.includes(r))

some(..) checks each element of the array against a test function and returns true if any element of the array passes the test function, otherwise, it returns false. indexOf(..) >= 0 and

Wednesday, 20 October 2021

Javascript Decode encoded html entities in a JSON object into decoded ones

https://gomakethings.com/decoding-html-entities-with-vanilla-javascript/ 


HTML entities such as <p>In this course, you'll learn:</p> is usally encoded in JSON string as 

&lt;p&gt;In this course, you&amp;rsquo;ll learn:&lt;/p&gt; to avoid quots "" errors in JSON string



To decode HTML entites (to get <p>) back in JS so that it is properly shown in a web page(If do not decode HTML entities browser will show HTML tag <p> as text instead of having any effects),


we will need to utlize textarea, as getting values in text area will automatically be converted into decoded HTML entities


// Create globally used textarea

var domTextArea =  document.createElement('textarea');


// Function that takes a JSON object, and recursively decode encoded HTML entities if needed        

decodeHTML(testObj) {

   

            for (var key in testObj) {

                if (typeof (testObj[key]) == 'string') {

                    domTextArea.innerHTML = testObj[key];

                    testObj[key] = this.domTextArea.value;

                    continue;

                }


                this.decodeHTML(testObj[key]);


            };

        },



NOTE: for (var key in testObj) will also work for array :


var a = [1,2,3];


for (var key in a) { console.log(a[key]) }

// Output:

 1

2

 3


Tuesday, 19 October 2021

Remote Desktop get to lock screen

 ctrl alt delete does not work on remote desktop for lock screen



use ctrl alt end 


https://serverfault.com/questions/57222/how-to-send-ctrlaltdel-using-remote-desktop

RXJS, finalize is same as finally can only be used whe observable complete or subject completes

 Observable automatically completes after emission for example of(1), observer=> observer.next(1) hence for observable, usally piple(fianlize()) can always be used. Note finalize is always called in the end when observable completes.



For subject, it does not complete after next, subject.next(1), subject.next(2), it can keep emitting, for subject to complete use

var complete  = subject.piple(take(1))



https://stackoverflow.com/questions/49735826/rxjs5-finalize-operator-not-called


For some observable, it may not always be completed after emission such as this.route.queryParams,


Need to call  this.route.queryParams.pipe(take(1)),



https://stackoverflow.com/questions/49735826/rxjs5-finalize-operator-not-called

Thursday, 14 October 2021

Git 'fatal: Unable to write new index file'

 https://stackoverflow.com/questions/16064513/git-fatal-unable-to-write-new-index-file


the disk ran out of space, so I had to delete files from the hard drive to make space.