@burakboduroglu/penote 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ ### About Javascript-Notes 🚀
2
+
3
+ Kişisel JavaScript notları — Markdown formatında düzenlenmiştir.
4
+
5
+ ### Table of Contents 📚
6
+
7
+ | File Name | Topics |
8
+ | --------- | ------ |
9
+ | [javascirpt_array_methods.md](javascirpt_array_methods.md) | JS Array Methods |
10
+ | [closures_currying_compose.md](closures_currying_compose.md) | Closures, Currying, Compose |
11
+ | [async_js.md](async_js.md) | Fetch API, Promise, async/await |
12
+ | [regex_part_1.md](regex_part_1.md) | Regular expressions (1) |
13
+
14
+ ---
15
+
16
+ [← README](../README.md)
@@ -0,0 +1,258 @@
1
+ # Regular Expressions Cheat Sheet PART - 1
2
+
3
+ Regular expressions are a powerful tool for matching patterns in text. This blog post will introduce some of the basic syntax for regular expressions and how to use them in JavaScript.
4
+
5
+ ## Creating a Regular Expression
6
+
7
+ There are two ways to create a regular expression in JavaScript. The first is to use the `RegExp` constructor:
8
+
9
+ ```javascript
10
+ let text = "Programming is my favorite thing to do in the world.";
11
+
12
+ let regex1 = new RegExp("Programming");
13
+ let regex2 = /Programming/;
14
+
15
+ // .test()
16
+ console.log(regex1.test(text)); // true
17
+ console.log(regex2.test(text)); // true
18
+
19
+ // .exec()
20
+ console.log(regex1.exec(text)); // ["Programming", index: 0, input: "Programming is my favorite thing to do in the world."]
21
+ console.log(regex2.exec(text)); // ["Programming", index: 0, input: "Programming is my favorite thing to do in the world."]
22
+
23
+ // .match()
24
+ console.log(text.match(regex)); // ["Programming", index: 0, input: "Programming is my favorite thing to do in the world."]
25
+
26
+ // .search()
27
+ console.log(text.search(regex)); // 0
28
+
29
+ // .replace()
30
+ console.log(text.replace(regex, "Coding")); // Coding is my favorite thing to do in the world.
31
+
32
+ // .split()
33
+ console.log(text.split(regex)); // ["", " is my favorite thing to do in the world."]
34
+
35
+ // /\s/
36
+ console.log(text.split(/\s/)); // ["Programming", "is", "my", "favorite", "thing", "to", "do", "in", "the", "world."]
37
+ ```
38
+
39
+ `.test()` returns a boolean value indicating whether or not the regular expression matches the text.
40
+ `.exec()` returns an array containing the matched text, the index of the match, and the input string.
41
+ `.match()` returns an array containing the matched text, the index of the match, and the input string.
42
+ `.search()` returns the index of the first match.
43
+ `.replace()` returns a new string with the matched text replaced by the second argument.
44
+ `.split()` returns an array of strings split at the matched text.
45
+ `/\s/` is a regular expression that matches whitespace characters.
46
+
47
+ > exec and match are the same, but `match` is a string method and `exec` is a RegExp method.
48
+
49
+ ### Flags
50
+
51
+ Regular expressions can also have flags. Flags are added to the end of the regular expression and change the behavior of the regular expression. Usage of flags is demonstrated below:
52
+
53
+ - /pattern/flags
54
+ - new RegExp("pattern", "flags")
55
+
56
+ Flags
57
+
58
+ - `g` - global, match all instances of the pattern
59
+ - `i` - ignore case, match regardless of case
60
+ - `m` - multiline, match across multiple lines
61
+
62
+ ```javascript
63
+ let text = "Programming is my favorite thing to do in the world.";
64
+ let regex1 = /o\s/;
65
+
66
+ console.log(text.match(regex1)); // ["o ", index: 13, input: "Programming is my favorite thing to do in the world."]
67
+
68
+ let regex2 = /o\s/g;
69
+
70
+ console.log(text.match(regex2)); // ["o ", "o "]
71
+
72
+ let regex3 = /G\s/gi;
73
+
74
+ console.log(text.match(regex3)); // ["g ", "g "]
75
+ ```
76
+
77
+ Explanation of the above code:
78
+
79
+ - `regex1` matches the first instance of the pattern.
80
+ - `regex2` matches all instances of the pattern.
81
+ - `regex3` matches all instances of the pattern regardless of case.
82
+
83
+ ## Recommended Resources
84
+
85
+ Regex Pal is a great tool for testing regular expressions: https://www.regexpal.com/
86
+
87
+ ## Wildcards
88
+
89
+ Wildcards are characters that match any character. The wildcard character is `.`. The following example demonstrates the use of the wildcard character:
90
+
91
+ ```javascript
92
+ let text = "Programming is my favorite thing to do in the world.";
93
+ let regex1 = /w.r/g;
94
+
95
+ console.log(text.match(regex1)); // ["wor"]
96
+
97
+ let regex2 = /w\./gi;
98
+
99
+ console.log(text.match(regex2)); // ["w."]
100
+ ```
101
+
102
+ Explanation of the above code:
103
+
104
+ - `regex1` matches any character between `w` and `r`.
105
+ - `regex2` matches any character between `w` and `.`.
106
+
107
+ ```javascript
108
+ let text = "He is holding his hat in his hand.";
109
+ let regex1 = /h../g;
110
+
111
+ console.log(text.match(regex1)); // ["hol", "his", "hat", "his", "han"]
112
+
113
+ let regex2 = /h../gi;
114
+
115
+ console.log(text.match(regex2)); // ["He ", "hol", "his", "hat", "his", "han"]
116
+ ```
117
+
118
+ ## Control Characters
119
+
120
+ - `\t` is a tab character
121
+ - `\n` is a newline character
122
+ - `\r` is a carriage return character
123
+ - `\v` is a vertical tab character
124
+
125
+ ## Using Character Sets
126
+
127
+ ```javascript
128
+ let text1 = "Gray, Grey, Grab";
129
+ let regex1 = /Gr[ae]y/g;
130
+
131
+ console.log(text.match(regex1)); // ["Gray", "Grey"]
132
+
133
+ let text2 = "Programming is my favorite thing to do in the world.";
134
+ let regex2 = /[aei][ w]/g;
135
+
136
+ console.log(text2.match(regex2)); // "e " -> from "favorite", "e " -> from "the"
137
+ ```
138
+
139
+ ## Specifying Ranges
140
+
141
+ ```javascript
142
+ let text1 = "1 11 a b c abc";
143
+ let regex1 = /[1-6a-z]/g;
144
+
145
+ console.log(text1.match(regex1)); // ["1", "1", "a", "b", "c", "a", "b", "c"]
146
+
147
+ let text2 = "13-20";
148
+ let regex2 = /[10-20]/;
149
+
150
+ console.log(text2.match(regex2)); // ["1","2","0"]
151
+ ```
152
+
153
+ ## Excluding a Character Set
154
+
155
+ ```javascript
156
+ let text1 = "1 2 33 123 12 93 85 abcd";
157
+ let regex1 = /[^0-9]/;
158
+
159
+ console.log(text1.match(regex1)); // a b c d and all spaces
160
+ ```
161
+
162
+ ## Shorthand of Character Set
163
+
164
+ - `\d` -> [0-9]
165
+ - `\w` -> [a-zA-Z0-9_]
166
+ - `\s` -> [ \t\r\n]
167
+
168
+ ```javascript
169
+ let text1 = "1 2 33 123 12 93 85 abcd";
170
+ let regex1 = /\d/g;
171
+
172
+ console.log(text1.match(regex1)); // ["1", "2", "3", "3", "1", "2", "9", "3", "8", "5"]
173
+
174
+ let text2 = "Programming is my favorite thing to do in the world.";
175
+ let regex2 = /\w/g;
176
+
177
+ console.log(text2.match(regex2)); // ["P", "r", "o", "g", "r", "a", "m", "m", "i", "n", "g", "i", "s", "m", "y", "f", "a", "v", "o", "r", "i", "t", "e", "t", "h", "i", "n", "g", "t", "o", "d", "o", "i", "n", "t", "h", "e", "w", "o", "r", "l", "d"]
178
+
179
+ let text3 = "Programming is my favorite thing to do in the world.";
180
+ let regex3 = /\s/g;
181
+
182
+ console.log(text3.match(regex3)); // [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " "]
183
+ ```
184
+
185
+ - `\D` -> [^0-9]
186
+ - `\W` -> [^a-zA-Z0-9_]
187
+ - `\S` -> [^ \t\r\n]
188
+
189
+ ```javascript
190
+ let text1 = "1 2 33 123 12 93 85 abcd";
191
+ let regex1 = /\D/g;
192
+
193
+ console.log(text1.match(regex1)); // [" ", " ", " ", " ", " ", " ", " ", "a", "b", "c", "d"]
194
+ ```
195
+
196
+ ## Repetitions
197
+
198
+ - `*` -> It used to match 0 or more times
199
+ - `+` -> It used to match 1 or more times
200
+ - `?` -> It used to match 0 or 1 time
201
+
202
+ ### Greedy and Lazy Matching
203
+
204
+ `Greedy matching` is the default behavior of regular expressions. Greedy matching means that the regular expression will match as many characters as possible. `Lazy matching` means that the regular expression will match as few characters as possible.
205
+
206
+ ```javascript
207
+ let html = "<h1>Heading</h1><p>Paragraph</p>";
208
+ let h1Regex = /<h1>.*<\/h1>/;
209
+
210
+ console.log(html.match(h1Regex)); // ["<h1>Heading</h1>"]
211
+ ```
212
+
213
+ ### Specifying the Repetition Amount
214
+
215
+ - `{n}` -> It used to match exactly n times
216
+ - `{n,}` -> It used to match at least n times
217
+ - `{n,m}` -> It used to match at least n times and at most m times
218
+
219
+ ```javascript
220
+ let text1 = "Programming is my favorite thing to do in the world.";
221
+ let regex1 = /\w{3,5}/g;
222
+
223
+ console.log(text1.match(regex1)); // ["Program", "ming", "favor", "ite", "thing", "world"]
224
+ ```
225
+
226
+ ### Example
227
+
228
+ - Validate phone numbers, check to see if it matches these formats:
229
+ - (nnn)-nnn-nnnn
230
+ - nnn.nnn.nnnn
231
+ - nnn-nnn-nnnn
232
+ - nnnnnnnnnn
233
+ - (nnn)nnnnnnn
234
+
235
+ `Solution`:
236
+
237
+ ```javascript
238
+ let phoneNumber = 555 - 444 - 3333;
239
+ let regex = /\(?\d{3}\)?-?\d{3}-?\d{4}/;
240
+
241
+ console.log(phoneNumber.match(regex));
242
+ ```
243
+
244
+ `Explanation`: /\(?\d{3}\)?-?\d{3}-?\d{4}/
245
+
246
+ - `\(?` -> It matches 0 or 1 time "("
247
+ - `\d{3}` -> It matches exactly 3 times digit
248
+ - `\)?` -> It matches 0 or 1 time ")"
249
+ - `-?` -> It matches 0 or 1 time "-"
250
+ - `\d{3}` -> It matches exactly 3 times digit
251
+ - `-?` -> It matches 0 or 1 time "-"
252
+ - `\d{4}` -> It matches exactly 4 times digit
253
+
254
+ If you have any recommendations or feedback, please feel free to reach out to me on comment. However Part-2 will be coming soon. Stay tuned.
255
+
256
+ ## Follow me on GitHub
257
+
258
+ [GitHub](https://github.com/burakboduroglu)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023–2026 Burak Boduroğlu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ ## MongoDB Basics - 1 🚀👩‍🚀
@@ -0,0 +1,13 @@
1
+ ### About MongoDB-Notes 🚀
2
+
3
+ Kişisel MongoDB notları — Markdown formatında düzenlenmiştir.
4
+
5
+ ### Table of Contents 📚
6
+
7
+ | File Name | Topics |
8
+ | --------- | ------ |
9
+ | [mongodb_basic_1.md](mongodb_basic_1.md) | MongoDB temelleri |
10
+
11
+ ---
12
+
13
+ [← README](../README.md)
@@ -0,0 +1,142 @@
1
+ ## Advanced Python - 1 🚀👩‍🚀
2
+
3
+ ### - Enumerate
4
+
5
+ - Enumerate is a built-in function of Python. It allows us to loop over something and have an automatic counter.
6
+
7
+ ```python
8
+ # Example 1
9
+ for i, char in enumerate('Hello'):
10
+ print(i, char)
11
+
12
+ # Output -> 0 H 1 e 2 l 3 l 4 o
13
+
14
+ # Example 2
15
+ for i, char in enumerate(list(range(100))):
16
+ if char == 50:
17
+ print(f'The index of 50 is: {i}')
18
+ ```
19
+
20
+ ### - Zip
21
+
22
+ - Zip is a built-in function of Python. It allows us to loop over two lists at the same time.
23
+
24
+ ```python
25
+ # Example 1
26
+ list1 = [1, 2, 3]
27
+ list2 = [10, 20, 30]
28
+
29
+ for item in zip(list1, list2):
30
+ print(item)
31
+ # Output -> (1, 10) (2, 20) (3, 30)
32
+
33
+ # Example 2
34
+ list1 = [1, 2, 3]
35
+ list2 = [10, 20, 30, 40, 50]
36
+ list3 = ['a', 'b', 'c', 'd', 'e']
37
+
38
+ for item in zip(list1, list2, list3):
39
+ print(item)
40
+ # Output -> (1, 10, 'a') (2, 20, 'b') (3, 30, 'c')
41
+
42
+ # Example 3
43
+ list1 = [1, 2, 3]
44
+ list2 = [10, 20, 30, 40, 50]
45
+ list3 = ['a', 'b', 'c', 'd', 'e']
46
+
47
+ for a, b, c in zip(list1, list2, list3):
48
+ print(a, b, c)
49
+ # Output -> 1 10 a 2 20 b 3 30 c
50
+
51
+ # Example 4
52
+ list1 = [1, 2, 3]
53
+ list2 = [10, 20, 30, 40, 50]
54
+ list3 = ['a', 'b', 'c', 'd', 'e']
55
+
56
+ print(list(zip(list1, list2, list3)))
57
+ # Output -> [(1, 10, 'a'), (2, 20, 'b'), (3, 30, 'c')]
58
+ ```
59
+
60
+ ### - Unzip
61
+
62
+ - Unzip is a built-in function of Python. It allows us to unzip a list.
63
+
64
+ ```python
65
+ # Example 1
66
+ list1 = [1, 2, 3]
67
+ list2 = [10, 20, 30]
68
+
69
+ unzipped = list(zip(list1, list2))
70
+ print(unzipped)
71
+ # Output -> [(1, 10), (2, 20), (3, 30)]
72
+ ```
73
+
74
+ ### - List Comprehension
75
+
76
+ - List comprehension is a way to create a list using for loop in a single line.
77
+
78
+ ```python
79
+ # Example 1
80
+ my_list = [char for char in 'hello']
81
+ print(my_list)
82
+ # Output -> ['h', 'e', 'l', 'l', 'o']
83
+
84
+ # Example 2
85
+ my_list = [num for num in range(0, 8)]
86
+ print(my_list)
87
+ # Output -> [0, 1, 2, 3, 4, 5, 6, 7]
88
+
89
+ # Example 3
90
+ my_list = [num**2 for num in range(0, 5)]
91
+ print(my_list)
92
+ # Output -> [0, 1, 4, 9, 16]
93
+
94
+ # Example 4
95
+ my_list = [num**2 for num in range(0, 5) if num % 2 == 0]
96
+ print(my_list)
97
+ # Output -> [0, 4, 16]
98
+
99
+ # Example 5
100
+ my_list = [x*y for x in [2, 4, 6] for y in [1, 10, 1000]]
101
+ print(my_list)
102
+ # Output -> [2, 20, 2000, 4, 40, 4000, 6, 60, 6000]
103
+
104
+ # Example 6
105
+ my_list = [x*y for x in [2, 4, 6] for y in [1, 10, 1000] if x*y > 50]
106
+ print(my_list)
107
+ # Output -> [60, 6000]
108
+
109
+ # Example 7
110
+ my_list = [x if x % 2 == 0 else 'ODD' for x in range(0, 10)]
111
+ print(my_list)
112
+ # Output -> [0, 'ODD', 2, 'ODD', 4, 'ODD', 6, 'ODD', 8, 'ODD']
113
+ ```
114
+
115
+ ### - Dictionary Comprehension
116
+
117
+ - Dictionary comprehension is a way to create a dictionary using for loop in a single line.
118
+
119
+ ```python
120
+ # Example 1
121
+ simple_dict = {
122
+ 'a': 1,
123
+ 'b': 2
124
+ }
125
+
126
+ my_dict = {key: value**2 for key, value in simple_dict.items()}
127
+ print(my_dict)
128
+ # Output -> {'a': 1, 'b': 4}
129
+ ```
130
+
131
+ ### - Set Comprehension
132
+
133
+ - Set comprehension is a way to create a set using for loop in a single line.
134
+
135
+ ```python
136
+ # Example 1
137
+ simple_set = {1, 2, 3}
138
+
139
+ my_set = {num for num in simple_set}
140
+ print(my_set)
141
+ # Output -> {1, 2, 3}
142
+ ```
@@ -0,0 +1,155 @@
1
+ ## Advanced Python - 2 🚀👩‍🚀
2
+
3
+ ### - kwargs
4
+
5
+ - kwargs allows us to pass a variable number of keyword arguments to a function. We use the \*\* operator to unpack the dictionary into keyword arguments.
6
+ - kwargs is a dictionary.
7
+
8
+ ```python
9
+ # Example 1
10
+ def func(**kwargs):
11
+ print(kwargs)
12
+
13
+ func(name='name_1', age=30)
14
+ # Output -> {'name': 'name_1', 'age': 30}
15
+ ```
16
+
17
+ ### - args
18
+
19
+ - args allows us to pass a variable number of arguments to a function. We use the \* operator to unpack the list into positional arguments.
20
+
21
+ - args is a tuple.
22
+
23
+ ```python
24
+ # Example 1
25
+ def func(*args):
26
+ print(args)
27
+
28
+ func(1, 2, 3, 4, 5)
29
+ # Output -> (1, 2, 3, 4, 5)
30
+
31
+ # Example 2
32
+ def super_func(*args, **kwargs):
33
+ total = 0
34
+ for items in kwargs.values():
35
+ total += items
36
+ return sum(args) + total
37
+ print(super_func(1, 2, 3, 4, 5, num1=5, num2=10))
38
+ # Output -> 40
39
+ ```
40
+
41
+ ### - global
42
+
43
+ - global allows us to modify a global variable inside a function.
44
+
45
+ ### - lambda
46
+
47
+ - lambda is a way to create an anonymous function (a function without a name).
48
+ - lambda is a one-line function.
49
+
50
+ ```python
51
+ # Example 1
52
+ square = lambda num: num * num
53
+ print(square(2))
54
+ # Output -> 4
55
+
56
+ # Example 2
57
+ add = lambda a, b: a + b
58
+ print(add(2, 3))
59
+ # Output -> 5
60
+ ```
61
+
62
+ ### - filter
63
+
64
+ - filter is a built-in function of Python. It allows us to filter out items in an iterable (list, tuple, etc.) that don't match a certain condition.
65
+
66
+ ```python
67
+ # Example 1
68
+ def check_even(num):
69
+ return num % 2 == 0
70
+
71
+ my_nums = [1, 2, 3, 4, 5, 6]
72
+ print(list(filter(check_even, my_nums)))
73
+ # Output -> [2, 4, 6]
74
+
75
+ # Example 2
76
+ my_nums = [1, 2, 3, 4, 5, 6]
77
+ print(list(filter(lambda num: num % 2 == 0, my_nums)))
78
+ # Output -> [2, 4, 6]
79
+ ```
80
+
81
+ ### - map
82
+
83
+ - map is a built-in function of Python. It allows us to execute a function for each item in an iterable (list, tuple, etc.).
84
+
85
+ ```python
86
+ # Example 1
87
+ def square(num): return num * num
88
+
89
+ my_nums = [1, 2, 3, 4, 5]
90
+ print(list(map(square, my_nums)))
91
+ # Output -> [1, 4, 9, 16, 25]
92
+
93
+ # Example 2
94
+ my_nums = [1, 2, 3, 4, 5]
95
+ print(list(map(lambda num: num * num, my_nums)))
96
+ # Output -> [1, 4, 9, 16, 25]
97
+
98
+ # Example 3
99
+ def splicer(mystring):
100
+ if len(mystring) % 2 == 0:
101
+ return 'EVEN'
102
+ else:
103
+ return mystring[0]
104
+
105
+ names = ['Andy', 'Eve', 'Sally']
106
+ print(list(map(splicer, names)))
107
+ # Output -> ['EVEN', 'E', 'S']
108
+
109
+
110
+ # Example 4
111
+ def check_even(num):
112
+ return num % 2 == 0
113
+
114
+ my_nums = [1, 2, 3, 4, 5, 6]
115
+ print(list(map(lambda num: num * 2, filter(check_even, my_nums))))
116
+ # Output -> [4, 8, 12]
117
+ ```
118
+
119
+ ### - keyword arguments
120
+
121
+ - keyword arguments are arguments preceded by an identifier when we pass them to a function. The order of the arguments can be changed.
122
+
123
+ ```python
124
+ # Example 1
125
+ def func(a, b, c):
126
+ print(a, b, c)
127
+
128
+ func(1, 2, 3)
129
+ # Output -> 1 2 3
130
+
131
+ func(c=3, b=2, a=1)
132
+ # Output -> 1 2 3
133
+ ```
134
+
135
+ ### - all any
136
+
137
+ - all() returns True if all elements in an iterable are true (or if the iterable is empty).
138
+
139
+ - any() returns True if any element of an iterable is true. If the iterable is empty, it returns False.
140
+
141
+ ```python
142
+ # Example 1
143
+ my_list = [True, True, True]
144
+ print(all(my_list))
145
+ # Output -> True
146
+
147
+ my_list = [True, False, True]
148
+ print(all(my_list))
149
+ # Output -> False
150
+
151
+ # Example 2
152
+ my_list = [1, 2, 3, 4, 5, 6]
153
+ print(all([num % 2 == 0 for num in my_list]))
154
+ # Output -> False
155
+ ```