menu

Search By Label

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"
In PostgreSQL, the FOUND variable is a simple flag that helps you check if a query has found any results. It's like a "yes" or "no" indicator. 
 
1. When a query successfully finds one or more results, FOUND is set to true (or "yes").
2. When a query doesn't find any results, FOUND is set to false (or "no").

You can use FOUND in control structures like IF statements to make decisions based on whether your query found anything or not. It's a handy way to handle the outcome of a database search in your SQL scripts.
In PostgreSQL scripts, you can use global variables by defining custom variables and using them within your SQL code.
 
Example:

-- set a global variable 
SET my_var = 42;-- use the global variable 
SELECT * FROM my_table WHERE column = my_var;-- unset the global variable RESET my_var;

Complexity: Managing many small services can be like juggling a lot of balls. It can get complicated to coordinate and keep track of all these services. This complexity can make development and debugging more challenging.

Communication Overhead: In a microservices architecture, services often need to talk to each other over a network. This communication adds overhead and can slow things down compared to a monolithic system where everything is in one place.

Deployment Challenges: Deploying changes to multiple services can be like herding cats. Each service may have its own version, and coordinating updates across all of them can be tricky. It requires careful planning and automation.
Flexibility: Microservices allow you to independently build and update different application parts. It's like having building blocks that you can rearrange or replace without affecting the entire structure. This flexibility makes it easier to adapt to changing needs and technologies.

Scalability: Imagine you're running a restaurant, and each dish is prepared in its kitchen. If one dish becomes popular, you can add more kitchens just for that dish without changing the whole restaurant. Microservices work similarly, allowing you to scale specific application parts to handle more traffic or load.

Fault Isolation: In a large application, if one part breaks, it can sometimes bring down the entire thing. If one service has an issue with microservices, it's like a single light bulb going out in a string of lights. The rest of the lights (services) can keep shining. This helps with fault isolation and keeps your application more robust.
This tool can help you learn things like: 

1. How many rows were affected by a command? 
2. What's the unique ID of the last row that was added to a table?
3. If there was an error, what's the reason for it?
 
You can use this tool in a program or script to check these things. 

For example, if you update some data in a table, you can use "GET DIAGNOSTICS" to see how many rows got changed and if there was any problem. This can be really handy for keeping track of what's going on when you're working with a database. 

Example:

-- Let's say we update some data in a table. 
UPDATE my_table SET column1 = 'new_value' WHERE id = 42;-- Now, we want to know how many rows got changed and if there's a unique ID for the last row. 
GET DIAGNOSTICS rows_affected = ROW_COUNT, last_oid = RESULT_OID;-- We can print these values to see what happened. 
RAISE NOTICE 'Rows affected: %, Last OID: %', rows_affected, last_oid; 
We use RAISE NOTICE to generate a notice message like we use the console.logs() on Javascript. The message can include placeholders (e.g., %) where you can insert values or variables. 

Example:

CREATE OR REPLACE FUNCTION example_function() RETURNS void AS $$ 
BEGIN 
 -- Some code here 
 
 -- Raise a notice message 
 RAISE NOTICE 'This is a notice message: %', 'Additional data'; 
 
 -- More code here 
END; 
$$ LANGUAGE plpgsql; 

The :not pseudo selector is useful for styling a group of elements while leaving the last (or specified) element unstyled.

 
HTML
One
Two
Three
Four


CSS
.css-not-selector-shortcut { 
 display: flex; 
}

ul { padding-left: 0; }
li { list-style-type: none; margin: 0; padding: 0 0.75rem; }
li:not(:last-child) { border-right: 2px solid #d2d5e4; }

Did you know that in Ruby 3.1.3 and prior some regexps could take a long time to process?

Don't believe me? Try running this in a 3.1.3 irb console:

`/^a*b?a*$/ =~ "a" * 50000 + "x"`

Your system will halt for like 10 seconds before returning no matches. This is the basis for ReDoS (Regexp Denial of Service) attacks.

Thankfully, Ruby 3.2.0 has fixed this and the same regexp gets resolved in 0.003 seconds. They also added a `Regex.timeout` global option which would prevent your app from falling victim to ReDoS attacks!