Thursday, October 20, 2022

Use console command from bash history

history !n // then Home, delete 'history', edit command and Enter

history n // n === number

history | grep nvidia

history

Many identical console.logs in DevTools

Comment <React.StrictMode> in index.js

root.render(
// <React.StrictMode>
<App />
// </React.StrictMode>
);

After fetch console.log in React component like this:

const function = () => (
<>
{console.log(data)}
</>
);

return (function())

Before return getting {} and {data} after fetch...

Wednesday, October 19, 2022

rsync remote and local file copying command

Copy and overwrite older files only while showing progress:

rsync -rahP --info=progress2 --stats -u /source/folder/'My Folder'/ /destination/folder/'My Folder'/

    --existing              skip creating new files on receiver
    -u, --update            skip files that are newer on the receiver


Ctrl + Z => stop rsync process // -P => (-rahP)

Resume rsync process // fg %[number] – resume job [number]

fg 1 rsync -rahP --info=progress2 --stats -u /source/folder/'My Folder'/ /destination/folder/'My Folder'/


jobs – list the current jobs
fg – resume the job that’s next in the queue
fg %[number] – resume job [number]
bg – Push the next job in the queue into the background
bg %[number] – Push the job [number] into the background
kill %[number] – Kill the job numbered [number]
kill -[signal] %[number] – Send the signal [signal] to job number [number]
disown %[number] – disown the process(no more terminal will be owner), so command will be alive even after closing the terminal.

Cleanup after failed rsync:
find -type f -iname ".*.*.??????" -ls
find -type f -iname ".*.*.??????" -delete
https://www.tectut.com/2021/11/how-to-pause-and-resume-rsync/
https://manpages.ubuntu.com/manpages/trusty/man1/rsync.1.html
https://unix.stackexchange.com/questions/117190/best-way-to-sync-files-copy-only-existing-files-and-only-if-newer-than-target

Tuesday, October 18, 2022

clickHandler is not a function

Pass empty function to onClick as temporary solution:

const falseClick = () => {};

//

Remove first element from an array

Use slice(start, end) method:

const arr = ['a', 'b', 'c'];
const withoutFirst = arr.slice(1);

https://bobbyhadz.com/blog/javascript-remove-first-element-from-array

Can't get array length after fetch object destructuring

Cannot read properties of undefined (reading 'length'):

const { posts = [] } = data; // destructuring array from data
console.log(posts.length);

https://bobbyhadz.com/blog/javascript-cannot-read-property-length-of-undefined

const { data: { posts } = [] } = data; // extract arr didn't work out
const arr = posts || []; // empty array fallback
console.log(arr.length); // getting error in React

In React console.log after fetch like this:

const postsData = () => (
<>
{console.log(posts.length)}
</>
);
return (postsData());

https://leocode.com/development/how-to-deal-with-async-await-in-the-array-functions/

Monday, October 17, 2022

Events in JavaScript

If parent node contains 'logo' in className => class="logo":

if (e.target.parentNode.classList.contains('logo')) { }

If parent node contains <li></li> TAG:

if (e.target.parentNode.tagName === 'LI') { }

console.log(e.target); // show clicked target

console.log(e); // show event

https://www.section.io/engineering-education/keyboard-events-in-javascript/

https://stackoverflow.com/questions/7723188/what-properties-can-i-use-with-event-target