Skip to content

Instantly share code, notes, and snippets.

View kirilkirkov's full-sized avatar
👽
writing alien code..

Kiril Kirkov kirilkirkov

👽
writing alien code..
View GitHub Profile
@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
@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 / npm-vs-npx-in-nodejs.markdown
Last active October 10, 2024 05:52
Difference between NPM and NPX (NodeJS)

What is the difference between node npm command line and npx command line?

These are two different cli tools as part of your nodejs installation. Their goal is to make our work with JavaScript packages easier. The main difference is that npm is the actual package manager, but npx is used to execute the JavaScript packages.

What is NPM?

NPM means Node Package Manager, this is the default package manager for nodejs. If you have installed nodejs in your machine, then you will have available npm in yours command line\cli (terminal, dos). It interact with the online

@kirilkirkov
kirilkirkov / vue-performance.markdown
Last active October 10, 2024 05:52
Vue Performance - Better Writing of your code to be faster - Best Practices for Development

Lazy Loading Of Components

Lazy loading means to separate functionalities of the application in separate files. Eg. Modal window which is showing in the website, instead to load it everywhere in the website, we can load it only when needs.

Example:

// app.js
@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 ....