menu
KEDA is a tool that helps Kubernetes automatically start or stop workers based on how busy things are.

Imagine you have some background jobs like Celery tasks. If there are no tasks, you don't need any workers running — that saves money.
But when new tasks come in, KEDA wakes up the workers to handle them.

Example config:
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: celery-worker-scaledobject
spec:
  scaleTargetRef:
    name: celery-worker
  minReplicaCount: 0
  maxReplicaCount: 2
  pollingInterval: 15 # seconds
  cooldownPeriod: 300 # seconds
  triggers:
    - type: redis
      metadata:
        address: 10.147.77.27:6379
        listName: dev_process_files_queue # your custom Celery queue
        listLength: "8"


Automatically scale down pods when CPU/RAM is low:

- Scales up: when pods are unschedulable due to lack of resources.
- Scales down: when nodes are underutilized and workloads can be moved elsewhere.

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api-hpa
  namespace: dev
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api
  minReplicas: 1
  maxReplicas: 3
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 60

Preview Markdown files using the command 
:MarkdownPreview

The Circuit Breaker pattern is used in backend systems to prevent repeatedly calling a failing service, which helps to avoid cascading failures and allows the system to recover gracefully.

It works like an electric circuit breaker:
  • Closed: calls are allowed through.
  • Open: calls are blocked for a cooldown period after repeated failures.

This pattern helps protect your system from slowdowns and outages due to repeated calls to unstable services.

To view the code from your last git stash without applying it, use the following command:
git stash show -p

What does it do?
git stash show displays a summary of the stash.
-p (or --patch) shows the full diff of what was stashed — similar to what you'd see in a git diff.

Use the jq package to format a JSON string, converting:
echo '{"a":[1,2,3]}' | jq .


Into this pretty output:
{
  "a": [
    1,
    2,
    3
  ]
}
Run the command:
cat $VIRTUAL_ENV/pyvenv.cfg

To show the information from your current Python virtual environment for example:
home = /Library/Frameworks/Python.framework/Versions/3.12/bin
include-system-site-packages = false
version = 3.12.2
executable = /Library/Frameworks/Python.framework/Versions/3.12/bin/python3.12
command = /Library/Frameworks/Python.framework/Versions/3.12/bin/python3 -m venv /Users/oswaldo/projects/<project_name>

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

To query a MongoDB collection to search a RegExp, you can use the following syntax in a MongoDB query:
db.collection.find({
    name: {$regex: "Match here"}
})
To query a MongoDB collection where a specific field both exists and is not empty, you can use the following syntax in a MongoDB query (using the find method):
db.collection.find({
  description: { $exists: true, $ne: "" }
})

$exists: true: ensures the field exists.
$ne: "": ensures the field is not an empty string.

Partition for manageability, Sharding for scalability.

Partitioning
Dividing data into segments (partitions) for easier management or to group related data together.
Often used within the same system and transparent to the application.

Sharding
Splitting data across multiple databases or servers to distribute the load and scale horizontally. 

Each shard operates independently, and often, the application needs logic to direct queries to the correct shard unless the data storage system transparently supports the redirect.
You can use the command :%s/<string-to-replace>/<new-string> to replace all matches with a new string.
You should use these comparisons for their semantics.
Use is to check identity and == to check equality.
In Python names refer to objects, for example in this case value1 and value2 refer to an int instance storing the value 1000:

value1 = 1000
value2 = value1
>>> value1 == value2
True
>>> value1 is value2
True
In the following example the names value1 and value2 refer to different int instances, even if both store the same integer. Because the same value (integer) is stored == will be True, that's why it's often called "value comparison". However is will return False because these are different objects:
>>> value1 = 1000
>>> value2 = 1000

>>> value1 == value2 True >>> value1 is value2 False
This will open an interactive help session where you can type in the names of modules, functions, classes, etc., to get information about them.

Example Usage

Here’s a practical example:
import datetime
help(datetime.datetime)
This will provide detailed information about the datetime class within the datetime module, including its methods and usage.
It's a list of public objects of that module, as interpreted by import *. It overrides the default of hiding everything that begins with an underscore.

__all__ in a module, e.g. module.py:

__all__ = ['foo', 'Bar']

means that when you import * from the module, only those names in the __all__ are imported:

from module import *               # imports foo and Bar