menu

Search By Label

In Elasticsearch, you store your data in indices, which are like containers for your information. Each index can have different kinds of data, like text, numbers, or dates.

Now, think of "mapping" as a set of rules that tells Elasticsearch what kind of data to expect in each index. It's like saying, "In this index, we have names, and they should be stored as text. In that index, we have numbers, and they should be treated as numbers."

So, when you request the _mapping, you're basically asking Elasticsearch to show you the rule book for each index. This rule book describes how data is organized and what type of data each field should contain.
This method is used to replace the first occurrence of a specified pattern. 

Example:

text = "Hello, World! This is a test. Hello, Universe!" 
new_text =text.sub("Hello", "Hi") 
puts new_text # => "Hi, World! This is a test. Hello, Universe!" 

This method is used to retrieve a list of all the public methods available for an object. This method returns an array of symbols, where each symbol represents a method that can be called on the object.

This method can be used to know the class of an object, which allows you to inspect and work with the class itself, rather than just the object. 

Example:

"Hello".class # => String 
10.class # => Number 
10.0.class # => Float 

The "readonly" modifier is used to indicate that a property or variable should not be modified once it has been initialized. It ensures that the value of the property remains constant throughout the lifetime of the object or variable.
 
Example with an array:

const numbers: readonly number[] = [1, 2, 3]; 
numbers[0] = 4; // Error! Cannot assign to an element of a readonly array 
numbers.push(4); // Error! Cannot push to a readonly array 

This method is the opposite of the .blank? method. It is used to check whether a string, array, or other data structure contains meaningful content, and it returns true if the object is not empty, contains non-whitespace characters, or is not nil. Otherwise, it returns false.

Example:

"".present? # false (empty string) 
" ".present? # false (whitespace characters only) 
nil.present? # false (nil) 
"hello".present? # true (contains non-whitespace characters) 
[1, 2, 3].present? # true (array with elements) 

This method is used to check whether a string, array, or other data structure is empty or contains only whitespace characters.
 It returns true if the object is empty contains only whitespace, or is nil. Otherwise, it returns false. 

Example:

"".blank? # true (empty string) 
" ".blank? # true (whitespace characters only) 
nil.blank? # true (nil) 
"hello".blank? # false (contains non-whitespace characters) 
[1, 2, 3].blank? # false (array with elements)

The "SELECT INTO" statement is used to retrieve data from a database table and store it into variables or a new table. 

Example:

-- Assigning Values to Variables 
DECLARE @variable_name data_type; 
SELECT column_name INTO @variable_name FROM table_name WHERE condition;-- Creating a New Table 
SELECT column1, column2 INTO new_table FROM old_table WHERE condition;-- Inserting Data into an Existing Table 
INSERT INTO existing_table (column1, column2) 
SELECT column1, column2 FROM source_table WHERE condition;

Javascript supports currency formatting without any library. 

Example:

const number = 123456.789;console.log(new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number)); 
// Expected output: "123.456,79 €"// The Japanese yen doesn't use a minor unit 
console.log(new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(number)); 
// Expected output: "¥123,457"// Limit to three significant digits 
console.log(new Intl.NumberFormat('en-IN', { maximumSignificantDigits: 3 }).format(number)); 
// Expected output: "1,23,000"

The first parameter used is an Intl namespace internationalization.
StricMode is a tool to help React developers detect possible issues in the code. 

Some advantages are: 

  1. Identify early problems
2. Detection of unwanted side effects
3. Improved code quality
Ruby's Enumerable#cycle offers an easy way to either repeat a certain pattern n times or just to switch between two predefined states. 

Repeating a certain pattern:

irb> array = [1, 2, 3]  
=> [1, 2, 3] 
irb> array.cycle(3).to_a  
=> [1, 2, 3, 1, 2, 3, 1, 2, 3] 

Switching between two states:

irb> button = ['on', 'off'].cycle  
=> # 
irb> button.next  
=> "on" 
irb> button.next  
=> "off" 


In your session, it's necessary to set the editor for opening files using this export command:

export EDITOR= 

Afterward, to open the gem files, use the following command:
 
bundle open

This action allows you to open any gem within your Rails project, enabling you to explore its internals and understand the current flow, helping you solve any issues related to it.


In rails 7 the correct way to render templates through the wicked_pdf gem is:

template: 'folder/file', formats: [:html]

is important to know that now is required to set the file without the file extension.
API Gateway is like a traffic cop for web services and applications. It's a server that acts as a single entry point to manage, control, and route incoming and outgoing requests between various parts of a software system. 

Imagine a busy intersection with multiple roads and vehicles. The API Gateway sits at the center and directs traffic. Here's what it does: 

1. Routing: It decides where an incoming request should go based on the request's path, method, or other criteria. Just like a traffic cop directing vehicles to the right lanes.
2. Load Balancing: When there are multiple instances of a service running, the API Gateway can distribute incoming requests evenly among them to prevent overloading any single instance.
3. Authentication and Authorization: It can handle user authentication and ensure that only authorized users can access certain services. Think of it as checking IDs before letting someone into a restricted area.
4. Caching: To reduce load on services, the API Gateway can store responses from services and provide cached data when possible, like a vending machine having snacks readily available.
 
In essence, an API Gateway simplifies and centralizes how different parts of a software system communicate with each other and with external clients. It streamlines the flow of data and ensures that everything runs smoothly, just like a well-managed traffic intersection.
In JavaScript, console.time is a method that helps you measure the time it takes for a specific block of code to execute. It's like a stopwatch for your code. 

Example:

// Start the timer 
console.time('myTimer');// Simulate a time-consuming operation 
for (let i = 0; i < 1000000; i++) { 
 // Some code here 
}// Stop the timer and display the elapsed time in milliseconds 
console.timeEnd('myTimer');
 
So, when you run this code, you'll see something like: "myTimer: 23.789ms"