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 / 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 February 20, 2024 08:27
"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]);
@kirilkirkov
kirilkirkov / php-chatgpt-curl.php
Last active February 21, 2023 16:58
Access ChatGPT through PHP Using Curl Api. Easy Use of GPT3 API with Curl
<?php
define("CHATGPT_API_KEY", "your-key-goes-here");
$data = array(
"model" => "text-davinci-003",
"prompt" => "What is PHP and how it works?", // Your question or request
"temperature" => 0.5,
"max_tokens" => 500
);
@kirilkirkov
kirilkirkov / class-click-outside.js
Last active February 4, 2023 11:40
DOM Element Click OutSide handler with Vanilla JS. Easy integration in Vue or React. ES6 Import Module Type
/**
* Make new class instance for each element
*/
class ClickOutSide {
constructor() {
this.outsideHandler = null
this.element = null
this.documentEvent = (evt) => {
const flyoutEl = this.element
let targetEl = evt.target // clicked same el
@kirilkirkov
kirilkirkov / unit-vs-feature-test.md
Created December 1, 2022 13:06
Laravel tests simple explain in two words..

What is unit test?

Unit Tests are written from a programmers perspective. They are made to ensure that a particular method (or a unit) of a class performs a set of specific tasks.

What is feature test?

Functional Tests are written from the user's perspective. They ensure that the system is functioning as users are expecting it to.

@kirilkirkov
kirilkirkov / JavaScript-Stranges.md
Created November 25, 2022 09:04
We All Love JavaScript with its stranges..

JavaScript Strange Behaviors

  • console.log(typeof NaN) // Number
  • console.log(Math.min() > Math.max()) // TRUE
  • console.log(9 - '1') // 8
  • console.log(9 + '1') // 91
  • console.log(Boolean(0.1 + 0.5 === 0.6)) // TRUE
  • console.log(Boolean(0.1 + 0.2 === 0.2)) // FALSE
  • console.log(! + []) // TRUE
@kirilkirkov
kirilkirkov / Streams-VS-Buffer.md
Last active November 19, 2022 15:53
When to use streams and when buffer - Usage in NodeJS

Whats the difference between Streams and Buffer?

  • Buffer is temporary placeholder in memory (ram/disk) on which data can be dumped and then processing can be done.
  • Stream is a sequence of data elements. like when you typing something in your computer then when you press the keys it will form a data stream and then it goes to the processor for processing.

Stream can be processed through Buffer.

What are buffers and streams in REST API?

A buffer is a temporary memory that a stream takes to hold some data until it is consumed.

@kirilkirkov
kirilkirkov / docker-cmd-and-run-commands-explain.md
Created November 14, 2022 18:03
Whats the difference between cmd and run in Dockerfile

RUN - command triggers while we build the docker image.

CMD - command triggers while we launch the created docker image.


RUN EXPLAIN: RUN is an image build step, the state of the container after a RUN command will be committed to the container image. A Dockerfile can have many RUN steps that layer on top of one another to build the image. RUN: Commands May not Execute if Images are Cached.

@kirilkirkov
kirilkirkov / gist:60ff6d27b2a2da03d42cde85281f6330
Created September 7, 2022 15:46
Instagram in-app browser (WebView) errors with window.opener or window popups
Did you know that instagram webview (when click some link from private message or post) , the window.opener is null?
This is privacy reason.. so if you wants to close window popups, should use history.back(); instead of window.close();,
also the postMessage will not works with window.opener.postMessage ....