chore: add files from master-wiki repo

This commit is contained in:
Alexander Navarro 2024-11-20 20:00:35 -03:00
parent f99a9ae2ac
commit 1847f6bf28
315 changed files with 1047341 additions and 0 deletions

View file

@ -0,0 +1,3 @@
# ABI

View file

@ -0,0 +1,20 @@
---
title: "Colors"
tags:
- design
created: 2024-09-30 10:35
---
# Colors
## Accesibility
- Neurotipical persons wants attractive colors
- Neurodiversal persons don't want super stimulant colors
- Visually disable persons wants high contrast colors
To try to comply with all requirements try to follow:
- Use Matte colors
- Try to keey the saturation of the color in the middle, so it's not too intence neither to bland
- Comply with at least the minimun [[accebility contrast rules]]

View file

@ -0,0 +1,41 @@
---
title: "Error Handling"
tags:
- #coding
- #design-patterns
- #errors
created: 2024-10-20 16:45
---
# Error Handling
Different ways to handle errors in code
## Errors as Exceptions - Try Catch
### Try Catch
## Errors as Values
### `Result<T, Err>` - `Option<T>`
The `Result<T, Err>` type (sometimes also called `Option<T>`, `Maybe<T>`, or others)
is a custom data type that may or may not have a value, but like the
Schrödinger's box, we won't know until we peak inside of it, forcing the code
to handle both cases.
This data type can be use to solve 2 common pitfals:
- `Result<T, Err>`: this data can have a value (sometimes called `Ok(T)`), or can hold an error.
- `Option<T>`: this data can have a value (sometimes called `Some(T)`) or can not have a value (sometimes called `None()`).
This data type is often used with [[pattern matching]], allowing to handle each possible variation of the type.
Resources:
- [[Readwise/Monad Is Actually Easy.|This data type is a monad]]
- Rust [`Option<T>`](https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html#the-option-enum-and-its-advantages-over-null-values) and [`Result<T, E>`](https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html) types.
- Gleam [`Option(a)`](https://hexdocs.pm/gleam_stdlib/gleam/option.html) type.
- [Typescript Monads Package](https://github.com/thames-technology/monads)
### Return touples

View file

@ -0,0 +1,3 @@
# FFI
FFI

View file

@ -0,0 +1,50 @@
# iterators
> The iterator pattern allows you to perform some task on a sequence of items
> in turn. An iterator is responsible for the logic of iterating over each item
> and determining when the sequence has finished.
[Rust book](https://doc.rust-lang.org/book/ch13-02-iterators.html)
An itetarator it's usually related to some sort of lists, vectors or collection
of items, but the iterator can be anything that implements the interface. The
interaface depends on the language, but usually only needs a `next(Self) -> Item`
method that returns the next item to be acted upon.
The adventage of iterators is that you can use them with anything that accept
thems (kinda in the reusable side of programming), and modern standard
libraries implements patterns to use them like: `forEach`, `map`, `sum`, etc
Another common use case is to iterate on something indefinetly as long as it
continue to provide new items. For example you can implement a
`PollingIterator` that fetch data from a remote source until the source says
there's no more data:
```python
class EmailPoll:
"""Iterator class that pools emails from the EmailService indefinetly."""
def __init__(self, service: EmailService, wait_time: int):
super(EmailPoll, self).__init__()
self.service = service
self.wait_time = wait_time
self.current_mails = self.service.fetch_emails()
def __iter__(self):
return self
def __next__(self):
while len(self.current_mails) == 0:
self.current_mails = self.service.fetch_emails()
if len(self.current_mails) == 0:
print(f"No new emails, waiting {self.wait_time}s")
sleep(self.wait_time)
return self.current_mails.pop(0)
email_service = EmailService()
for mail in EmailPoll(email_service, 3):
print(mail)
```

View file

@ -0,0 +1,179 @@
---
title: "Journaling ~rompts"
tags:
created: 2024-09-22 21:23
---
# Journaling Prompts
![[How to Start Journaling#^363cd8]]
![[7 Intentional Questions To Ask Yourself Every Day#^029f29]]
![[11 Life-Changing Journaling Tips for Beginners#^05df43]]
![[11 Life-Changing Journaling Tips for Beginners#^ce92d8]]
![[11 Life-Changing Journaling Tips for Beginners#^ffddd6]]
![[11 Life-Changing Journaling Tips for Beginners#^4d6f9f]]
## Head full of thoughts, anxious, stressed, or an unknown feeling
### [[7 Mindful Journaling Prompts to Calm an Anxious Mind#^69db00|What I'm feeling right now?]]
Once you start writing, **dont stop until you feel there is nothing else to
write**. This means you should write everything down, even if you begin to veer
away from the prompt. Dont pay any mind to spelling mistakes, your handwriting
and dont edit what ends up on the page. Just write it all out.
### [[7 Mindful Journaling Prompts to Calm an Anxious Mind#^27b8e0|Where Am I Right Now?]]
The 5-4-3-2-1 coping technique for anxiety attacks is all about bringing your attention back to the now. In your journal, write the following:
• Five things that you see
• Four things that you can touch
• Three things that you can hear
• Two things that you can smell
• One thing that you can taste
### [[6 Morning Journal Prompts That Will Transform Your Day#^80fb8d|How do I want to feel when I go to bed tonight?]]
Whenever youre in a rut, a morning journaling exploration of **how you want to feel (rather than what you want to achieve)** is a great first step to lifting your mood.
To do this, start by imagining that youre in bed at the end of the day and youre about to close your eyes. Take a deep breath and then exhale. How do you want to feel at that moment?
Instead of saying happy, you could write down that you want to feel accomplished or connected. Take things a step further by brainstorming simple actions that will support you.
### [[6 Morning Journal Prompts That Will Transform Your Day#^44f8db|What season of life am I in?]]
We all have times when we feel **overwhelmed by the weight of our responsibilities**. Theres so much that we want to do and be—but never enough time to get it all done.
think about your own life and ask yourself, _“What season am I in?”_:
- Are you in a season of caring for others?
- A season of resting while you heal from physical or emotional trauma?
- A season of growth in your career or professional life?
> [!info]
> When working through this journal prompt, ask yourself if you need rest, if you need to work, if you need to spend time with family or friends, or if you need to be alone right now.
### [[6 Morning Journal Prompts That Will Transform Your Day#^b6b0bd|Write it all out]]
The idea behind **free-writing** is just as it sounds: you simply write out all of your thoughts without editing until there is nothing left.
I find that its powerful because it allows your brain to unload without expectations. Its a bit like ranting to a friend after a long day—sometimes you just need to get things off your chest, and then you can move on.
### [[7 Intentional Questions To Ask Yourself Every Day#^3b92eb|Is there a simpler way?]]
When Im faced with a problem or a task, Ive noticed that **my first instinct is to overthink things** and make the situation way more complicated than it needs to be.
Taking just five minutes to ask the question and look for a simpler way has saved me countless hours throughout my life. (And Ill also admit that sometimes it happens in reverse —Id spend hours doing something and then realises I made it harder than need be!)
## Worried about something or feeling negative
### [[Readwise/7 Mindful Journaling Prompts to Calm an Anxious Mind#^beb82a|What Am I Afraid Of?]]
To journal through your fears, start by writing them out one at a time. Ask
yourself what are the worse case scenarios, how they might affect you, and what
you would do. Ask yourself how likely it is to happen, why you think it might
happen, whether its occurrence would be positive or negative and why.
Allowing your fears to play out in your journal helps to **challenge the
legitimacy of these fears**. Its also a chance to discover **how you would address
them**, which can make you feel more prepared.
### [[7 Mindful Journaling Prompts to Calm an Anxious Mind#^3608de|Why Do I Feel Unwell?]]
When Im so overwhelmed that I cant think about how to care for myself, I turn to my journal. **I start with the line I feel unwell because… and let my thoughts flow. Answering this question leads me to discover what I need** (whether it be rest, connection, or creative expression). By delving into why I feel unwell, I learn what I can do about it, which improves how I care for myself.
### [[7 Mindful Journaling Prompts to Calm an Anxious Mind#^a59479|How Can This Moment Inform My Future]]
Taking time to acknowledge our mistakes, understand why they occurred, and think about how we can make better choices in the future is healthy.
Mistakes are inevitable and mindfully working through them helps us accept them as part of life and let go of perfectionism.
### [[7 Mindful Journaling Prompts to Calm an Anxious Mind#^fc98ae|I Am Lucky To…]]
Gratitude is one of the healthiest emotions to sit with. It has the power to **shift your mindset from scarcity to abundance**, which can be helpful when youre feeling stressed or just plain having a bad day.
try reflecting on:
- A favourite memory
- Your own strengths
- Song lyrics or a list of favourite songs
- Your greatest lessons
- Your biggest supporter
- How you overcame a negative experience in the past
### [[6 Morning Journal Prompts That Will Transform Your Day#^656f82|Today I am excited to...]]
We are hard-wired to focus more on the negative things in life than the positive things. So how can we overcome this? By putting **extra attention on the positive** in the morning and throughout the day as well.
> [!info]
> If youre struggling to feel excited, **try getting your senses involved**. Imagine a warm cup of coffee pressed between your palms, the sound of the birds on your way to work, the sun shining on your skin—and see if it doesnt change the way you feel.
### [[6 Morning Journal Prompts That Will Transform Your Day#^e92888|Today I get to...]]
**When you don't want to do what you need to do.** Think about things that you have to do today and see if you can re-frame your thoughts about the situation.
> [!info]
> Dont forget to acknowledge if you are currently living out a past goal or dream!
### [[6 Morning Journal Prompts That Will Transform Your Day#^44a1a6|I am challenged by…]]
Theres a productivity saying, _[[eat the frog]]_ that loosely applies to this journaling prompt. The meaning behind it is that **you should do the most difficult thing on your to-do list first**.
By making your challenges the focus of your morning journal prompt, youre eating the frog but in a more mindful way. When you write about what challenges you, it is helpful to explore **why and how you will overcome the challenge**, but you should also write out **what it will mean to you or your life**.
If those words dont ring true to your situation, you may need to re-evaluate whether the challenge fits with your values and goals.
## Cannot stop thinking about someone
### [[7 Mindful Journaling Prompts to Calm an Anxious Mind#^c261c4|Write A Letter That Youll Never Send]]
Address the letter to the person you need or want to talk to and **say everything you want to say**. This prompt will help you organice your thoughts and feelings about this person. You can also **be as honest as you need** because youre never going to send the letter.
You can write to:
- Your future self
- Your younger self
- To someone who is no longer with us
- To someone who has hurt your feelings
- To someone you admire
- To someone who needs your help
## Check on yourself
### [[7 Intentional Questions To Ask Yourself Every Day#^78caa2|Why am I doing this?]]
I think too often **we assume we know why we do what we do**, but when we carve out time to sit and reflect, the truth can surprise us.
It might save you ten minutes on a Monday morning, or ten years spent chasing a goal you dont even really want.
### [[7 Intentional Questions To Ask Yourself Every Day#^0ea258|Who am I doing this for?]]
This is a good question to ask yourself regularly when you feel your priorities are out of alignment. **It can help shine a light on where you need stronger personal boundaries**.
But I should also point out that self-reflection isnt about judging yourself or others. Instead, **its about honesty; knowing why you do what you do and who you do things for**, so you can make intentional decisions about how to invest your time, money and energy.
### [[7 Intentional Questions To Ask Yourself Every Day#^de9f88|How does this add value to my life?]]
We trade away our precious lives in little moments [...] We often spend our lives on things that give us little value in return.
Ask everything you own and everything you do to **earn its place in your life** by asking the question, “How does this add value?” Whether its a new purchase or another task on your to-do list, make sure its worth it.
> [!info]
> If you cant quickly explain in very specific terms how something is adding value to your life, then odds are it isnt.
### [[7 Intentional Questions To Ask Yourself Every Day#^8419b3|What am I giving up?]]
**Everything in life has a tradeoff**. When you put a name to the tradeoffs associated with any decision, it helps you see things more clearly. Again, its not about right or wrong, but it is about alignment.
Whenever you decide to do or buy something, make sure you think about what youre giving up to make it happen.
### [[7 Intentional Questions To Ask Yourself Every Day#^b44977|Am I being honest with myself?]]
Its important to check that youre being honest with yourself, because if youre not, none of your other answers really matter.

View file

@ -0,0 +1,74 @@
---
tags: dev
---
# Multi Language Library
To create a library that can be used in multiple languages, the language that
is going to implement the library needs to support [[notes/ffi|FFI]] with the language
that the library is written in.
With this in, we can use the following in our favor:
- It's impossible that every language support every other language.
- For compatibility reasons, Almost every language supports C's [[notes/abi|ABI]] for their [[notes/ffi|FFI]].
- Some compiled language has the avility to compile a C's _"dynamic library"_ (`.so` file in unix and `.dll` in windows).
- The [[notes/ffi|FFI]] use a _"dynamic library"_ to work.
So, in conclusion: **we can use whatever language that supports compiling to C's ABI to build multi language libraries**
## List of language that compiles to C's ABI
### [[Go]]
To produce a shared library, you need to compile it with compile with: `go build -buildmode=c-shared`.
Note that the documentation says you need to specify with functions needs to be exported:
> Build the listed main package, plus all packages it imports, into a C shared
> library. The only callable symbols will be those functions exported using a
> cgo //export comment. Requires exactly one main package to be listed.
Example:
src/go/main.go:
```go
package main
import "C"
import "fmt"
//export helloLib
func helloLib(x C.int) {
fmt.Printf("Hello from Go! x=%d\n", x)
}
func main() {}
```
src/c/main.c:
```c
void helloLib(int);
int main() {
helloLib(12345);
}
```
Building and running:
```bash
go build -buildmode=c-shared -o libmy.so ./src/go/
gcc -o test src/c/main.c libmy.so
./test
Hello from Go! x=12345
```
Sources:
- <https://stackoverflow.com/questions/75035609/can-go-executable-be-used-as-a-dynamic-library>
- <https://pkg.go.dev/cmd/go#hdr-Build_modes>
## List of languages that has support for FFI with C

View file

@ -0,0 +1,9 @@
---
title: "None"
tags:
created: 2024-10-20 17:02
---
# None

View file

@ -0,0 +1,16 @@
---
title: "Postgres: Export a query to CSV on the client side"
tags: postgres
created: 2024-09-27 09:20
---
# Postgres: Export a query to CSV on the client side
Execute the follow sentence in an **interactive session** of psql:
```sql
\copy (
Select * From foo
) TO '/tmp/test.csv' WITH CSV DELIMITER ';' HEADER
```

View file

@ -0,0 +1,9 @@
---
title: "Untitled"
tags:
created: 2024-10-20 16:44
---
# Untitled