• Featured post

C# Async ops

El nucleo de la programacion asincrona son los objetos Task y Task<T>. Ambos son compatibles con las palabras clave async y await.

Primero hay que identificar si el codigo se usa para trabajos enlazados a I/O o si estos son CPU intensivos.

  • Si el codigo espera algo como una BBDD o una response de un servidor, es codigo I/O. En este caso hay que usar async y await
  • Si el codigo realiza un calculo costoso, es CPU intensivo. Use await para esperar una operacion que se ha comenzado en background con Task.run

Read More

Migrate docker-compose to k8s

Steps to go from a docker-compose file, to build an Image out of the file, upload it to DockerHub, and run it with Kubernetes (minikube).

Set up

Install Kompose

# linux
curl -L https://github.com/kubernetes/kompose/releases/download/v1.22.0/kompose-linux-amd64 -o kompose
chmod +x kompose
sudo mv ./kompose /usr/local/bin/kompose

Clone App and Host It into DockerHub

Clone the files, go to the directory where your Dockerfile is and run:

# mariocodes is my DockerHub username
# kubernetes-custom-java-maven-app is the name of the repo I created at DockerHub
docker build -f Dockerfile -t mariocodes/kubernetes-custom-java-maven-app .

Read More

K8s install Minikube

(Oficial Doc)

Technology to quickly set up a Kubernetes cluster locally to learn how to use Kubernetes.

Installation

How to install on a fresh Ubuntu installation:

Install prerrequisites and kubectl

sudo apt-get update && sudo apt-get install -y apt-transport-https curl

curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -

echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update
sudo apt-get install -y kubectl

Read More

Common errors in k8s

STATUS CrashLoopBackOff

CrashLoopBackOff and no log appears. This happens as the container has no command to run so it start up and then immediately exits.

Give your image a command.

more here

apiVersion: v1
kind: Pod
metadata:
  name: twocontainers
spec:
  containers:
  - name: container1
    image: python:3.6-alpine
	command: ['sh', '-c', 'echo cont1 > index.html && python -m http.server 8082']
  - name: container2
    image: python:3.6-alpine
	command: ['sh', '-c', 'echo cont1 > index.html && python -m http.server 8083']

i18n & l10n

i18n is just a nomenclature for Internationalization. i18n involves, among other things, the ability to display translated content. It prepares a digital product for localization by for example, separate the content into strings so they are ready to be translated and delivered.

The same goes for L10n. This is a nomenclature for Localization. L10n involves translating content, adapting graphics and finalizing the producto for each regional market.

Reference(s)

https://www.oneskyapp.com/blog/i18n-need-to-know-internationalization/

SQL Indexes

Indexes are a basic structure type that apply to one or multiple columns in order to improve performance and speed up queries that: filter, sort or join data for a table.

this may improve performance for a query that uses last_name in a WHERE clause or an ORDER BY

CREATE INDEX idx_last_name ON employees (last_name);

you can also create composite indexes

CREATE INDEX idx_composite ON employees (last_name, first_name)

and also composite index for only active employees

CREATE INDEX idx_active_employees ON employees (status) WHERE status = 'active';

When to use indexes

Frequent filters WHERE - if you usually filter by a specific column (last_name for example), an index should improve performance.

JOIN for big tables - when you use JOIN with big tables through PKs or FKs.

ORDER BY or GROUP BY - queries that search for / group by a specific column also benefit from indexes.

Best practices

Don’t create indexes in every column. This slows things down on insert, delete or update operations.

Index are best used for big domain fields such as ids, names, surnames. Don’t use them for male/female (or boolean) fields.

Keep indexes optimized: operations where you mass update or mass delete items in your tables may fragment your indexes. You may need to periodically check them and REINDEX them.

ALWAYS MEASURE PERFORMANCE TIME before and after the creation of that index. If your index doesn’t improve performance, remove it as it causes overhead.

Reference(s)

https://stackoverflow.com/questions/7744038/decision-when-to-create-index-on-table-column-in-database
https://stackoverflow.com/questions/52444912/how-to-find-out-fragmented-indexes-and-defragment-them-in-postgresql
https://chatgpt.com/

Advanced SQL

UNION

The union sentence is used to accumulate results for two SELECT sentences.

SELECT column1, column2 FROM table1
UNION
SELECT column1, column2 FROM table2

We have the following tables

company1

per name surname
1 ANTONIO PEREZ
2 PEDRO RUIZ

company2

per name surname
1 LUIS LOPEZ
2 ANTONIO PEREZ

Read More

Count number of entries in filtered table

(for this post some formulas and menu names are in spanish as my excel and computer are in spanish and excel formulas depend on this).

full list

The formula is:

=AGREGAR(3;3;J:J)-1

The first two parameters are for the function itself. The important one is J:J which marks the column to count. What’s important here is this is not going to count filtered items in tables.

Watch out with headers! If you have headers in your table, add -1 to your formula.