URLs "p1" – 82 resources

I am an avid WWW surfer, with hundreds of websites visited each month, sometimes daily. I bookmark them all, at least for logging purposes. These posts having the "urls" category, capture what was on my browser on a specific date. I hope you enjoy some of these shared resources.


URLs "p1" 20190708 – 77 great readings

I am an avid WWW surfer, with hundreds of websites visited each month, sometimes daily. I bookmark them all, at least for logging purposes. These posts having the "urls" category, capture what was on my browser on a specific date. I hope you enjoy some of these shared resources.


Listening to Chris Forsyth – "Tomorrow Might as Well Be Today"

The wind of good fortune brought me the music of Chris Forsyth. By chance, I just discovered his latest album. This is a mostly instrumental piece, with punctual singing. It is different, even experimental, yet without unpleasant ruptures. The audio in this album paints a very “full” stage, with few opportunities for silence, but it does not get tiring, instead involving and flowing through the listener. At times, it remembers me the early Pink Floyd.

Listening to Diego Trip – "Al Espacio"

A surprising album, sung in Spanish. I usually prefer strictly instrumental albums, yet I cannot resist quality lyrics, in this case framed in what feels like a well-researched landscape of conservative-to-modern arrangements. “Al Espacio” (which translates to “To the Space”) is a superb, often original, album! Non-monotonous tracks, sung by a male vocalist, but with its instruments-only moments.

Again, I am not listening to it on Spotify, but I cannot find a better way to share its playlist:

URLs "p1" 20190706 – 56 great resources, from science to money

I am an avid WWW surfer, with hundreds of websites visited each month, sometimes daily. I bookmark them all, at least for logging purposes. These posts having the "urls" category, capture what was on my browser on a specific date. I hope you enjoy some of these shared resources.


URLs "p1" 20190705 – 80 superb readings

Great resources I opened and eventually read in the past 2 days, on a wide range of subjects: science, podcasts, environment, racing, literature, etc.

I am an avid WWW surfer, with hundreds of websites visited each month, sometimes daily. I bookmark them all, at least for logging purposes. These posts having the "urls" category, capture what was on my browser on a specific date. I hope you enjoy some of these shared resources.


Listening to Mnemonic – "Aversionen"

I am listening to “Mnemonic” (artist), album “Aversionen”, but not on Spotify.

This “Mnemonic” is an artist with just 18 monthly listeners on Spotify. This should highlight how incredibly hard is for creators, in any field of activity, to be recognized, even when producing good to great art, as is the case. The “sheeping” behavior on humans is such that people tend to flock and form clusters on everything, including music consumption, giving rise to unjust asymmetries in the “market of attention”.

It was not trivial to find the right “Mnemonic” artist on Spotify. There are at least two artists named “Mnemonic”, both in the electronic music genre, both worth listening.

There is
“Mnemonic” (NOT the author of “Aversionen”):

and there is the author of what I am listening to:
“Mnemonic”:

Here is the playlist of “Aversionen”, a rhythmic bassy album with exotic, quality, mixes:

File system organization automation – moving thousands of files

I am trying to organize large thousands of files.
The task is not healthy if done by hand; moreover, it is prone to human error. So, I wrote an automated solution, using PHP and some of its file system calls.

The problem is described in the main function comments, here shared in this post. Imagine thousands of folders, each eventually containing a single specially named sub-folder (e.g. “_”) whose contents (files and directories) you want to move to its parent root. This was interesting to write because it shows the power of a language’s file system tools for automation in files organization.

Check the “before” and “after” images for the simplest example I managed to capture in a visual representation.

/*
 * 2019-07-04 started
 * 2019-07-04 first tested ok - test preserved in file "test_20190704.php"
 * learned: https://www.php.net/manual/en/class.splfileinfo.php
 * the idea is to move the contents in <some folder>\_\<contents> to <some folder>\<contents>
 * the "_" is the product of a rename "shortener" tool - it facilitates in avoiding very long paths that result from some jobs
 * however, some archives when unpacked will still have sub-folders inside the _ folder
 * and that organization creates problems to other tools of mine
 * this function should received a folder F path, of a folder which might contain a "_" named sub folder
 * then it will move _'s files and folders to the F's root
 *
 * @param string $pStrFolderPath : some folder path
 * @param string $pStrSpecificNameOfSubFolderWhoseContentsAreToBeMovedToParentFolder : optional, the name of the special folder, defaults to "_"
 * @param bool $pbFeedback : verbose activity, giving feedback to user? Defaults to true
 * @param bool $pbCaseSensitive : case sensitive in checking the folder? Default to false and is not relevant for folders with names like "_"
 * @return int : the number of successful ren/move operations
 */
