Skip to content

Commit

Permalink
Some minor modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeMarcelino committed Jun 27, 2024
1 parent aa624d7 commit 41c88d1
Show file tree
Hide file tree
Showing 23 changed files with 326 additions and 38 deletions.
4 changes: 2 additions & 2 deletions 0651-genexp.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#programming #language #python #functional

- Save more memory comparable to [[ndtq-listcomp]]
- Can be used with tuples, arrays and other sequences
- Save the cost to build a list
- Can be used with [[82os-python-tuples]], arrays and other sequences
- Save the cost to build a [[aw9b-python-list]]

```python
>>> symbols
Expand Down
3 changes: 2 additions & 1 deletion 17dv-inherit.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# Inherit
#nix #nixos #programming #language

It is a way to assign a variable inside a scope that is nested inside another scope using the same name
- It is a way to assign a variable inside a scope that is nested inside another scope using the same name
- They use expressions [[af9g-nix-let-in]] to assign variables before.


```nix
Expand Down
14 changes: 8 additions & 6 deletions 4dyw-python-sequences.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Python Sequences
#programming #language #python #datastructure

Containers: [[aw9b-python-list]]#, [[82os-python-tuples]]#, collections.deque → It has a reference of the object
Flat: string, bytes, array.array → It stores the value of the object itself
- Containers: [[aw9b-python-list]]#, [[82os-python-tuples]]#, collections.deque → It has a reference of the object
- Flat: string, bytes, array.array → It stores the value of the object itself

