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:d333f77df4f33d76bd5b
Created February 24, 2016 09:11
php fluent interface pattern $obj->method1()->method2();
<?php
class User
{
protected $name;
protected $surname;
protected $password;
public function setName($name)
{
@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 / array_in_lenght
Created July 17, 2015 13:38
Return a size in bytes,kilobytes,megabytes and gigabytes for given array or string. Can be used if you want to check performance for some script.
<?php
function array_size($arr) {
$byte = 0;
foreach ($arr as $key => $val) {
$byte += is_array($val) ? array_size($val) : mb_strlen($val);
}
$kb = number_format($byte / 1024, 4);
$mb = number_format($byte / 1048576, 4);
$gb = number_format($byte / 1073741824, 4);
$result = array('Bytes: ' => $byte, 'Kilobytes: ' => $kb, 'Megabytes: ' => $mb, 'Gigabytes: ' => $gb);
@kirilkirkov
kirilkirkov / gist:fc6e20f9cee38031753d3828386f23f8
Created August 28, 2022 07:25
JavaScript - Destructuring To Get The First And Last Element Of An Array In ES6
The easiest lay to get first and last element from an array in javascript with one line code.
<script>
const meals = ['apple', 'orange', 'bananna'];
const {length, 0: first, [length - 1]: last} = meals;
console.log(first, last)
</script>
@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 / Fix Ugly Fonts in Netbeans under Linux
Created February 13, 2018 20:45
Fix Ugly Fonts in Netbeans under Linux
To enable anti-aliased fonts just for Netbeans, add -J-Dawt.useSystemAAFontSettings=on to the end of the netbeans_default_options line in /usr/share/netbeans/etc/netbeans.conf e.g.:
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dawt.useSystemAAFontSettings=on"
Alternatively, you can set this globally so that all AWT apps are affected, by setting the _JAVA_OPTIONS environment variable in your .bash_profile:
export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true'
This also has Swing equivalent, using the swing.aatext preference. You'll have to log out and log back in for this to take effect.
@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 / DER vs. CRT vs. CER vs. PEM Certificates and How To Convert Them
Created March 17, 2020 15:21
DER vs. CRT vs. CER vs. PEM Certificates and How To Convert Them
https://support.ssl.com/Knowledgebase/Article/View/19/0/der-vs-crt-vs-cer-vs-pem-certificates-and-how-to-convert-them
Certificates and Encodings
At its core an X.509 certificate is a digital document that has been encoded and/or digitally signed according to RFC 5280.
In fact, the term X.509 certificate usually refers to the IETF’s PKIX Certificate and CRL Profile of the X.509 v3 certificate standard, as specified in RFC 5280, commonly referred to as PKIX for Public Key Infrastructure (X.509).
X509 File Extensions
@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 / 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
);