Skip to content

Instantly share code, notes, and snippets.

View SeLub's full-sized avatar
🎯
Focusing

Sergey Lubimov SeLub

🎯
Focusing
View GitHub Profile

Cryptography Functions and Parameters:

Cryptography is the practice of securing information by transforming it into a secret code that can only be decoded by authorized parties using specific cryptographic algorithms and keys. The primary objectives of cryptography are confidentiality, integrity, and authenticity. Below, we outline some common cryptographic functions along with their parameters:

1. Symmetric Encryption (AES - Advanced Encryption Standard)

Purpose: Ensures confidential communication between two parties by encrypting data using a single key. Parameters:

  • Key Size: Determines the strength of the encryption algorithm, typically measured in bits (e.g., 128, 256). Larger keys provide more security but reduce efficiency.
  • Mode of Operation: Defines how the data is processed within the block cipher (e.g., CBC, ECB, GCM). Common modes include Cipher Block Chaining (CBC) and Galois/Counter Mode (GCM), which offer better security than Electronic Codebook (ECB).
  • **Padding Sc

UUID vs CUID

UUID (Universally Unique Identifier)_ and CUID (Collision-resistant Unique Identifier) are both methods for generating unique identifiers, but they differ in their design and intended use cases.

UUID:
Definition:
A 128-bit number used to uniquely identify information in computer systems.

Characteristics:

@SeLub
SeLub / cluster.md
Created October 2, 2025 10:42
How Clustering Works in Node.js

When using clusters in Node.js, it's important to understand how clustering works and whether or not a load balancer is necessary. Clustering allows you to create multiple server instances that share the same port, which can be beneficial for utilizing multi-core systems. However, this does not inherently provide any load balancing capabilities on its own.

How Clustering Works in Node.js

When you use cluster module in Node.js, it forks several child processes to handle incoming connections. Each fork listens on the same port and can receive requests for different parts of your application. Here's a basic example:

const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;

How to restrict API access to our backend

Here are several approaches to restrict API access to our frontend:

CORS Policy Configuration:

import cors from '@fastify/cors';

fastify.register(cors, {
@SeLub
SeLub / how_to_strucure_nodejs_project.md
Created February 8, 2025 09:59
How to structure project

How to structure NodeJS project

Possible structures:

File structure

1. Domain-Driven Structure:

src/
├── domains/

Binary Search Task

Task: We have an array sorted in ascending order:

a = [ 3, 4, 6, 9, 10, 12, 14, 15, 17, 19, 21 ]; Define a function f(a, x) that would return x, the nearest smallest number, or -1 on error.

Example:

Task

console.log '1' after 1 second,
'2' after 2 seconds and
'3' after 3 seconds after start of the program.

setTimeout

The delay parameter only guarantees that your callback will not execute before that time has elapsed. Other queued tasks or operations could delay it further than the specified time.

const startTime = process.hrtime();
@SeLub
SeLub / gist:f3d61ae628d500e022f28822ad611127
Last active February 8, 2024 06:23
Remove or recover last commit pushed to git

Delete last commit from git

First way

git reset --hard HEAD~1
git push --force

Another way