Mutable: [[aw9b-python-list]]#, bytearray, array.array, deque
* You can change the sequence itself
Immutable: tuple, string, bytes
* Sequence does not change, and a new one is created
- Mutable: [[aw9b-python-list]]#, bytearray, array.array, deque
* You can change the sequence itself
- Immutable: tuple, string, bytes
* Sequence does not change, and a new one is created
- Operations on sequences: [[5vht-and-with-sequences]]#
- Generation expression: [[0651-genexp]]#
7 changes: 5 additions & 2 deletions 5b36-python-data-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ class FrenchDeck:
```

Implementing python data model it is possible above is possible to use it in the iteration `for` or
[[aw9b-python-list]]#.
Avoid [[82os-python-tuples]]# for mutable objects.
[[aw9b-python-list]].
Avoid [[82os-python-tuples]] for mutable objects.

### References
Ramanlho, 2022, Chapter 1
1 change: 1 addition & 0 deletions 5quz-why-do-we-take-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
[[3j89-feedback-loop]] showing if your notes are good or not.
- Rely on the system you are used to writing you notes. Focusing on the ideas
- There is a correct way to write [[zkr2-question-about-a-topic]].
- We take notes to learn things [[7h4q-how-to-learn-and-understand]]#
13 changes: 13 additions & 0 deletions 5vht-and-with-sequences.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# + and * with Sequences
#python #programming #language #efficiency

- It is the operation `_add_` and `_mul_`.
- `a += b` is the operation `_iadd_`. When it is not implemented, the **fallback** is the `_add_`
- `_iadd_` is the `list.extend()`. Is the same for `bytearray` and `array.array`.
- For `immutable` objects, the `_iadd_` is similar to the `_add_`.

> [!warning]
> **PERFORMANCE**: Append on `imutable` objects are inefficient
> [!warning]
> **BUG**: Does not put `mutable` objects on `immutable` ones.
35 changes: 35 additions & 0 deletions 7h4q-how-to-learn-and-understand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# How to learn and understand
#notes #writing #learn #system #organization #method

- Familiarity is as same of understand.
- If we did not understand we cannot explain something with our words
- Try to search for patterns, detect the distinction and similarities between the concepts and questions
- Reformulate questions and piece of information is more important than to have extensively knowledge base.
- Learn how to manipulate the [[ndec-literature-notes]] and [[wz0b-permanent-notes]], reformulate it, choose the right
words, try to search for gist/patterns. Which is important, what are the important mental models
- Each piece of information is source for other piece of information, make as many connections as possible, which
meaningful context.
- Which aspects are important to write?
- [[8imv-slip-box]] help to create distinctions between concepts and things in general using connections. Use it to
answer the questions you have in mind.
- Some ideas/questions can appear in the middle of research/findings of other ideas, you do not need to answer it right
at the moment, store it on the [[8imv-slip-box]].
- Write down the note make you argumentation being coherent and be discussed independently of the author.
- Connection is elaboration (Writing, take notes, thinking about connections)
- [[8imv-slip-box]] long-term memory, while brain takes care of creativity

> [!tip] Quote
> If learning is your goal, cramming is an irrational act
> [!tip] Quote
> what does this all mean for my own research and the questions I think about in my [[8imv-slip-box]]? This is just
> another way of asking: Why did the aspects I wrote down catch my interest?
> [!tip] Quote
> Learning would be not so much about saving information, like on a hard disk, but about building connections and
> bridges between pieces of information to circumvent the inhibition mechanism in the right moment. It is about making
> sure that the right "cues" trigger the right memory, about how we can think strategically to remember the most
> useful information when we need it.
### References
Ahrens, 2017, p82-100
3 changes: 3 additions & 0 deletions 7t2m-how-to-take-smart-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
topic. If you are writing something that you did not understand correctly the notes will show that you not concise
about a specific topic.
- When writing notes don't be a critic, do this after the notes is already done or during the proofread.
- [[5quz-why-do-we-take-notes]]#
- Handwriting notes is better to learning because they need to be more assertive because we write slow
[[mjpl-handwriting-with-our-words]]#.

### References

Expand Down
3 changes: 3 additions & 0 deletions 82os-python-tuples.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
> [!warning]
> `sort` return a new object for tuple. Take a look on [[pcvu-sort-and-sorted]].
### References
Ramalho, 2022, Chapter 1
4 changes: 4 additions & 0 deletions 9n4u-python-dictionary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Python Dictionary
#python #datastructure #language #programming

- [[x4fp-dictcomp]]#
48 changes: 48 additions & 0 deletions a1mq-unpacking-sequences-and-iterables.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Unpacking Sequences and Iterables
#python #programming #datastrcture #language

- Works with any iterable: [[aw9b-python-list]], [[x4fp-dictcomp]], [[82os-python-tuples]]
- Parallel assignment

```python
# tuples
>>> lax_coordinates = (33.9425, -118.4080)
>>> latitude, longitude = lax_coordinates
>>> latitude
33.9425

