Cascade effect of texts
Animated cascade text on terminal with Python
Cascade effect of texts
Diferença do modelo Single Tenant e Multi Tenant em um SaaS
Os modelos de Single Tenant e Multi Tenant são duas abordagens diferentes para a arquitetura de um SaaS, e dizem respeito a como o serviço/infraestrutura é oferecido ao cliente.
SaaS: Software as a Service
Single = Um software que é utilizado por UMA empresa, cada cliente possui um instância do software, incluindo a infraestrutura e banco de dados.
Multi = Um software que é utilizado por VÁRIAS empresas, todos os clientes compartilham a mesma instância do software, incluindo a infraestrutura e banco de dados.
Multi Tenant NÃO QUER DIZER subdomínios.
Multi Tenant NÃO QUER DIZER um banco de dados por empresa.
Supress "Text content does not match server-rendered HTML"
Just use suppressHydrationWarning
on the component that is causing the warning:
Otimizando chamadas assíncronas no Javascript
Dica JavaScript: Otimize Chamadas Assíncronas com Promise.all
Executar await
em chamadas assíncronas de forma sequencial, como em getProducts()
seguido por getOrders()
, faz com que a segunda chamada espere a conclusão da primeira, aumentando o tempo total de execução.
Optar por Promise.all
nesse caso, permite que as chamadas sejam feitas em paralelo, reduzindo o tempo de espera e melhorando a performance da sua aplicação.
❌ worse
✅ better
Mas o Promise.all
deve ser usado com cuidado, porque se uma das requisições falhar, todas vão falhar.
ref: https://www.linkedin.com/feed/update/urn:li:activity:7166552833750773760/
Create intentional hover effects with transition-delay
Intentional CSS :hover effects 🎈
Add a small transition-delay
so you know the :hover
is intentional. See the difference below 🎞️
vs.
Can be useful for some designs 🤙
Tthe difference between `iter`, `into_iter` and `iter_mut` on Rust
TL;DR
into_iter
may yield any of T
, &T
or &mut T
, depending on the context.iter
will yield &T
, by convention.The first question is: "What is into_iter
?"
into_iter
comes from the IntoIterator
trait:
You implement this trait when you want to specify how a particular type is to be converted into an iterator. Most notably, if a type implements IntoIterator
it can be used in a for
loop.
For example, Vec
implements IntoIterator
... thrice!
Each variant is slightly different.
This one consumes the Vec
and its iterator yields values (T
directly):
The other two take the vector by reference (don't be fooled by the signature of into_iter(self)
because self
is a reference in both cases) and their iterators will produce references to the elements inside Vec
.
This one yields immutable references:
While this one yields mutable references:
So:
What is the difference between
iter
andinto_iter
?
into_iter
is a generic method to obtain an iterator, whether this iterator yields values, immutable references or mutable references is context dependent and can sometimes be surprising.
iter
and iter_mut
are ad-hoc methods. Their return type is therefore independent of the context, and will conventionally be iterators yielding immutable references and mutable references, respectively.
Use pattern matching on Rust slices/vectors
This is a usefull pattern on Rust match
when you want to match slices of a vector.
Imagine this problem: We want to implement a function which takes an vector containing the names of people that like an item. It must return the display text as shown in the examples:
We can solve this with:
Where rest @ ..
will catch all the rest of the vector items.
Another examples:
refs:
How to fast replace all mathing strings on vim
For basic find-and-replace on vim, we can use the :substitute
(:s
) command.
The general form of the substitute command is as follow:
:[range]s/{pattern}/{string}/[flags] [count]
The command search each line in [range]
for a {pattern}
, and replaces it with a {string}
.
[count]
is a positive integer that multiplies the command.
If no [range]
and [count]
are given, only the pattern found in the current line is replaced.
The current line is the line where the cursor is placed.
For example, to search for the first occurrences of the string "foo"
in the current line, and replace it with "bar"
, you should use:
:s/foo/bar
To replace all occurrences of the search pattern in the current line, add the g
flag:
:s/foo/bar/g
If you want to search and replace the pattern in the intire file, use the percentage character %
as a range.
This caracter indicates a range from the first to the last line of the file:
:%s/foo/bar/g
We can also use |
as parameter separator:
:s|foo|bar
To show confirmation for each substituition, use c
flag:
:s/foo/bar/gc
To ignore case sensitivity, use i
flag:
:s/foo/bar/gi
There is much more options, look at the ref link for more...
How to use a "application-only" volume on MOCP for change volume on mocp without affect system
I was using MOCP on linux for a while to listenning some musics that I have downloaded on my machine, but the only defect of MOCP is the volume controll... until now...
The default volume controll of MOCP controlls the volume from ALSA hardware mixer setting, which change the volume from all system. That is a pain when you want to listennig musics as background music, while listenning another sounds too (like noisekun.com).
Today I discovered that there is a way to make mocp volume controll independent from system volume.
You may see that on volume bar (lower left corner) was writen "Master":
This mean that the volume controll reflect the system volume, so we need to change this with the key X. Now our bar is:
And the volume is independent of system volume.
If your volume bar is writen "S.Off", you can type W to change to "Soft"
What is the "Box" in Rust Lang
Reading some Rust code examples in documentation and blogs, I can see the use of Box<T>
declaration. Like:
According to the official Rust documentation: "All values in Rust are stack allocated by default. Values can be boxed (allocated on the heap) by creating a Box<T>
. A box is a smart pointer to a heap allocated value of type T
. When a box goes out of scope, its destructor is called, the inner object is destroyed, and the memory on the heap is freed."
How to generate a random fixed size string in Rust
For generate a random string with fixed size in Rust, we can use Alphanumeric
trait from rand
crate:
Connect SQLite in a Rust app
For run SQL queries on SQLite database from Rust, we can use the sqlite3 crate:
Math behind the calculation of the number of handshakes from N persons
Given people, how many handshakes will be given by all the people greeting each other?
We can determine this using the formula:
Where is the number of people that will handshake.
ref: solution for https://www.hackerrank.com/challenges/handshake/problem
How to disable node warnings with env variable
When we run a node script, we can see incovenie warnings like:
For disable this warnings, just pass NODE_NO_WARNINGS=1
as environment variable before node command or script, e.g.:
On package.json
script:
Use position sticky with tailwindcss
We can use sticky
class when using tailwind to make an element fixed on screen while the parent element is visible.
Code:
CSS Equivalent:
Visual example: https://www.w3schools.com/howto/howto_css_sticky_element.asp
How to mock module implementation inside a test with jest
Sometimes you are testing a component and need to mock a module (in this case I needed to mock a zustand store), but with the exemple of "next/navigation" mock, you are mocking the module for entire test suit on the file that you declare the jest.mock()
. But, if you want to mock a specific implementation for each test? So first, with need to declare the module mock, without pass the implementation function:
In this case we are mocking "../../stores/sounds-state-store"
module
And, inside each test, we will use the jest.Mock.mockImplementation()
function to mock the implementation of module inside it
/test
scope:
the store we want to mock is useSoundsStateStore
, from '../../stores/sounds-state-store'
Full code:
Note that we use:
instead of:
Because it's a typescript project, and we need to tell the ts compiler that useSoundsStateStore
have jest.Mock
functions on this scope.
references:
How to fix error "invariant expected app router to be mounted" when test Next.js hooks/components
Next.js: 14.0.3
When you try to test a component or hook that uses some function from "next/navigation" module (like useRouter
, useSearchParams
, useSearchParams
, etc.), you may come across the error:
This happening because the "next/navigation" just works when app router was monted, to solve this, you need to mock the entire module. Put this before all your describe
s and it
/test
s:
references: https://github.com/vercel/next.js/discussions/48937
Enable some locales to use when they not appear on "Region & Language" menu
When we go to Region & Language menu to change locale (language and units) of a newly installed system with GNOME, may not have the language you are looking for. For the most cases is a question of enable it on /etc/locale.gen
.
For this, just edit the file /etc/locale.gen
with root privileges:
$ sudo vim /etc/locale.gen
And uncomment the language that you looking for, e.g:
for
#pt_BR.UTF-8 UTF-8
remove the #
, and save
pt_BR.UTF-8 UTF-8
After edit the locale file, regenerate locales with command:
sudo locale-gen
That's it! Just go to Region & Language and select your language.
referencies:
Gnome (Debian 11): How to install en*DK formats (date, numbers, units)?: https://unix.stackexchange.com/questions/679315/gnome-debian-11-how-to-install-en-dk-formats-date-numbers-units [_archive*]
Black wallpaper on xfce4 when restart the computer
This problem consists of black background insted the wallpaper on xfce4, apparently is the xfdesktop
daemon that was not starting on login. To fix it, wee just need to setup this daemon to auto start on login:
Session and Startup
> Application Autostart
Add
xfdesktop --replace
.references:
Desktop background appears black when using XFCE: https://unix.stackexchange.com/questions/151471/desktop-background-appears-black-when-using-xfce [archive]
Integrando Oak com certificados SSL
Primeiro devemos certificar que temos o programa openssl
deve aparecer algo como isto
senão tiver o openssl
instalado, instale com o comando:
(debian based)
Para gerar a chave privada e o certificado rode o comando:
Depois gere a chave descriptografada:
ja pode excluir o arquivo keytmp.pem
, ele não será mais necessário.
Para usar Oak com HTTPS devemos passar os atributos secure
, certFile
e keyFile
.
como o exemplo a seguir:
How To Create an HTTPS Server on Localhost using Express: https://medium.com/@nitinpatel_20236/how-to-create-an-https-server-on-localhost-using-express-366435d61f28 [archive]
oak docs: https://github.com/oakserver/oak [archive]
OpenSSL Tutorial: How Do SSL Certificates, Private Keys, & CSRs Work?: https://phoenixnap.com/kb/openssl-tutorial-ssl-certificates-private-keys-csrs [archive]