restructure: arrays and slices
This commit is contained in:
@ -11,26 +11,26 @@
|
||||
|
||||
## GOALS:
|
||||
|
||||
### 👉 [STEP #1 — Print the Digits](https://github.com/inancgumus/learngo/tree/master/14-arrays/13-project-clock/01-printing-the-digits/)
|
||||
### 👉 [STEP #1 — Print the Digits](https://github.com/inancgumus/learngo/tree/master/15-project-retro-clock/01-printing-the-digits/)
|
||||
- [ ] Define a new placeholder type
|
||||
- [ ] Create the digit arrays from 0 to 9
|
||||
- [ ] Put them into the "digits" array
|
||||
- [ ] Print them side-by-side
|
||||
|
||||
### 👉 [STEP #2 — Print the Clock](https://github.com/inancgumus/learngo/tree/master/14-arrays/13-project-clock/02-printing-the-clock/)
|
||||
### 👉 [STEP #2 — Print the Clock](https://github.com/inancgumus/learngo/tree/master/15-project-retro-clock/02-printing-the-clock/)
|
||||
- [ ] Get the current time
|
||||
- [ ] Create the clock array
|
||||
- [ ] Print the clock
|
||||
- [ ] Add the separators
|
||||
|
||||
### 👉 [STEP #3 — Animate the Clock](https://github.com/inancgumus/learngo/tree/master/14-arrays/13-project-clock/03-animating-the-clock/)
|
||||
### 👉 [STEP #3 — Animate the Clock](https://github.com/inancgumus/learngo/tree/master/15-project-retro-clock/03-animating-the-clock/)
|
||||
- [ ] Create an infinite loop to update the clock
|
||||
- [ ] Update the clock every second
|
||||
- [ ] Clear the screen before the infinite loop
|
||||
- [ ] Move the cursor to the top-left corner of the screen before each
|
||||
step of the infinite loop
|
||||
|
||||
### 👉 [BONUS: STEP #4 — Blink the Clock](https://github.com/inancgumus/learngo/tree/master/14-arrays/13-project-clock/04-blinking-the-separators/)
|
||||
### 👉 [BONUS: STEP #4 — Blink the Clock](https://github.com/inancgumus/learngo/tree/master/15-project-retro-clock/04-blinking-the-separators/)
|
||||
- [ ] Blink the separators
|
||||
|
||||
### 👉 [FULL ANNOTATED SOLUTION](https://github.com/inancgumus/learngo/tree/master/14-arrays/13-project-clock/05-full-annotated-solution/main.go)
|
||||
### 👉 [FULL ANNOTATED SOLUTION](https://github.com/inancgumus/learngo/tree/master/15-project-retro-clock/05-full-annotated-solution/main.go)
|
@ -2,20 +2,20 @@
|
||||
|
||||
These exercises will reinforce your knowledge of manipulating arrays. You will prove yourself that you can write easy to maintain Go programs.
|
||||
|
||||
1. **[Refactor](https://github.com/inancgumus/learngo/tree/master/14-arrays/13-project-clock/exercises/01-refactor)**
|
||||
1. **[Refactor](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/exercises/01-refactor)**
|
||||
|
||||
In this exercise, you will refactor the project to multiple files by moving
|
||||
all the placeholders. This will make the project easy to maintain down the road.
|
||||
|
||||
2. **[Set an Alarm](https://github.com/inancgumus/learngo/tree/master/14-arrays/13-project-clock/exercises/02-alarm)**
|
||||
2. **[Set an Alarm](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/exercises/02-alarm)**
|
||||
|
||||
You will print " ALARM! " every 10 seconds.
|
||||
|
||||
3. **[Split Second](https://github.com/inancgumus/learngo/tree/master/14-arrays/13-project-clock/exercises/03-split-second)**
|
||||
3. **[Split Second](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/exercises/03-split-second)**
|
||||
|
||||
You will display the split second in the clock, you will need to update the
|
||||
clock every 1/10th of a second instead of every second.
|
||||
|
||||
4. **[Ticker](https://github.com/inancgumus/learngo/tree/master/14-arrays/13-project-clock/exercises/04-ticker)**
|
||||
4. **[Ticker](https://github.com/inancgumus/learngo/tree/master/15-project-retro-led-clock/exercises/04-ticker)**
|
||||
|
||||
This is an HARD EXERCISE. You will slide the clock animation from right-to-left. After this exercise, you will truly feel that you've mastered everything you've learned so far.
|
@ -1,31 +0,0 @@
|
||||
# Slice Exercises
|
||||
|
||||
## Exercises Level I - Basics — Warm-Up
|
||||
|
||||
1. **[Declare nil slices](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/01-declare-nil)**
|
||||
|
||||
2. **[Assign empty slices](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/02-empty)**
|
||||
|
||||
3. **[Assign slice literals](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/03-slice-literal)**
|
||||
|
||||
4. **[Declare the arrays as slices](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/04-declare-arrays-as-slices)**
|
||||
|
||||
5. **[Fix the Problems](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/05-fix-the-problems)**
|
||||
|
||||
6. **[Compare the slices](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/06-compare-the-slices)**
|
||||
|
||||
---
|
||||
|
||||
## Exercises Level II - Appending
|
||||
|
||||
1. **[Append #1 — Append and compare byte slices](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/07-append)**
|
||||
|
||||
2. **[Append #2 — Append to a nil slice](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/08-append-2)**
|
||||
|
||||
3. **[Append #3 — Fix the problems](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/09-append-3-fix)**
|
||||
|
||||
4. **[Append #4 — Sort and write items to a file](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/10-append-4-sort-to-a-file)**
|
||||
|
||||
5. **[Append #5 — Sort and write items to a file with their ordinals](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/11-append-5-sort-to-a-file)**
|
||||
|
||||
5. **[Append #6 — Find and write the names of subdirectories to a file](https://github.com/inancgumus/learngo/tree/master/15-slices/exercises/12-append-6-print-directories)**
|
25
16-slices/exercises/README.md
Normal file
25
16-slices/exercises/README.md
Normal file
@ -0,0 +1,25 @@
|
||||
# Slice Exercises
|
||||
|
||||
## Exercises Level I - Basics — Warm-Up
|
||||
|
||||
1. **[Declare nil slices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/01-declare-nil)**
|
||||
|
||||
2. **[Assign empty slices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/02-empty)**
|
||||
|
||||
3. **[Assign slice literals](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/03-slice-literal)**
|
||||
|
||||
4. **[Declare the arrays as slices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/04-declare-arrays-as-slices)**
|
||||
|
||||
5. **[Fix the Problems](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/05-fix-the-problems)**
|
||||
|
||||
6. **[Compare the slices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/06-compare-the-slices)**
|
||||
|
||||
---
|
||||
|
||||
## Exercises Level II - Appending
|
||||
|
||||
1. **[Append #1 — Append and compare byte slices](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/07-append)**
|
||||
|
||||
2. **[Append #2 — Append to a nil slice](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/08-append-2)**
|
||||
|
||||
3. **[Append #3 — Fix the problems](https://github.com/inancgumus/learngo/tree/master/16-slices/exercises/09-append-3-fix)**
|
@ -1,38 +0,0 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
s "github.com/inancgumus/prettyslice"
|
||||
)
|
||||
|
||||
func main() {
|
||||
msg := []byte{'h', 'e', 'l', 'l', 'o'}
|
||||
s.Show("msg", msg)
|
||||
|
||||
s.Show("msg[0:1]", msg[0:1])
|
||||
s.Show("msg[0:2]", msg[0:2])
|
||||
s.Show("msg[0:3]", msg[0:3])
|
||||
s.Show("msg[0:4]", msg[0:4])
|
||||
s.Show("msg[0:5]", msg[0:5])
|
||||
|
||||
// default indexes
|
||||
s.Show("msg[0:]", msg[0:])
|
||||
s.Show("msg[:5]", msg[:5])
|
||||
s.Show("msg[:]", msg[:])
|
||||
|
||||
// error: beyond
|
||||
// s.Show("msg", msg)[:6]
|
||||
|
||||
s.Show("msg[1:4]", msg[1:4])
|
||||
|
||||
s.Show("msg[1:5]", msg[1:5])
|
||||
s.Show("msg[1:]", msg[1:])
|
||||
|
||||
s.Show("append(msg)", append(msg[:4], '!'))
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
s "github.com/inancgumus/prettyslice"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// think of this as search results of a search engine.
|
||||
// it could have been fetched from a database
|
||||
items := []string{
|
||||
"pacman",
|
||||
"mario",
|
||||
"tetris",
|
||||
"doom",
|
||||
"galaga",
|
||||
"frogger",
|
||||
"asteroids",
|
||||
"simcity",
|
||||
"metroid",
|
||||
"defender",
|
||||
"rayman",
|
||||
"tempest",
|
||||
"ultima",
|
||||
}
|
||||
|
||||
s.MaxPerLine = 4
|
||||
s.Show("All items", items)
|
||||
|
||||
top3 := items[:3]
|
||||
s.Show("Top 3 items", top3)
|
||||
|
||||
l := len(items)
|
||||
|
||||
// you can use variables in a slice expression
|
||||
last4 := items[l-4:]
|
||||
s.Show("Last 4 items", last4)
|
||||
|
||||
// reslicing: slicing another sliced slice
|
||||
mid := last4[1:3]
|
||||
s.Show("Last4[1:3]", mid)
|
||||
|
||||
// the same elements can be in different indexes
|
||||
// fmt.Println(items[9], last4[0])
|
||||
|
||||
// slicing returns a slice with the same type of the sliced slice
|
||||
fmt.Printf("slicing : %T %[1]q\n", items[2:3])
|
||||
|
||||
// indexing returns a single element with the type of the indexed slice's element type
|
||||
fmt.Printf("indexing: %T %[1]q\n", items[2])
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
s "github.com/inancgumus/prettyslice"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// think of this as search results of a search engine.
|
||||
// it could have been fetched from a database
|
||||
items := []string{
|
||||
"pacman",
|
||||
"mario",
|
||||
"tetris",
|
||||
"doom",
|
||||
"galaga",
|
||||
"frogger",
|
||||
"asteroids",
|
||||
"simcity",
|
||||
"metroid",
|
||||
"defender",
|
||||
"rayman",
|
||||
"tempest",
|
||||
"ultima",
|
||||
}
|
||||
|
||||
// s.Show("0:4", items[0:4])
|
||||
// s.Show("4:8", items[4:8])
|
||||
// s.Show("8:12", items[8:12])
|
||||
// s.Show("12:13", items[12:13])
|
||||
// s.Show("12:14", items[12:14]) // error
|
||||
|
||||
l := len(items)
|
||||
|
||||
const pageSize = 4
|
||||
|
||||
for from := 0; from < l; from += pageSize {
|
||||
to := from + pageSize
|
||||
if to > l {
|
||||
to = l
|
||||
}
|
||||
|
||||
// fmt.Printf("%d:%d\n", from, to)
|
||||
|
||||
currentPage := items[from:to]
|
||||
|
||||
head := fmt.Sprintf("Page #%d", (from/pageSize)+1)
|
||||
s.Show(head, currentPage)
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
# The Brief Anatomy of a PNG image
|
||||
|
||||
```
|
||||
The first 24 bytes:
|
||||
|
||||
PNG HEADER:
|
||||
╔═════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗
|
||||
║ 137 ║║ 80 ║║ 78 ║║ 71 ║║ 13 ║║ 10 ║║ 26 ║║ 10 ║
|
||||
╚═════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝
|
||||
0 1 2 3 4 5 6 7
|
||||
|
||||
CHUNK LENGTH CHUNK TYPE (IHDR)
|
||||
╔═══╗╔═══╗╔═══╗╔════╗╔════╗╔════╗╔════╗╔════╗
|
||||
║ 0 ║║ 0 ║║ 0 ║║ 13 ║║ 73 ║║ 72 ║║ 68 ║║ 82 ║
|
||||
╚═══╝╚═══╝╚═══╝╚════╝╚════╝╚════╝╚════╝╚════╝
|
||||
8 9 10 11 12 13 14 15
|
||||
|
||||
( Unsigned 32-bit integers )
|
||||
WIDTH HEIGHT
|
||||
╔═══╗╔═══╗╔═══╗╔════╗╔═══╗╔═══╗╔═══╗╔════╗
|
||||
║ 0 ║║ 0 ║║ 2 ║║ 76 ║║ 0 ║║ 0 ║║ 3 ║║ 32 ║
|
||||
╚═══╝╚═══╝╚═══╝╚════╝╚═══╝╚═══╝╚═══╝╚════╝
|
||||
16 17 18 19 20 21 22 23
|
||||
|
||||
... Other bytes in the png image ...
|
||||
```
|
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE: Append #4 — Sort to a file
|
||||
// EXERCISE: Sort to a file
|
||||
//
|
||||
// 1. Get arguments from command-line
|
||||
//
|
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE: Append #5 — Sort to a file with ordinals
|
||||
// EXERCISE: Sort to a file with ordinals
|
||||
//
|
||||
// Use the previous exercise: Append #4
|
||||
//
|
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
// ---------------------------------------------------------
|
||||
// EXERCISE: Append #6 — Print the directories
|
||||
// EXERCISE: Print the directories
|
||||
//
|
||||
// Create a program that can get multiple directory paths from
|
||||
// the command-line, and prints only their subdirectories into a
|
@ -0,0 +1,7 @@
|
||||
# File Append Exercises
|
||||
|
||||
1. **[Sort and write items to a file](https://github.com/inancgumus/learngo/tree/master/15-slices/19-empty-file-finder-project/exercises/1-sort-to-a-file)**
|
||||
|
||||
2. **[Sort and write items to a file with their ordinals](https://github.com/inancgumus/learngo/tree/master/15-slices/19-empty-file-finder-project/exercises/2-sort-to-a-file)**
|
||||
|
||||
3. **[Find and write the names of subdirectories to a file](https://github.com/inancgumus/learngo/tree/master/15-slices/19-empty-file-finder-project/exercises/3-print-directories)**
|
@ -4,14 +4,14 @@
|
||||
The first 24 bytes:
|
||||
|
||||
+=================================+
|
||||
| PNG Header | 8 bytes | -> 137 80 78 71 13 10 26 10
|
||||
| PNG Header | 8 bytes | -> 89 50 4e 47 0d 0a 1a 0a
|
||||
+---------------------+-----------+
|
||||
| IHDR Chunk Header | |
|
||||
| Chunk Length | 4 bytes | -> The length of the IHDR Chunk Data
|
||||
| Chunk Type | 4 bytes | -> 73 72 68 82
|
||||
| Chunk Type | 4 bytes | -> 49 48 44 52
|
||||
+---------------------+-----------+
|
||||
| IHDR Chunk Data | |
|
||||
| Width | 4 bytes | -> Unsigned 32-bit integer
|
||||
| Height | 4 bytes | -> Unsigned 32-bit integer
|
||||
| Width | 4 bytes | -> uint32 — big endian
|
||||
| Height | 4 bytes | -> uint32 — big endian
|
||||
+=================================+
|
||||
```
|
26
x-tba/slices/20-png-parser-project/2-png-anatomy-example.md
Normal file
26
x-tba/slices/20-png-parser-project/2-png-anatomy-example.md
Normal file
@ -0,0 +1,26 @@
|
||||
# The Brief Anatomy of a PNG image
|
||||
|
||||
```
|
||||
The first 24 bytes:
|
||||
(all numbers are uint32 big-endian)
|
||||
|
||||
PNG HEADER
|
||||
╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗
|
||||
║ 89 ║║ 50 ║║ 4e ║║ 47 ║║ 0d ║║ 0a ║║ 1a ║║ 0a ║
|
||||
╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝
|
||||
0 1 2 3 4 5 6 7
|
||||
|
||||
CHUNK LENGTH CHUNK TYPE (IHDR)
|
||||
╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗
|
||||
║ 00 ║║ 00 ║║ 00 ║║ 0d ║║ 49 ║║ 48 ║║ 44 ║║ 52 ║
|
||||
╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝
|
||||
8 9 10 11 12 13 14 15
|
||||
|
||||
WIDTH HEIGHT
|
||||
╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗╔════╗
|
||||
║ 00 ║║ 00 ║║ 02 ║║ 4c ║║ 00 ║║ 00 ║║ 03 ║║ 20 ║
|
||||
╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝
|
||||
16 17 18 19 20 21 22 23
|
||||
|
||||
... rest of the bytes in the png image ...
|
||||
```
|
Before Width: | Height: | Size: 80 B After Width: | Height: | Size: 80 B |
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user