>>> T = (20, 8)
>>> divmod(*t)
(2,4)
```
- Getting the last part
```python
>>> _ , filename = os.path.split('/home/luciano.ssh/id.rsa.pub')
>>> filename
'id_rsa.pub'
```

- Getting the excess
```python
>>> a, b, *rest = range(5)
>>> a, b, rest
(0, 1, [2,3,4])
>>> a, *body, c, d = range(5)
>>> a, body, c, d
(0, [1,2], 3, 4)
>>> fun(*[1,2],3,*range(4,7))
>>> *range (4), 4
(0,1,2,3,4)
>>> [*range(4),4]
[0,1,2,3,4]
```
* Dictionaries
```python
>>> def dump(*kwargs)
return
>>> dump(**{'x':1}, y=2, **{'z':3})
{'x':1, 'y':2, 'z':3}
>>> {'a':0, **{'x':1}, 'y':2, *{'z':3,'x':4}} # In that case the second x overlap the value of the first one.
```

There another way to unpacking things in pythons, it is [[phk2-pattern-matching-or-destructuring]]#
1 change: 1 addition & 0 deletions aw9b-python-list.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@

- [[ndtq-listcomp]]#
- [[j7wj-when-list-is-not-the-best-option-python]]#
- [[nfgb-slicing]]
10 changes: 5 additions & 5 deletions b4vt-clojure.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Clojure
#functional #programming #clojure

- [[vdzq-sequence-abstraction]]
- [[hpky-contagion]]
- [[p09q-ratio]]
- [[qkll-first-rest-and-cons]]
- [[worn-collection-abstraction]]
- [[vdzq-sequence-abstraction]]#
- [[hpky-contagion]]#
- [[p09q-ratio]]#
- [[worn-collection-abstraction]]#
- [[vtpp-bigint-bigdecimal]]#
7 changes: 1 addition & 6 deletions ic18-nix.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# Nix
# NixOS
#programming #functional #nix #nixos

- [[17dv-inherit]]
- [[38pe-lookup-paths]]
- [[6b5l-string-interpolation]]
- [[t58q-nix-language]]
- [[af9g-nix-let-in]]
- [[f8cg-nix-shell-environment]]
- [[j8ti-nixos-package]]
- [[z8de-attribute-set]]
24 changes: 14 additions & 10 deletions index.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# My Zettelkasten
#root

This is my Zettelkasten, you will encounter things related to **programming**, **zettelkasten** itself and **note
taking** and etc.
This is my Zettelkasten, you will encounter things related to **programming**, **zettelkasten** itself and **note-taking** and, etc.

## Programming

- [[tds4-python]]
- [[ic18-nix]]
- [[b4vt-clojure]]
- [[tds4-python]]#
- [[b4vt-clojure]]#

## Note Taking
- [[38lz-zettelkasten]]
- [[7t2m-how-to-take-smart-notes]]
- [[tn2j-gtd-getting-things-done]]
## Note-Taking
- [[38lz-zettelkasten]]#
- [[7t2m-how-to-take-smart-notes]]#
- [[tn2j-gtd-getting-things-done]]#

##
## Linux
- [[ic18-nix]]#
- [[wwgd-shebang]]#

## Misc

- [[9ufi-zeigarnik-effect]]#
1 change: 1 addition & 0 deletions j8ti-nixos-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ A package in NixOS can have multiple programs or none of them. It can be a libra
$ nix-shell -p cowsay --run "cowsay nix"
```
The code indicating that the package `cowsay` contains a binary which will run the code with argument `"cowsay nix"`
- The [[38pe-lookup-paths]]# is where path packages are found.

## Pinning Packages
- use a commit
Expand Down
41 changes: 41 additions & 0 deletions nfgb-slicing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Slicing
#python #programming #datastructure #language

- `s[a:b:c]`, `a` and `b` are first and second dimension, `c` is the **stride**.
- It is possible to use **slicing** to assign values

```python
>>> s = 'bicycle'
>>> s[::3]
'bye'
>>> s[::-1]
'elcycle'
>>> s[::-2]
'eccb' #bicycle
>>> l = list(range(10))
>>> l[3::3] = [11,22]
[0,1,20,11,5,22,9]
```

```python
>>> invoice = """
0.....6.................................40........52...55........
1909 Pimoroni PiBrella $17.50 3 $52.50
1489 6mm Tactile Switch x20 $4.95 2 $9.90
1510 Panavise Jr. - PV-201 $28.00 1 $28.00
1601 PiTFT Mini Kit 320x240 $34.95 1 $34.95
"""

>>> SKU = slice(0, 6)
>>> DESCRIPTION = slice(6, 40)
>>> UNIT_PRICE = slice(40, 52)
>>> QUANTITY = slice(52, 55)
>>> ITEM_TOTAL = slice(55, None)
>>> line_items = invoice.split('\n')[2:]
>>> for item in line_items:
print(item[UNIT_PRICE], item[DESCRIPTION])
$17.50 imoroni PiBrella
$4.95 mm Tactile Switch x20
$28.00 anavise Jr. - PV-201
$34.95 iTFT Mini Kit 320x240
```
88 changes: 88 additions & 0 deletions phk2-pattern-matching-or-destructuring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Pattern Matching or Destructuring
#python #programming #datastructure #language

