menu

Search By Label

In certain instances, when sharing content via Rails view using I18n and incorporating specific HTML instructions, such as the requirement to set a string in bold, we follow this approach:

# config/locales/en.yml
en:
  homepage:
    services:
      title: "This is the <strong>example</strong>"

in this case should use the html_safe method in views like:

 <h1><%= t(:title, scope: %w[homepage services]).html_safe %></h1>

with this implementation, any HTML tag can work effectively.
Is possible to navigate over tabs in a custom panel with this shortcut:

ctrl/cmd + shift + a 
If you want to validate a field in js for example a password field, you can use the regex, is a sequence of characters that forms a search pattern
I have the pwdField
and my  const to test is const validPwd = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])([A-Za-z\d$@$!%*?&]|[^ ]){8,}$/;
  1. Min 8 characters
  2. at least one  uppercase or lowercase letter
  3. contains $@$!%*?&
You can use the test method to validate the field.
Example:
    const getPwdAndValidate = (pwdField, pwdField2) => {
    const validPwd = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*?&])([A-Za-z\d$@$!%*?&]|[^ ]){8,}$/;
        if (pwdField === pwdField2 && validPwd.test(pwdField) && pwdField.length >= 8) {
            return pwdField;
        } else {
            return null;
        }
    };

The :back symbol in Rails is often used to generate a URL that represents the previous page or location the user came from. It's commonly utilized in conjunction with methods like redirect_to redirecting users back to where they were before performing a specific action.


Here's a brief explanation:

- Usage with redirect_to you can use :back with the redirect_to method to send the user back to the previous page:

redirect_to :back

Usage with Links, You can also use :back as the path in a link to create a "Back" button or link:

<%= link_to 'Back', :back, class: 'btn btn-primary' %> 

The shortcut for opening the Visual Studio Code command palette is:

Ctrl/Cmd + Shift + P
Hide the terminal with the following shortcut:

Ctrl/Cmd+j
Switch your rails app database without having to touch a single file. Pass --force to skip prompts.

rails db:system:change --to=postgresql
 This method is used to create a new Map data structure. A Map is a built-in data structure in JavaScript that allows you to store key-value pairs and provides various methods for working with these pairs. Here's how you can use "new Map()" to create a new Map:
 
Example:

const myMap = new Map();myMap.set('name', 'John'); 
myMap.set('age', 30);console.log(myMap.get('name')); // Output: 'John' 
console.log(myMap.get('age')); // Output: 30

This command is useful for ensuring that your local npm cache is in a healthy state, which can help prevent issues when installing or updating packages. If any issues or corruption are detected, npm cache verify will attempt to fix them. It's a maintenance command to help maintain the reliability of your local npm package cache.

A reverse proxy is like a guardian for web servers. It sits between client devices (like browsers) and web servers, accepting requests from clients and directing them to the appropriate server to fulfill those requests. It's a way to balance the load on multiple servers and provide an extra layer of security and performance optimization for websites and web applications. 


  • Operational Direction: A reverse proxy is placed between a client and one or more backend servers. It serves as a gateway for client requests, forwarding those requests to the appropriate backend server or server cluster based on various criteria. 
  •  
    Load Balancing: Reverse proxies are commonly used for load balancing across multiple servers, ensuring even distribution of incoming requests to maintain system performance. 

  • Security and Protection: They provide an additional layer of security by shielding backend servers from direct exposure to the internet. This helps protect servers from direct attacks.
In Ruby, the .is_a? method is used to check if an object is an instance of a particular class or a subclass of that class. It allows you to determine if an object belongs to a certain class in the class hierarchy. The .is_a? method returns true if the object is an instance of the specified class or one of its subclasses, and false otherwise. 

Example:

# Define a class 
class Animal 
end# Create an object 
dog = Animal.new# Check if the object is an instance of a class 
puts dog.is_a?(Animal) # true 
puts dog.is_a?(Object) # true, since all objects are instances of Object 
puts dog.is_a?(String) # false, since a dog is not a String
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