menu

Search By Label

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.

Lambda functions are anonymous functions in Python. They allow you to define a small, one-line function without the need for a formal def keyword and a function name.

Example:
Imagine you want to double a number. Here's how you can do it with a regular function:
def double(x):
  """Doubles a number."""
  return x * 2

result = double(5)
print(result)  # Output: 10

This defines a function named double that takes a number (x) as input and returns its double.
Here's how you can achieve the same functionality using a Lambda function:
# Lambda function to double a number
double_lambda = lambda x: x * 2

result = double_lambda(5)
print(result)  # Output: 10

Use Cases:
  • Passing small functions as arguments to other functions.
  • Sorting or filtering data based on a simple criterion.
  • Creating throwaway functions used only once.
Syntactic sugar refers to the little bit of ✨ magic ✨ Ruby provides you in writing easier to read and more concise code. In Ruby this means leaving out certain symbols, and spaces or writing some expression with a helper of some kind one of these possibilities is the sandwich method, we look more at it here: 

It is common when we begin to handle an array in a each to do it specific actions thing like that:
array = [1, 2, 3, 4]
new_array = []
array.each do |element|
  new_array << element * 2
end
new_array
# => [2, 4, 6, 8]

Today I learned how simplified it is to handle this type of interaction by thinking about this magic we talked about before. the first thing that is important here is to remember that the use of each handle and return the same array and for this reason, it is necessary to create a new_array variable to inject the new values of the product to element * 2

Most of the time, if you have to use the sandwich method, there is probably a higher-level iterator that you could use that will allow you to perform the function on the array or hash without using the sandwich method. In this case, your best bet would be map :

array = [1, 2, 3, 4]
array.map do |element|
  element * 2
end
# => [2, 4, 6, 8]


GET requests are designed to retrieve data from a server, similar to fetching a document from a library catalog.
Since you're "getting" info, a body (like a new book) wouldn't be appropriate. Params (like search terms) are used to filter or specify the data you want.
This design keeps GET requests simple and avoids ambiguity.

The .strip() method in Python is used to remove leading and trailing characters from a string. It's a versatile method with various applications for string manipulation.

Example:
data = "  Hello, world!   "  # String with leading and trailing spaces

stripped_data = data.strip()

print(stripped_data)  # Output: "Hello, world!" (whitespace removed)
Or
data = "**Hello, world!**"  # String with leading and trailing asterisks

stripped_data = data.strip("*")

print(stripped_data)  # Output: "Hello, world!" (asterisks removed)

you can debug any Python app (>3.7 version) by adding the method breakpoint()  to any line.

Here the actions you can use:
h: help
w: where
n: next
s: step (steps into function)
c: continue
p: print
l: list
q: quit

Source: https://www.youtube.com/watch?v=aZJnGOwzHtU&ab_channel=PatrickLoeber