Skip to content

Instantly share code, notes, and snippets.

View codeWithNks's full-sized avatar

Neeraj Sharma codeWithNks

View GitHub Profile
@codeWithNks
codeWithNks / README.md
Created January 14, 2025 09:27 — forked from piyushgarg-dev/README.md
Kafka Crash Course
const NUM_VIRTUAL_NODES = 3; // Number of virtual nodes per physical server
// Extending ConsistentHashing to add virtual nodes
class ConsistentHashingWithVirtualNodes extends ConsistentHashing {
// Overriding the addServer method to add virtual nodes
addServer(serverId) {
// For each physical server, create multiple virtual nodes
for (let i = 0; i < NUM_VIRTUAL_NODES; i++) {
const virtualNodeId = `${serverId}#${i}`; // Virtual node is a combination of the server ID and index
super.addServer(virtualNodeId); // Add virtual node to the ring

1. What is the difference between Named Export, Default Export, and * as export?

  • Named Export:
    • Definition: Exports specific variables or functions by their names.
    • Usage: You import them using the same name in another file.
    • Example:

1. What is a Microservice?

  • Definition: A microservice is an independent, self-contained service that handles a specific function of an application.
  • Key points:
    • Each microservice runs on its own.
    • Services communicate with each other through APIs.
    • It can be scaled or updated independently.
  • Example: An e-commerce platform with separate microservices for user management, product catalog, and payment processing.
@codeWithNks
codeWithNks / show-me-code.md
Created December 31, 2024 13:32
About props, config-driven

1. Is JSX mandatory for React?

  • No, JSX is not mandatory, but it is widely used for its readability and simplicity.
  • Without JSX:
    React.createElement('h1', null, 'Hello World');
  • With JSX:
    <h1>Hello World</h1>
@codeWithNks
codeWithNks / Components.md
Last active December 30, 2024 14:25
JSX, Components

{TitleComponent} vs {<TitleComponent />} vs {<TitleComponent></TitleComponent>} in JSX

Syntax Description Example Is Content Rendered? Output/Behavior Use Case
{TitleComponent} Refers to the component itself (not its output). This is used for passing or referencing the co

1. NPM (Node Package Manager)

  • A package manager for JavaScript.
  • Manages libraries, tools, and dependencies.
  • Comes with Node.js.
  • Key commands:
    • npm install [package]: Install a package.
    • npm init: Create a package.json file.
    • npm run [script]: Run custom scripts from package.json.

Here’s how you can use npx with Parcel, a popular web application bundler, without needing to install it globally.


Scenario 1: Use Parcel without Global Installation

You want to bundle a JavaScript file using Parcel, but you don’t want to install it globally.

Command:

npx parcel index.html

1. Tilde (~)

  • Allows patch-level updates but keeps the minor and major versions fixed.
  • It’s strict about not allowing any changes to the minor or major versions.

Example: ~4.17.1

  • Matches: >= 4.17.1 and < 4.18.0
  • Allowed: 4.17.2, 4.17.3
@codeWithNks
codeWithNks / Inception.md
Last active December 30, 2024 14:08
Basics of react-ep1

Sure, I'll explain these concepts with code examples where applicable.

  1. What is Emmet? Emmet is a plugin for text editors that allows you to write abbreviations and then expand them into full-fledged HTML, CSS, and even JavaScript code. It saves time and improves productivity by reducing the amount of code you need to write manually. Here's an example:
<!-- Emmet abbreviation -->
nav>ul>li*5>a