menu

Search By Label

MongoDB Semantic Search refers to the ability to search for documents in a MongoDB collection based on the meaning or context of the data, rather than just exact keyword matches. Traditional database searches are often keyword-based, which means they only return documents that contain an exact match to the search query. Semantic search, on the other hand, aims to understand the intent behind the query and return results that are contextually similar, even if the exact keywords aren't present.


Single-Threaded Execution: JavaScript operates on a single thread, meaning it executes one task at a time using the call stack, where functions are processed sequentially.

Call Stack: Picture the call stack as a stack of plates. Each time a function is invoked, a new plate (function) is added to the stack. Once a function completes, the plate is removed.

Web APIs: Asynchronous tasks like setTimeout, DOM events, and HTTP requests are managed by the browser’s Web APIs, operating outside the call stack.

Callback Queue: After an asynchronous task finishes, its callback is placed in the callback queue, which waits for the call stack to clear before moving forward.

Event Loop: The event loop constantly monitors the call stack. When it's empty, the loop pushes the next callback from the queue onto the stack.

Microtasks Queue: Tasks like promises are placed in a microtasks queue, which has higher priority than the callback queue. The event loop checks the microtasks queue first to ensure critical tasks are handled immediately.

Priority Handling: To sum up, the event loop prioritizes microtasks before handling other callbacks, ensuring efficient execution.
Page to compare different LLM:

https://arena.lmsys.org/
We can delete a property from an object in python with `.pop('property_name', None)` to avoid errors if the object does not exist.
image.png 81.1 KB

Source: https://www.javatpoint.com/difference-between-del-and-pop-in-python#:~:text=In%20Python%2C%20%22del%22%20can,removes%20an%20object%20from%20memory
This aggregation stage performs a left outer join to a collection in the same database.

There are four required fields:
  • from: The collection to use for lookup in the same database
  • localField: The field in the primary collection that can be used as a unique identifier in the from collection.
  • foreignField: The field in the from collection that can be used as a unique identifier in the primary collection.
  • as: The name of the new field that will contain the matching documents from the from collection.

Example:
db.comments.aggregate([
  {
    $lookup: {
      from: "movies",
      localField: "movie_id",
      foreignField: "_id",
      as: "movie_details",
    },
  },
  {
    $limit: 1
  }
])
Within the breakpoint() debugger, type dir(object) to list all available attributes and methods of the object.
This will give you an overview of what you can access.
Shallow copy
A shallow copy duplicates only the top-level properties. If those properties are references (like objects or arrays), the copy will reference the same objects.
let original = { a: 1, b: { c: 2 } }
let copy = { ...original }
copy.b.c = 3 // Changes "original.b.c"
When to use:
- Small objects with primitive data types.
- Situations where performance is critical.
- Cases where changes to nested objects should reflect in all copies.

Deep copy
A deep copy creates a complete clone of the original object, duplicating all nested objects and arrays.
let original = { a: 1, b: { c: 2 } }
let copy = JSON.parse(JSON.stringify(original));
copy.b.c = 3 // The "original.b.c" remains 2
When to use:
- Complex objects with nested structures.
- Scenarios where complete independence from the original object is needed.
- Preventing unintended side-effects from shared references.
To debug a Node.js application, one can use the debugging built-in method:

(1) Insert debugger; statement where you want to insert a break point
(2) Run the file with command $ node inspect <file name>
(3) Use a key for example, c to continue to next break point

You can even debug values associated to variables at that break point by typing repl. For more information, Please check the official guide.
Amazon Simple Email Service (SES) is a cost-effective email service built on the reliable and scalable infrastructure that Amazon.com developed to serve its own customer base. With Amazon SES, you can send transactional email, marketing messages, or any other type of high-quality content to your customers
Service to extract text information with precision using an AWS service:

Amazon Textract is a machine learning (ML) service that automatically extracts text, handwriting, 
design elements and data from scanned documents.
It goes beyond simple optical character recognition (OCR) to identify,
understand and extract specific data from documents.

Source:https://aws.amazon.com/es/textract/
You can print the full object with all the child nodes of an object using:
console.dir(body, { depth: null });
You can add this line at the beginning of a file to ignore all checks:
// @ts-nocheck
or 
// @ts-expect-error
To skip only the next line.
https://create-react-app.dev/docs/adding-custom-environment-variables/
The Law of Demeter belongs to the principle that states in a ruby method of an object should invoke only the methods of the following kinds of objects:
  1. itself
  2. its parameters
  3. any objects it creates/instantiates
  4. its direct component objects

The law restricts how deeply a method can reach into another object’s dependency graph, preventing any one method from becoming tightly coupled to another object’s structure.

Multiple Dots

The most obvious violation of the Law of Demeter is “multiple dots,” meaning a chain of methods being invoked on each others’ return values.

class User
  def discounted_plan_price(discount_code)
    coupon = Coupon.new(discount_code)
    coupon.discount(account.plan.price)
  end
end

The call to account.plan.price above violates the Law of Demeter by invoking price on the return value of plan. The price method is not a method on User, its parameter discount_code, its instantiated object coupon or its direct component account.

The quickest way to avoid violations of this nature is to delegate the method:
class User
  def discounted_plan_price(discount_code)
    account.discounted_plan_price(discount_code)
  end
end

class Account
  def discounted_plan_price(discount_code)
    coupon= Coupon.new(discount_code)
    coupon.discount(plan.price)
  end
end

In a Rails application, you can quickly delegate methods using ActiveSupport’s delegate class method:
class User
  delegate :discount_plan_price, to: :account
end

If you find yourself writing lots of delegators, consider changing the consumer class to take a different object

A Blueprint is a way to organize a group of related views and other code.
Rather than registering views and other code directly with an application, they are registered with a blueprint.
Then the blueprint is registered with the application when it is available in the factory function.