menu

Search By Label

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.
You can use the method Array.index() to find the position of an element, example:

languages = ["English", "Spanish", "French"]
current_lang = "Spanish"

try:
  # Use the index() method to find the index of the element
  index = languages.index(current_lang)
  print(f"The index of '{current_lang}' in the languages list is: {index}")
except ValueError:
  print(f"'{current_lang}' is not found in the languages list.")

This command shows data about a package and prints it to stdout.
As an example, to view information about the connect package from the registry, you would run:

npm view connect

And you can see all versions using:
npm view connect versions
Using json.dumps()
Similar to JavaScript's JSON.stringify(), Python offers json.dumps() to convert a Python object into a JSON string. This is the preferred method for most scenarios as JSON is a widely used and well-structured format.

import json

my_object = {"name": "Alice", "age": 30, "city": "New York"}
json_string = json.dumps(my_object)

print(json_string)  # Output: {"name": "Alice", "age": 30, "city": "New York"}

You can use the command:
docker image ls
Convolutional Neural Networks (CNNs) are a specific type of deep learning architecture that excels at tasks involving images, videos, and other grid-like data. They are particularly successful in applications like image classification, object detection, and image segmentation.

Imagine you're looking at a picture of a cat. Our brains are good at recognizing the shapes of ears, whiskers, and fur to tell it's a cat. Convolutional Neural Networks (CNNs) are like artificial brains for computers, especially good at understanding pictures and videos.
Here's the basic idea:
  • CNNs look at images in small squares, like a detective examining a crime scene with a magnifying glass.
  • They learn what patterns are important in each square, like edges, shapes, and colors.
  • By putting these clues together, CNNs can eventually recognize the whole picture, just like you can recognize the cat.

This makes CNNs super useful for:
  • Telling what's in a picture (cats, dogs, cars, etc.)
  • Finding specific objects in a picture (like finding a cat in a photo of your living room)
  • Understanding videos (like what's happening in a security camera recording)

To specify a Python runtime, add a runtime.txt file to your app’s root directory that declares the exact version number to use.
$ cat runtime.txt
python-3.12.4

Source: https://devcenter.heroku.com/articles/python-runtimes
In Python, if you want to access the index while iterating over a sequence (like a list), you can use the built-in function enumerate().
Here’s how you can do it:
xs = [8, 23, 45]
for index, x in enumerate(xs):
    print(f"item #{index + 1} = {x}")

This will give you the desired output:
item #1 = 8
item #2 = 23
item #3 = 45
Magic Numbers are literal numeric values that are used directly in code without a clear explanation of their meaning.
For example:
function calculatePrice(total) {
  if (total > 1000) {
    return total * 0.9; // 0.9 is a magic number
  } else {
    return total * 0.95; // 0.95 is another magic number
  }
}


In this example, the numbers 0.9 and 0.95 are magic numbers because their meaning is not clear. If someone else reads this code in the future, it will be difficult to understand their significance without additional context.
Similarly, Magic Strings are literal string values that are used directly in code without a clear explanation. 
For example:
function getErrorMessage(code) {
  switch (code) {
    case "ERR001":
      return "Connection Error"; // "ERR001" is a magic string
    case "ERR002":
      return "Authentication Error"; // "ERR002" is another magic string
    default:
      return "Unknown Error";
  }
}

Resources: 
https://softwareengineering.stackexchange.com/questions/365339/what-is-wrong-with-magic-strings
https://dev.to/ruben_alapont/magic-numbers-and-magic-strings-its-time-to-talk-about-it-ci2
I use polymorphic routes for readability purposes. This is useful to make the lines of code a bit shorter like this:

<%= button_to "Delete", [quote, line_item_date] %>
<%= button_to "Delete", quote_line_item_date_path(quote, line_item_date) %>

It is also possible to use them in controllers. For example, the two following lines for code are equivalent:

redirect_to @quote
redirect_to quote_path(@quote)


If you want to learn more about them, here is a link to the documentation.

A Foundation Model in AI is a large, powerful neural network trained on a massive dataset of text, code, images, or other forms of data. Here are some key points to understand them:
  • Large and General: These models are typically very large, containing billions or even trillions of parameters. This allows them to learn complex patterns and relationships within the data.
  • Broadly Applicable: Foundation models are trained in a way that allows them to be applied to a wide range of tasks. They can be fine-tuned for specific purposes like generating text, translating languages, or recognizing objects in images.
  • Platform for AI Applications: They act as a foundation upon which other AI applications can be built. By fine-tuning a foundation model for a specific task, developers can create powerful AI tools without needing to train a massive model from scratch.

Think of them as pre-trained brains:

  • Imagine a child learning from a vast amount of information (books, videos, experiences). Foundation models are like these "child brains" in the AI world, having learned from a huge dataset.
  • While the child might not be an expert in any specific field, it can use this knowledge as a base to learn new things quickly. Similarly, foundation models can be adapted (fine-tuned) to perform various tasks effectively.