Skip to content

Instantly share code, notes, and snippets.

View uxjp's full-sized avatar
🛠️
making it work

JP uxjp

🛠️
making it work
View GitHub Profile
@uxjp
uxjp / .bashrc
Created November 22, 2023 14:38
Prompt Linux Shell - PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
PS1='\[\033[01;32m\]@\u\[\033[00m\] \[\033[01;34m\]\W\[\033[00m\]\[\033[01;36m\]$(parse_git_branch)\[\033[00m\]\n$ '
# Don't forget
# $ source ~/.bashrc
@uxjp
uxjp / gist:7984d41cdf7e9735286b2cdb33fe430a
Created August 30, 2023 22:00
Flutter - setState() called after dispose()
A solução que consegui encontrar para `setState() called after dispose()` foi justamente validar usando `mounted`.
Pelo que pesquisei já foi até sugestão de issue o setState checar o `mounted` por default. https://github.com/flutter/flutter/issues/107070
Em um app com multiplas telas dados são carregados assincronamente, em alguns casos widgets estão fechados(unmounted - fora da árvore de widgets)
antes dos dados serem carregados completamente. Se um `setState` é executado em um `widget` que não está mais na tela teremos um erro.
Pode ocorrer de fluxos de outros widgets não apresentem erro. Entretanto não deixar um check para o `mounted`
deixa esse potencial ponto de falha em um widget que pode ser usado em várias partes do App.
@uxjp
uxjp / MongoDB.md
Created June 20, 2023 19:13 — forked from royz/MongoDB.md
MongoDB - install, enable authentication & remote access on Ubuntu 20.04

Install MongoDB 5.x

Source: MongoDB Docs

1. Import the public key used by the package management system

wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -

2. Create a list file for MongoDB

defmodule Ab do
def abs(x) when x < 0, do: x * -1
def abs(x), do: x
end
defmodule Solution do
IO.read(:all)
|> String.split
|> Enum.map(&String.to_integer/1)
|> Enum.map(&Ab.abs/1)
@uxjp
uxjp / list_length.ex
Created September 25, 2022 03:40
fp-list-length without libs
defmodule Arr do
def count(arr) do
c(arr, 0)
end
def c([_ | tail], acc) do
c(tail, acc + 1)
end
def c([], acc) do
@uxjp
uxjp / 0_sum_odd_indexes_in_a_list.ex
Last active September 25, 2022 03:25
Sum_odd_indexes_in_a_list
# I miss interpreted the function, but the outcome was cool
defmodule ListUtil do
def su(list) do
sum(list, 0)
end
def sum([head | tail], acc) do
sum(tail, head + acc)
end
@uxjp
uxjp / 1_revert_list.ex
Last active September 25, 2022 02:15
Revert a List Elixir
defmodule ListUtil do
def invert([head | tail], acc) do
invert(tail, [head | acc])
end
def invert([], acc) do
acc
end
end
defmodule Solution do
IO.read(:all)
|> String.to_integer
|> (&(Range.new(1, &1))).()
|> Enum.to_list
|> IO.inspect
end
@uxjp
uxjp / 1_filter_list_positions.ex
Last active September 22, 2022 11:57
Elixir filter positions in a list
defmodule Solution do
IO.read(:all)
|> String.split
|> Enum.drop_every(2)
|> Enum.each(&IO.puts/1)
end
@uxjp
uxjp / 1_filter_list.ex
Last active September 22, 2022 02:26
Filter list Elixir
defmodule Solution do
[max | tail ] = IO.read(:all)
|> String.split
|> Enum.map(&String.to_integer/1) #everything is already integer after this
tail
|> Enum.filter(fn x -> x < max end)
|> Enum.each(&IO.puts/1)
end