menu

Search By Label

Cross Join in PostgreSQL is like a full outer join, but without any matching condition. It simply combines every row from the first table with every row from the second table, creating a result set that is the product of the number of rows in both tables.

Example:

Let's say you have two tables:
  • Customers with columns customer_id and name
  • Products with columns product_id and name

A cross join between these two tables would produce a result set where every customer is paired with every product. This could be useful if you want to generate a list of all possible combinations of customers and products, perhaps for a recommendation system or a marketing campaign.

SELECT customers.customer_id, customers.name, products.product_id, products.name
FROM customers
CROSS JOIN products;

This query would create a table with a row for every combination of customer and product, showing each customer's ID and name along with each product's ID and name.
You could use a regular expression with .replace() to match everything from the start of your string up until the first dot ., and replace that with an empty string.

var str = "P001.M003.PO888393"; 
var res = str.replace(/^[^\.]*\./, '');
console.log(res);

Output: 
#=> M003.PO888393

If you need to create an initial array with default values and specific length you can use:
arr = new Array(3).fill(0)
Push your docker image using the tag.
docker push NAME[:TAG]


Tagging an image in Docker is important for the following reasons:
  • Version control: Tags help identify different versions of an image.
  • Traceability: Tags allow you to track changes and updates to an image.
    Automation: Tags are used in automated processes, such as deploying new versions.
    Troubleshooting: Tags help pinpoint specific image versions when debugging.
    Managing large-scale projects: Tags organize images in complex projects.

docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]

Example:
docker tag 518a41981a6a myRegistry.com/myImage


A GET request expresses the user's intent to not have any side effects. Naturally, there will always be side effects on the server like log entries for example, but the important distinction here is whether the user had asked for a side effect or not.

Another reason to stay away from GET surfaces if you respond with the recommended 201 Created response for a request where the resource is being created on the server. The next request would result in a different response with status 200 OK and thus it cannot be cached as is usually the case with GET requests.

Instead, I would suggest to use PUT, which is defined as

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI.

If a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response. If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request. If the resource could not be created or modified with the Request-URI, an appropriate error response SHOULD be given that reflects the nature of the problem.
In the above form, it should be considered a "create or update" action.

To implement pure "get or create" you could respond with 409 Conflict in case an update would result in a different state.
However, especially if you are looking for idempotence, you might find that "create or update" semantics could actually be a better fit than "get or create". This depends heavily on the use case though.

source: https://stackoverflow.com/questions/21900868/best-http-method-for-get-or-create#:~:text=I'm%20writing%20an%20HTTP%20based%20API,%20and%20I%20have%20a
You can intercept requests or responses before they are handled by then or catch.
// Add a request interceptor
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  });
usePathname is a Client Component hook that lets you read the current URL's pathname.

'use client'

import { usePathname } from 'next/navigation' 

export default function ExampleClientComponent() {  
  const pathname = usePathname()  
  
  return <p>Current pathname: {pathname}</p>
}

usePathname intentionally requires using a Client Component. It's important to note Client Components are not a de-optimization. They are an integral part of the Server Components architecture.

A interesting way to use it is like to modify the classNames in active routes as:

<Link 
  key={link.name}
  href={link.href}            
  className={clsx(              
     'flex h-[48px] grow items-center justify-center gap-2 rounded-md bg-gray-50 p-3 text-sm font-medium hover:bg-sky-100 hover:text-blue-600 md:flex-none md:justify-start md:p-2 md:px-3',
    {               
      'bg-sky-100 text-blue-600': pathname === link.href,
     },            
    )}         
   >            
   <LinkIcon className="w-6" />            
     <p className="hidden md:block">{link.name}</p>          
</Link>

In sofware and tech idempotency typically refers to the idea that you can perform an operation multiple times without triggering any side effects more than once.

Here's the main facts you need to know about idempotency:

  • Idempotency is a property of operations or API requests that ensures repeating the operation multiple times produces the same result as executing it once.
  • Safe methods are idempotent but not all idempotent methods are safe.

  • HTTP methods like GET, HEAD, PUT, DELETE, OPTIONS, and TRACE are idempotent, while POST and PATCH are generally non-idempotent.


Source: https://blog.dreamfactory.com/what-is-idempotency#:~:text=Idempotency%20is%20a%20property%20of,all%20idempotent%20methods%20are%20safe.
you can use the debugger statement directly in your Node code to create breakpoints. When the Node runtime hits the debugger statement, it will pause execution if a debugger is attached.
function exampleFunction() {
    const value = 42;
    debugger; // Execution will pause here if a debugger is attached
    console.log(value);
}

exampleFunction();
Start Your Application in Debug Mode using the --inspect or --inspect-brk flag when running your app.
node --inspect --5120 lib/app.js
If all goes as expected you will see the port to access to the breakpoints, example:
Debugger listening on ws://127.0.0.1:9229/65b96f6d-6202-49db-bbe8-63b706a580a2
Visit the port on your browser and open the Node DevTools.
image.png 54.1 KB
More info: https://nodejs.org/en/learn/getting-started/debugging
In Python, variables don't directly store values. Instead, they store references to objects in memory. Each object has a reference count, which keeps track of how many variables are pointing to it. When the reference count of an object becomes zero, it's considered garbage and is automatically collected by the garbage collector.
x = 10
y = x
print(id(x))  # Output: 140737469306640
print(id(y))  # Output: 140737469306640
In this example, both x and y refer to the same integer object with the memory address 140737469306640. The reference count of this object is 2.
del x
print(id(y))  # Output: 140737469306640
After deleting x, the reference count of the integer object becomes 1. Since y is still pointing to it, the object is not garbage collected.