function moveEverythingInFolderWithSpecificNameIfItExistsInPathToItsParentFolder (
    string $pStrFolderPath,
    string $pStrSpecificNameOfSubFolderWhoseContentsAreToBeMovedToParentFolder = "_",
    $pbFeedback=true,
    $pbCaseSensitive = false
)
{
    $bPathExists=file_exists($pStrFolderPath);
    $iSuccessfulRenamesCounter=$iFailedRenames=0;

    if ($pbFeedback){
        feedbackOnFunctionCall(
            __FUNCTION__,
            func_get_args()
        );
    }//if

    if ($bPathExists) {
        //dirsInDir does NOT return the dots dirs . and ..
        $dirsInDir = dirsInDir(
            $pStrFolderPath,
            false //not recursive
        );
        $iHowManyDirsInDir = count($dirsInDir);
        $bRightNumberOfDirs = ($iHowManyDirsInDir === 1); // $pStrSpecificNameOfSubFolderWhoseContentsAreToBeMovedToParentFolder

        //there should be only 1 dir if the move op is to be safe in preserving the contents' hierarchy
        if ($bRightNumberOfDirs) {
            $oSingleDirItemObject = $dirsInDir[0];
            $strDirName = $oSingleDirItemObject["fname"];

            $bFolderHasTheSearchedForName =
                $pbCaseSensitive ?
                    //sensitive
                    strcmp(
                        $strDirName,
                        $pStrSpecificNameOfSubFolderWhoseContentsAreToBeMovedToParentFolder
                    ) === 0

                    :
                    //insensitive
                    strcasecmp(
                        $strDirName,
                        $pStrSpecificNameOfSubFolderWhoseContentsAreToBeMovedToParentFolder
                    ) === 0;

            $oParentFolderPath = new SplFileInfo ($pStrFolderPath);
            $strParentDirectoryFullPath = $oParentFolderPath->getRealPath();

            if ($bFolderHasTheSearchedForName) {
                $strOldLocationOfSearchedFolder = $oSingleDirItemObject["realPath"];

                //dirItems is a function of mine, returning an assoc array representing each dir in a path, except the dot dirs (. and ..)
                $aItemsInSearchedFolder = dirItems(
                    $strOldLocationOfSearchedFolder,
                    "*",
                    false //not recursive
                );

                foreach ($aItemsInSearchedFolder as $itemAsAssocArray) {
                    $strOldLocationOfSearchedFolder = $itemAsAssocArray["realPath"];
                    $strItemName = $itemAsAssocArray["fname"];
                    $strNewLocationForSearchedFolderContents = $strParentDirectoryFullPath . "\\" . $strItemName;

                    $bRenameMoveItemOK = rename(
                        $strOldLocationOfSearchedFolder,
                        $strNewLocationForSearchedFolderContents
                    );
                    if ($bRenameMoveItemOK) {
                        $iSuccessfulRenamesCounter++;
                    }//if ok
                    else {
                        echo "Failed in moving $strOldLocationOfSearchedFolder to $strNewLocationForSearchedFolderContents" . PHP_EOL;
                        $iFailedRenames++;
                    }//else
                }//foreach item in folder

                $strFullPathOfSearchedFolder = $oSingleDirItemObject['realPath'];
                $aItemsInSearchedFolder = dirItems($strFullPathOfSearchedFolder);
                $bEmptyFolder = count($aItemsInSearchedFolder)===0;
                if ($bEmptyFolder){
                    $rmResult = rmdir($strFullPathOfSearchedFolder); //return not used, but it is a bool
                }//if
            }//if found the searched folder
        }//if there is exactly 1 folder in the path
    }//if path exists

    return $iSuccessfulRenamesCounter;
}//moveEverythingInFolderWithSpecificNameIfItExistsInPathToItsParentFolder



mover_after.png
https://arturmarques.com/wp/wp-content/uploads/2019/07/mover_after.png (image/png)

mover_after.png


mover_before.png
https://arturmarques.com/wp/wp-content/uploads/2019/07/mover_before.png (image/png)

mover_before.png

Technical Details