Skip to content

Instantly share code, notes, and snippets.

View kirilkirkov's full-sized avatar
🎯
Focusing

Kiril Kirkov kirilkirkov

🎯
Focusing
View GitHub Profile
@kirilkirkov
kirilkirkov / gist:ea094f1eb589e65e176a0e79a4810ea6
Created February 12, 2024 13:50
CSS ONLY DROPDOWN ANIMATION WITH TAILWINDCSS
<ul>
<li>Test</li>
<li class="group">
<button>Proba</button>
<div
class="grid grid-rows-[0fr] transition-[grid-template-rows] duration-700 group-hover:grid-rows-[1fr] [&>*]:overflow-hidden">
<ul class="row-[1_/_span_2] space-y-2 [&>li:first-child]:pt-2 [&>li:last-child]:pb-2">
<li>Proba submenu</li>
<li>Proba submenu</li>
<li>Proba submenu</li>
@kirilkirkov
kirilkirkov / no-opcache.md
Last active September 14, 2023 13:34
Sequence of Processing When Opening a Website with NGINX and PHP

Sequence of Processing When Opening a Website with NGINX and PHP (No Opcache Activated)

**Client's Browser**
    |
    |   DNS
    |
    v
**Website Server**
 |
@kirilkirkov
kirilkirkov / nextjs-ssr-prefetch-example.md
Last active June 10, 2024 10:07
"Understanding Next.js: Prefetching, Server-Side Rendering, and Data Fetching for Dynamic Pages"
// pages/index.js

import Link from 'next/link'

export default function HomePage() {
  return (
    <div>
      <h1>Welcome to our news site!</h1>
      <ul>
@kirilkirkov
kirilkirkov / react-useEffect-fast-state-update.md
Created June 14, 2023 20:33
Handling Asynchronous State Updates in React: The Functional Form of setState

Do you know that if you call setIndexes([...indexes, index]); too fast.. one after another time.. its possible only to update the array, but not to increment it?

The problem you're facing may be due to the asynchronous nature of the setState function in React. When using the useState hook, the setState function doesn't update the state immediately, but during the next render of the component.

Your logic for adding values to the setIndexes array can looks correct but.. However, when you use setIndexes([...indexes, index]), you're actually accessing the previous value of uploadedFiles, which may not be updated yet.

To solve this issue, you can use the functional form of setState, where you take the previous value of the indexes array and add the new value to it. Here's an example:

setIndexes((prevIndexes) =&gt; [...prevIndexes, index]);

How public and private class access modifiers are compiled to javascript in typescript

public: The public access modifier in TypeScript does not result in any changes during compilation. This is because in JavaScript, all class members are by default considered public. Therefore, a public member in a TypeScript class remains unchanged in the resulting JavaScript code.

// Example TypeScript code:

За да използвате проверка за логнат потребител за всяка страница в Next.js, можете да използвате High Order Component (HOC) или wrapper component, който да включва функцията getServerSideProps. Така ще можете да използвате тази проверка на всяка страница, която искате да бъде достъпна само за логнати потребители.

Ето пример как може да създадете HOC, който да включва getServerSideProps за проверка на потребителското състояние:

import { useRouter } from 'next/router';

export const withAuth = (WrappedComponent) => {
  const Wrapper = (props) => {
    const router = useRouter();

PHP vs NodeJS threads and process

PHP по подразбиране използва един процес за всяка заявка за уебстраница. Този процес съдържа единствена нишка за обработка на заявката и това е единствената нишка, която може да използва PHP скрипта.

Node.js от друга страна използва един процес с множество нишки за обработка на заявки. Тези нишки са създадени от Node.js за да могат да обработват заявки едновременно, като всеки потребителски заявка се обработва от отделна нишка.

@kirilkirkov
kirilkirkov / promises-with-async-await.js
Last active October 10, 2024 05:51
Explain Promises with Async/Await and new Promise constructor. How to handle reject with Await keyword
async function getResp() {
try {
const authors = await getPromise(true);
console.log(authors, 'Try')
} catch(e) {
console.log(e, 'Catch')
}
}
function getPromise(resolveIt) {
@kirilkirkov
kirilkirkov / vue-this-examples.js
Last active October 10, 2024 05:51
How this works in VueJS
// In Browser - Window Object
// In Node - {}
console.log(this)
// In Browser - Window Object
// In Node - Node Object
function globalScoped() {
console.log(this)
}
globalScoped()
@kirilkirkov
kirilkirkov / react-rerender.js
Last active October 10, 2024 05:52
Example of how Vue and React works when change their states - in react all javascript is executed, in Vue only the template.
import React, { useState, useEffect } from 'react';
function App() {
const [count, setCount] = useState(0);
// execute each time when click the button
console.log(Math.random())
useEffect(() => {
// execute each time when click the button