Skip to content

Instantly share code, notes, and snippets.

Setting Up PostgreSQL Inside Docker

  • docker pull postgres
  • docker run --name postgres-test -e POSTGRES_PASSWORD=root -d postgres
  • docker exec -it postgres-test psql -U postgres
  • to exit : \q

Creating a Database

Untitled-2024-04-29-1438(1)

Aspect VirtualBox Docker
Virtualization Type Hardware (Full Virtualization) OS-Level (Containerization)
OS Requirement Each VM requires its own OS Containers share the host OS kernel
Resource Overhead Higher, due to multiple OS instances Lower, due to shared OS kernel
Startup Time Slower, due to full OS boot process Faster, containers start almost instantly
Isolation High, each VM is fully isolated High, but not as complete as VMs
  1. Backend Optimization:
    • Reduce the number of database queries by optimizing SQL queries, using indexes, and fetching only necessary data.
    • Redis Integration:
      • storing sessions
  2. Frontend Optimization:
    • Caching Resources:
      • using CDN
    • using a meta framework that can returns HTML to some components instead of JavaScript.
    • Data Caching with WebSockets
  • optimize Images

Test-Driven Development

Test-Driven Development (TDD) is a software development approach where tests are written before the actual code. The process follows these steps:

  1. Write a Test: Create a test for a new function or feature.
  2. Run the Test: The test will fail initially because the feature isn't implemented yet.
  3. Write Code: Write the minimal code needed to pass the test.
  4. Run the Test Again: Ensure the code passes the test.
  5. Refactor: Clean up the code while ensuring the test still passes.
  6. Repeat: Continue this cycle for each new feature or function.

There are many frameworks in the JavaScript ecosystem. This is not a comparison but a list of patterns used in different frameworks. I'll focus on React and Solid.

Untitled-2024-04-29-1438

@K3ndev
K3ndev / data-flow-next-tanstack.md
Last active April 5, 2024 06:35
Using next and tanstack-query in next.js

image

@K3ndev
K3ndev / why-graphQL.md
Last active February 19, 2024 12:47
why-graphQL

Reason 1: Over-fetching

  • Over-fetching occurs when a client retrieves more data than is actually needed for a particular task or view, resulting in wasted bandwidth and slower performance
  • Traditional RESTful APIs often suffer from over-fetching due to the fixed data structure returned by each endpoint, which may include unnecessary fields.
  • GraphQL addresses this issue by allowing clients to specify their data requirements upfront in a single query, reducing the likelihood of over-fetching by retrieving only the required data fields.

Reason 2: Under-fetching

to shutdown

  • wsl --shutdown

to install

  • wsl --install or search it inside of microsoft store

to remove an image

  • wsl --list
  • wsl --unregister <DistributionName>

immutable

  • ES5 (2009)

some()

const bool = arr.some(element => element > 3);
console.log(bool); // Output: true

every()