Garbage Collection:
Python's garbage collector periodically scans the memory for objects with a reference count of zero. These objects are marked as garbage and are reclaimed by the garbage collector. The exact timing and frequency of garbage collection can vary depending on the Python implementation and workload.
Headless applications focus on separating the frontend (user interface) from the backend (server-side logic). This separation allows for greater flexibility and scalability, as the frontend and backend can be developed, maintained, and updated independently. In a headless application, the frontend communicates with the backend through APIs to fetch data and perform actions.

Frontend applications
are traditional applications that have a tightly coupled frontend and backend. The frontend is responsible for rendering the user interface and handling user interactions, while the backend handles server-side logic and data management. Frontend applications typically have a fixed structure and are designed for a specific platform or device.

Key differences between headless and frontend applications:
  • Separation of concerns: Headless applications have a clear separation between the frontend and backend, while frontend applications have a more integrated approach.
  • Flexibility: Headless applications are more flexible as they can support multiple frontends and can be updated independently.
  • Scalability: Headless applications can be scaled more easily as the frontend and backend can be scaled independently.
  • Development: Headless applications often require more complex development processes due to the separation of concerns.
  • User experience: Frontend applications typically provide a more cohesive user experience as the frontend and backend are tightly integrated.

In summary
  • Frontend Application: This is a broad term that encompasses any application that interacts directly with the user. It could be a website, mobile app, or desktop application.  
  • Headless Application: This is a specific architecture where the frontend (user interface) is decoupled from the backend (server-side logic) and communicates through APIs.   

A React app that fetches data from an API
falls into the headless category because it:
  1. Separates frontend and backend: The React app (frontend) is distinct from the backend service providing the API.
  2. Uses APIs: The React app communicates with the backend through APIs to retrieve and manipulate data.  

In essence, while all React apps that use APIs are frontend applications, they also inherently follow a headless architecture due to the separation of concerns and API-based communication.

A headless application is a software application that separates the front-end (user interface) from the back-end (server-side logic). This separation allows for greater flexibility and scalability, as the front-end and back-end can be developed, maintained, and updated independently.

Key characteristics of headless applications:
  • Decoupled front-end and back-end: The front-end and back-end components are separate entities that communicate through APIs.
  • API-driven: The back-end provides APIs that the front-end can use to fetch data and perform actions.
  • Multiple front-ends: A headless application can support multiple front-ends, such as web, mobile, and desktop applications.
  • Flexibility: This architecture allows for rapid changes to the front-end without affecting the back-end, and vice versa.
  • Scalability: The front-end and back-end can be scaled independently to meet changing demands.

Benefits of headless applications:
  • Faster development: The decoupled architecture allows for parallel development of the front-end and back-end.
  • Improved flexibility: The ability to update the front-end without affecting the back-end enables rapid changes and experimentation.
  • Enhanced scalability: The ability to scale the front-end and back-end independently ensures optimal performance and resource utilization.
  • Reusability: The back-end can be reused for multiple front-ends, reducing development effort.
  • Improved user experience: Headless applications can provide a more consistent and responsive user experience across different platforms.

Example:
A headless e-commerce application could have a back-end that manages product information, orders, and inventory. The front-end could be a web application, a mobile app, or even a voice-activated assistant. The front-end would communicate with the back-end through APIs to fetch product data, place orders, and manage the shopping cart.

An API gateway acts as a single entry point for clients to access and interact with multiple backend services. It provides a unified interface, abstracting the complexity of the underlying systems and simplifying communication.

Key functions of an API gateway:
  • Unified interface: It presents a consistent API to clients, regardless of the backend services being accessed.
  • Authentication and authorization: It can handle authentication and authorization, ensuring that only authorized users can access specific resources.
  • Rate limiting: It can implement rate limiting to prevent abuse and protect backend services from overload.
  • Caching: It can cache frequently accessed data to improve performance and reduce load on backend services.
  • Transformation: It can transform data between different formats, ensuring compatibility between clients and backend services.
  • Security: It can provide security features like encryption, data validation, and protection against common attacks.

Benefits of using an API gateway:
  • Simplified development: It reduces the complexity of client-side development by providing a single endpoint.
  • Improved performance: It can improve performance by caching data and optimizing communication with backend services.
  • Enhanced security: It can strengthen security by implementing authentication, authorization, and rate limiting.
  • Scalability: It can handle increased traffic by distributing load across multiple backend services.
  • Flexibility: It can adapt to changes in backend services without affecting clients.

Example:
In a mobile application, an API gateway can act as a central point for clients to access different backend services, such as user authentication, product catalog, and order processing. The API gateway can handle authentication, rate limiting, and data transformation, providing a consistent and secure interface for the mobile app.

A load balancer can be a device or software that distributes incoming network traffic across multiple servers to improve performance, reliability, and scalability. It acts as a traffic manager, ensuring that workload is evenly distributed among available servers, preventing any single server from becoming overloaded.

Key functions of a load balancer:
  • Traffic distribution: It directs incoming traffic to the most appropriate server based on various factors, such as server load, health status, and application requirements.
  • Failover: If a server fails or becomes unresponsive, the load balancer can automatically redirect traffic to a working server, ensuring uninterrupted service.
  • Session persistence: It can maintain session affinity, ensuring that requests from a particular client are always routed to the same server, preserving the state of the session.
  • Performance optimization: Load balancers can improve performance by reducing latency, increasing throughput, and enhancing overall system responsiveness.
  • Security: Some load balancers can provide security features like SSL termination, DDoS protection, and access control.


Example:
In an e-commerce website, a load balancer can distribute incoming traffic from customers across multiple web servers, ensuring that the website remains responsive even during peak traffic periods. If one server fails, the load balancer can automatically redirect traffic to another server, preventing service interruptions.