Skip to content

Commit 139ba08

Browse files
committed
Update ruby notes, small updates to JS, ffmpeg and docker notes
1 parent ac92aa0 commit 139ba08

20 files changed

+252
-113
lines changed

notes/language/javascript/fetch.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Fetch
3+
ref: https://developer.mozilla.org/en-US/docs/Web/API/Window/fetch
4+
---
5+
6+
## Basic
7+
8+
Issue a GET request:
9+
10+
```js
11+
fetch('https://example.com/').then(res => console.log(res.status));
12+
```

notes/language/ruby/array.md

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
---
22
title: Array
3+
ref: https://docs.ruby-lang.org/en/3.4/Array.html
34
---
45

6+
## Basic
7+
58
```ruby
69
my_array = [1, 2, 3]
710
my_array = (1..10).to_a
@@ -10,15 +13,34 @@ my_array[1]
1013
my_array.push(40)
1114
my_array << 40 # Same as push
1215

16+
```
17+
18+
## Methods
19+
20+
| Method | Description |
21+
| ---------- | ----------------------------------------------------------------- |
22+
| `push` | Appends each argument to the array. |
23+
| `sort` | Returns a new array sorted. |
24+
| `sort_by!` | Sort in place by using the given block. |
25+
| `reverse` | Returns a new array in inverse order. |
26+
| `map` | Returns a new array with each element updated by the given block. |
27+
| `collect` | Same as `map`. |
28+
29+
Update elements order:
30+
31+
```ruby
1332
my_array.sort! do |v1, v2|
1433
v1 <=> v2
1534
end
1635
my_array = my_array.sort_by do |key, value|
1736
value
1837
end
1938
my_array.reverse!
39+
```
2040

21-
## Map
41+
Calculate the square of every element:
42+
43+
```ruby
2244
my_nums.map { |num| num ** 2 }
2345
my_nums.collect { |num| num ** 2 }
2446
```

notes/language/ruby/basic_types.md

+24-7
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,46 @@
22
title: Basic types
33
---
44

5+
## Types
6+
57
```ruby
68
my_name = "Taro" # String
79
my_int = 10 # Integer
810
my_float = 3.14
911
my_bool = true
1012
my_nil = nil
1113
my_symbol = :hello # Symbol
14+
```
15+
16+
To convert between types:
1217

18+
```ruby
1319
my_name.to_sym # to symbol
1420
my_name.intern # to symbol
1521
my_symbol.to_s # to string
22+
```
1623

17-
## Check if an object can receive a method
18-
my_var.respond_to?(:next)
19-
20-
my_int.next # Add 1 to an integer
21-
my_int.to_s # Convert to string
24+
Number operations:
2225

26+
```ruby
27+
my_int.next # Add 1 to an integer
2328
my_float.floor # Round down
29+
```
30+
31+
Check if an object can receive a method:
2432

25-
## Assign the result to the variable
33+
```ruby
34+
my_var.respond_to?(:next)
35+
```
36+
37+
Assign the result to the variable by using `!`:
38+
39+
```ruby
2640
my_name.capitalize!
41+
```
2742

28-
## Methods that return boolean
43+
Methods that return boolean use `?`:
44+
45+
```ruby
2946
string_to_check.include? "substring"
3047
```

notes/language/ruby/builtin_functions.md notes/language/ruby/builtin.md

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
---
2-
title: Built-in functions
2+
title: Built-in
33
---
44

5+
## Interactive Console
6+
7+
Run the command:
8+
9+
```shell
10+
irb
11+
```
12+
13+
## Functions
14+
515
```ruby
616
print "Hello" # Prints something and do NOT put a new line
717
puts "Hello" # Prints something and puts a new line at the end
@@ -11,3 +21,14 @@ puts "My name is #{name}!"
1121
my_name = gets # Gets the input from the user
1222
my_name = gets.chomp # Same as gets but removes the new line
1323
```
24+
25+
## Comments
26+
27+
```ruby
28+
# One line comment
29+
30+
=begin
31+
I'm a comment!
32+
I don't need any # symbols.
33+
=end
34+
```

notes/language/ruby/class.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: Class
33
---
44

5+
## Basic
6+
57
```ruby
68
class BaseClass
79
include Math # Variables and methods are inherited to class instances

notes/language/ruby/comments.md

-12
This file was deleted.

notes/language/ruby/control_flow.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: Control flow
33
---
44

5+
## Condition
6+
57
```ruby
68
if cond1
79
do_something
@@ -21,7 +23,11 @@ do_something if cond
2123
do_something unless cond
2224

2325
cond ? was_true : was_false
26+
```
2427

28+
## Switch
29+
30+
```ruby
2531
case my_var
2632
when 0
2733
do_something

notes/language/ruby/hash.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
---
22
title: Hash
3+
ref: https://docs.ruby-lang.org/en/3.4/Hash.html
34
---
45

