Sunday, October 23, 2022

Random array items generator

Generate n random posts from array:

const n = 4; // n random posts generator
const randomPosts = (function getRandomInt(max) {
return Math.floor(Math.random() * max);
})(posts.length - n);

{posts.slice(randomPosts, randomPosts + n).map(...}

//

Add and append HTML elements in React

Append arr2 elements to arr: (8) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]

(arr) => arr.concat(gerArr2())

Append arr2 array to arr: (4) [Array(4), Array(4), Array(4), Array(4)]

(arr) => [...arr, gerArr2()]

Save search term state to React Hooks with spread operator and wrapper function

// Using .concat(), no wrapper function (not recommended)
setSearches(searches.concat(query))

// Using .concat(), wrapper function (recommended)
setSearches(searches => searches.concat(query))

// Spread operator, no wrapper function (not recommended)
setSearches([...searches, query])

// Spread operator, wrapper function (recommended)
setSearches(searches => [...searches, query])

https://stackoverflow.com/questions/54676966/push-method-in-react-hooks-usestate

https://javascript.plainenglish.io/how-to-add-to-an-array-in-react-state-3d08ddb2e1dc

https://www.skptricks.com/2018/06/append-or-prepend-html-using-reactjs.html

Friday, October 21, 2022

Toggle burger menu with buttons

//

const toggleClick = () => {
document.querySelector('nav').addEventListener('click', (e) => {
let parent = e.target.parentNode;
if (parent.classList.contains('logo') || parent.tagName === 'LI') {
console.log('toggle');
}
});
};

//

Key event to focus box with keyboard

Focus search-box with keyboard key:

(function focusSearch() {
document.addEventListener(
'keypress',
(e) => {
const name = e.key;
const code = e.code;
console.log(`Key pressed ${name} \r\n Key code value: ${code}`);
console.log(e);
if (e.code === 'Enter') {
window.scrollTo(0, 0, { behavior: 'smooth' }); // scroll to top
document.querySelector('.search').focus();
}
},
false
);
})();

//

Thursday, October 20, 2022

Uncaught (in promise) error

TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator)) 

Promise.all(fetch...etc)

Wrap fetch() with []

Promise.all([fetch...etc])

//

Система опалення з природною циркуляцією

Природна циркуляція в опалювальній системі працює наступним чином: рідина спочатку нагрівається в опалювальному котлі а потім по головному стояку піднімається вгору. Підніматися її змушує різницю температур, крім цього її підштовхує остившая рідина, яка повертається в котел.

Прокладати з нахилами та додати помпу.

https://www.youtube.com/watch?v=tQqw5Qb6uHY

https://www.youtube.com/watch?v=QeAsobkx3XM

https://otivent.com/uk/sistema-opalennya-z-prirodnoju-cirkulyacijeju

Use console command from bash history

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

history n // n === number

history | grep nvidia

history