- Destructuring like `Clojure` and `Scala`
- Pattern match are way to `match/case` things like `if/else` conditional.
- For `dict` the `order` of `key` does **not matter** and are possible to have `partial`. Which are different from
[[4dyw-python-sequences]].

```python
# Dictionary
# tag::DICT_MATCH[]
def get_creators(record: dict) -> list:
match record:
case {'type': 'book', 'api': 2, 'authors': [*names]}: # <1>
return names
case {'type': 'book', 'api': 1, 'author': name}: # <2>
return [name]
case {'type': 'book'}: # <3>
raise ValueError(f"Invalid 'book' record: {record!r}")
case {'type': 'movie', 'director': name}: # <4>
return [name]
case _: # <5>
raise ValueError(f'Invalid record: {record!r}')
# end::DICT_MATCH[]

>>> b1 = dict(api=1, author='Douglas Hofstadter',
... type='book', title='Gödel, Escher, Bach')
>>> get_creators(b1)
['Douglas Hofstadter']
>>> from collections import OrderedDict
>>> b2 = OrderedDict(api=2, type='book',
... title='Python in a Nutshell',
... authors='Martelli Ravenscroft Holden'.split())
>>> get_creators(b2)
['Martelli', 'Ravenscroft', 'Holden']
>>> get_creators({'type': 'book', 'pages': 770})
Traceback (most recent call last):
...
ValueError: Invalid 'book' record: {'type': 'book', 'pages': 770}
>>> get_creators('Spam, spam, spam')
Traceback (most recent call last):
...
ValueError: Invalid record: 'Spam, spam, spam'
# end::DICT_MATCH_TEST[]
"""
```
```python
# Dictionary partial with destructuring
>>> food = dict (category='ice cream', flavor='vanilla', cost=199)
>>> match food:
case {'category': 'ice cream', **details}: # Details capture the rest of the values
print(f'Ice cream details: {details}')
```
## Sequence Pattern
- Sequence pattern => () = []
- str, bytes = bytearray are treated atomic, they need to be converted into tuple or list
- The symbol `_` can be used multiple times on the **pattern matching**
- We can use classes or `str`, `float` or `classes` to runtime check the type of pattern match
```python
case [str(name), _, _, (float(lat), float(lon)), as coord] lon <= 0 # Runtime check with float and str
```
- The "lon ≤ 0" part is known as **guard rail**. They are evaluated only if match is matched.
```python
case ['define', Symbol as name, value_exp] # Test if name is Symbol
```
```python
metro_areas = [
('Tokyo', 'JP', 36.933, (35.689722, 139.691667)),
('Delhi NCR', 'IN', 21.935, (28.613889, 77.208889)),
('Mexico City', 'MX', 20.142, (19.433333, -99.133333)),
('New York-Newark', 'US', 20.104, (40.808611, -74.020386)),
('São Paulo', 'BR', 19.649, (-23.547778, -46.635833)),
]
def main():
print(f'{"":15} | {"latitude":>9} | {"longitude":>9}')
for record in metro_areas:
match record:
case [name, _, _, (lat, lon)] if lon <= 0:
print(f'{name:15} | {lat:9.4f} | {lon:9.4f}')
main()
```
6 changes: 6 additions & 0 deletions t58q-nix-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
- The only impurities on the language are the [[hc70-build-inputs]]#, that are composed of file system.
- Nix reference files using the content hash. If It does not know its content, it read the file during the evaluation of
the derivations
- [eaf9g-nix-let-in]]# are expression on on language that access variable inside itself, or a way to assign variable recursively
- There is something similar to [[af9g-nix-let-in]]# is the [[z8de-attribute-set]]# with rec propriety. The variable can
be used in the same scope it was defined.
- Nix language can use variables on the code using [[6b5l-string-interpolation]]#. It is possible to escape them to no
make confuse with bash variables.
- [[17dv-inherit]]# is a way to assign variable on a nested scope.


```nix
Expand Down
Loading

0 comments on commit 41c88d1

Please sign in to comment.