6+
## Basic
7+
58
```ruby
69
my_hash = Hash.new
710
my_hash = Hash.new("default value")

notes/language/ruby/interactive_console.md

-7
This file was deleted.

notes/language/ruby/library/http.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: Net::HTTP
3+
ref: https://docs.ruby-lang.org/en/3.4/Net/HTTP.html
4+
---
5+
6+
## Basic
7+
8+
```ruby
9+
require 'net/http'
10+
Net::HTTP.get('example.com', '/index.html')
11+
```

notes/language/ruby/method.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@
22
title: Method
33
---
44

5+
## Basic
6+
7+
Without parameters:
8+
59
```ruby
6-
## Simple case
710
def method_name
811
do_something
912
end
1013

1114
method_name # Call it
15+
```
1216

13-
## With parameters
17+
With parameters:
18+
19+
```ruby
1420
def method_name(param=5, *splat)
1521
# splat becomes an array
1622
do_something

notes/language/ruby/module.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: Module
33
---
44

5+
## Basic
6+
57
Unlike classes, instances cannot be created,
68
and cannot have subclasses.
79

notes/language/ruby/operators.md

+52-22
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,55 @@
22
title: Operators
33
---
44

5-
```ruby
6-
my_var = "something"
7-
my_var ||= "something" # Only assign if it is nil
8-
9-
my_int += 1
10-
my_int -= 1
11-
my_int *= 2
12-
my_int /= 2
13-
14-
v1 == v2
15-
v1 != v2
16-
v1 > v2
17-
v1 < v2
18-
v1 >= v2
19-
v1 <= v2
20-
21-
v1 <=> v2 # -1, 0, 1 (less, equal, greater)
22-
23-
c1 && c2
24-
c1 || c2
25-
!cond
26-
```
5+
## Arithmetic
6+
7+
| Operator | Description |
8+
| -------- | ------------------------------------------ |
9+
| `+` | Addition or unary plus |
10+
| `-` | Subtraction or unary minus |
11+
| `*` | Multiplication |
12+
| `/` | Division |
13+
| `%` | Remainder after division (modulo division) |
14+
| `**` | Exponentiation |
15+
16+
## Assignment
17+
18+
| Operator | Example | Same as |
19+
| -------- | ----------- | ------------------------------------- |
20+
| `=` | `a = b` | `a = b` |
21+
| `+=` | `a += b` | `a = a + b` |
22+
| `-=` | `a -= b` | `a = a - b` |
23+
| `*=` | `a *= b` | `a = a * b` |
24+
| `/=` | `a /= b` | `a = a / b` |
25+
| `\|\|=` | `a \|\|= b` | `a = b if a == nil or a == false` |
26+
| `\|\|=` | `a \|\|= b` | `a = b unless a == nil or a == false` |
27+
28+
## Relational
29+
30+
| Operator | Description |
31+
| -------- | --------------------------------- |
32+
| `==` | Equal to |
33+
| `!=` | Not equal to |
34+
| `>` | Greater than |
35+
| `<` | Less than |
36+
| `>=` | Greater than or equal to |
37+
| `<=` | Less than or equal to |
38+
| `<=>` | Less, equal or greater (-1, 0, 1) |
39+
40+
## Logical
41+
42+
| Operator | Description |
43+
| ------------- | ----------- |
44+
| `&&` `and` | AND |
45+
| `\|\|` `or` | OR |
46+
| `!` | NOT |
47+
48+
## Bitwise
49+
50+
| Operator | Description |
51+
| -------- | ----------- |
52+
| `&` | AND |
53+
| `\|` | OR |
54+
| `^` | XOR |
55+
| `<<` | Shift left |
56+
| `>>` | Shift right |

notes/language/ruby/string.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
---
22
title: String
3+
ref: https://docs.ruby-lang.org/en/3.4/String.html
34
---
45

6+
## Basic
7+
58
```ruby
69
my_string = "Taro"
710

notes/language/ruby/time.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
---
22
title: Time
3+
ref: https://docs.ruby-lang.org/en/3.4/Time.html
34
---
45

6+
## Basic
7+
58
```ruby
69
now = Time.now
710
```

notes/language/rust/crates/chrono.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Print current datetime in an arbitrary format:
1919
use chrono::prelude::*;
2020

2121
fn main() {
22-
let now: DateTime<Local> = Local::now();
22+
let now = Local::now();
2323
println!("{}", now.format("%Y-%m-%d %H:%M:%S"));
2424
}
2525
```

notes/language/rust/numbers.md

+10
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ ref: https://forkful.ai/en/rust/numbers/rounding-numbers/
1111
| `floor` | Largest integer less than or equal to number. |
1212
| `ceil` | Smallest integer greater than or equal to number. |
1313
| `trunc` | Integer part without fractional digits. |
14+
| `max` | Highest number. |
15+
| `min` | Lowest number. |
1416

1517
Example:
1618

@@ -19,6 +21,14 @@ let pi = 3.141592;
1921
let round_pi = pi.round();
2022
```
2123

24+
Between two floats `a` and `b`,
25+
return the highest or lowest:
26+
27+
```rust
28+
a.max(b) // f32::max(a, b)
29+
a.min(b) // f32::min(a, b)
30+
```
31+
2232
## Update reference
2333

2434
If updating a number in a function that received it as `&mut`:

0 commit comments

Comments
 (0)