From 6e931e503bebbd07bc1fe0511e0ece3993c91dd8 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Wed, 3 Apr 2019 19:32:55 +0300 Subject: [PATCH] move: string projects --- .../1-png-anatomy-format.md | 0 .../2-png-anatomy-example.md | 0 .../images/broken-missing-ihdr.png | 0 .../images/broken-missing-png-header.png | Bin .../png-parser-project/images/gopher.png | Bin .../png-parser-project/main.go | 0 .../01-charset-table/main.go | 69 --------------- .../01-bytes-runes-strings/02-example/main.go | 61 ------------- .../04-masker-challenge/main.go | 77 ----------------- .../04-masker-challenge/spam.txt | 7 -- .../05-masker-solution/main.go | 80 ------------------ .../05-masker-solution/spam.txt | 7 -- .../08-wrapper-example/main.go | 38 --------- .../08-wrapper-example/story.txt | 5 -- x-tba/strings-runes-bytes/exercises/README.md | 9 -- .../exercises/_exercise/main.go | 36 -------- x-tba/strings-runes-bytes/exercises/main.go | 18 ---- 17 files changed, 407 deletions(-) rename x-tba/{strings-runes-bytes => project-png-parser}/png-parser-project/1-png-anatomy-format.md (100%) rename x-tba/{strings-runes-bytes => project-png-parser}/png-parser-project/2-png-anatomy-example.md (100%) rename x-tba/{strings-runes-bytes => project-png-parser}/png-parser-project/images/broken-missing-ihdr.png (100%) rename x-tba/{strings-runes-bytes => project-png-parser}/png-parser-project/images/broken-missing-png-header.png (100%) rename x-tba/{strings-runes-bytes => project-png-parser}/png-parser-project/images/gopher.png (100%) rename x-tba/{strings-runes-bytes => project-png-parser}/png-parser-project/main.go (100%) delete mode 100644 x-tba/strings-runes-bytes/01-bytes-runes-strings/01-charset-table/main.go delete mode 100644 x-tba/strings-runes-bytes/01-bytes-runes-strings/02-example/main.go delete mode 100644 x-tba/strings-runes-bytes/04-masker-challenge/main.go delete mode 100644 x-tba/strings-runes-bytes/04-masker-challenge/spam.txt delete mode 100644 x-tba/strings-runes-bytes/05-masker-solution/main.go delete mode 100644 x-tba/strings-runes-bytes/05-masker-solution/spam.txt delete mode 100644 x-tba/strings-runes-bytes/08-wrapper-example/main.go delete mode 100644 x-tba/strings-runes-bytes/08-wrapper-example/story.txt delete mode 100644 x-tba/strings-runes-bytes/exercises/README.md delete mode 100644 x-tba/strings-runes-bytes/exercises/_exercise/main.go delete mode 100644 x-tba/strings-runes-bytes/exercises/main.go diff --git a/x-tba/strings-runes-bytes/png-parser-project/1-png-anatomy-format.md b/x-tba/project-png-parser/png-parser-project/1-png-anatomy-format.md similarity index 100% rename from x-tba/strings-runes-bytes/png-parser-project/1-png-anatomy-format.md rename to x-tba/project-png-parser/png-parser-project/1-png-anatomy-format.md diff --git a/x-tba/strings-runes-bytes/png-parser-project/2-png-anatomy-example.md b/x-tba/project-png-parser/png-parser-project/2-png-anatomy-example.md similarity index 100% rename from x-tba/strings-runes-bytes/png-parser-project/2-png-anatomy-example.md rename to x-tba/project-png-parser/png-parser-project/2-png-anatomy-example.md diff --git a/x-tba/strings-runes-bytes/png-parser-project/images/broken-missing-ihdr.png b/x-tba/project-png-parser/png-parser-project/images/broken-missing-ihdr.png similarity index 100% rename from x-tba/strings-runes-bytes/png-parser-project/images/broken-missing-ihdr.png rename to x-tba/project-png-parser/png-parser-project/images/broken-missing-ihdr.png diff --git a/x-tba/strings-runes-bytes/png-parser-project/images/broken-missing-png-header.png b/x-tba/project-png-parser/png-parser-project/images/broken-missing-png-header.png similarity index 100% rename from x-tba/strings-runes-bytes/png-parser-project/images/broken-missing-png-header.png rename to x-tba/project-png-parser/png-parser-project/images/broken-missing-png-header.png diff --git a/x-tba/strings-runes-bytes/png-parser-project/images/gopher.png b/x-tba/project-png-parser/png-parser-project/images/gopher.png similarity index 100% rename from x-tba/strings-runes-bytes/png-parser-project/images/gopher.png rename to x-tba/project-png-parser/png-parser-project/images/gopher.png diff --git a/x-tba/strings-runes-bytes/png-parser-project/main.go b/x-tba/project-png-parser/png-parser-project/main.go similarity index 100% rename from x-tba/strings-runes-bytes/png-parser-project/main.go rename to x-tba/project-png-parser/png-parser-project/main.go diff --git a/x-tba/strings-runes-bytes/01-bytes-runes-strings/01-charset-table/main.go b/x-tba/strings-runes-bytes/01-bytes-runes-strings/01-charset-table/main.go deleted file mode 100644 index c8dfcb8..0000000 --- a/x-tba/strings-runes-bytes/01-bytes-runes-strings/01-charset-table/main.go +++ /dev/null @@ -1,69 +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" - "os" - "strconv" - "strings" -) - -func main() { - var start, stop int - - if args := os.Args[1:]; len(args) == 2 { - start, _ = strconv.Atoi(args[0]) - stop, _ = strconv.Atoi(args[1]) - } - - if start == 0 || stop == 0 { - start, stop = 'A', 'Z' - } - - fmt.Printf("%-10s %-10s %-10s %-12s\n%s\n", - "literal", "dec", "hex", "encoded", - strings.Repeat("-", 45)) - - for n := start; n <= stop; n++ { - fmt.Printf("%-10c %-10[1]d %-10[1]x % -12x\n", n, string(n)) - } -} - -/* -EXAMPLE UNICODE BLOCKS - -1 byte ------------------------------------------------------------- -asciiStart = '\u0001' -> 32 -asciiStop = '\u007f' -> 127 - -upperCaseStart = '\u0041' -> 65 -upperCaseStop = '\u005a' -> 90 - -lowerCaseStart = '\u0061' -> 97 -lowerCaseStop = '\u007a' -> 122 - - -2 bytes ------------------------------------------------------------- -latin1Start = '\u0080' -> 161 -latin1Stop = '\u00ff' -> 255 - - -3 bytes ------------------------------------------------------------- -dingbatStart = '\u2700' -> 9984 -dingbatStop = '\u27bf' -> 10175 - - -4 bytes ------------------------------------------------------------- -emojiStart = '\U0001f600' -> 128512 -emojiStop = '\U0001f64f' -> 128591 -*/ diff --git a/x-tba/strings-runes-bytes/01-bytes-runes-strings/02-example/main.go b/x-tba/strings-runes-bytes/01-bytes-runes-strings/02-example/main.go deleted file mode 100644 index 2d8826a..0000000 --- a/x-tba/strings-runes-bytes/01-bytes-runes-strings/02-example/main.go +++ /dev/null @@ -1,61 +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" - "unicode/utf8" - "unsafe" -) - -func main() { - str := "Yūgen ☯ 💀" - - // can't change a string - // a string is a read-only byte-slice - // str[0] = 'N' - // str[1] = 'o' - - bytes := []byte(str) - - // can change a byte slice - // bytes[0] = 'N' - // bytes[1] = 'o' - - str = string(bytes) - - fmt.Printf("%s\n", str) - fmt.Printf("\t%d bytes\n", len(str)) - fmt.Printf("\t%d runes\n", utf8.RuneCountInString(str)) - fmt.Printf("% x\n", bytes) - fmt.Printf("\t%d bytes\n", len(bytes)) - fmt.Printf("\t%d runes\n", utf8.RuneCount(bytes)) - - // fmt.Println() - // for i, r := range str { - // fmt.Printf("str[%2d] = % -12x = %q\n", i, string(r), r) - // } - - fmt.Println() - fmt.Printf("1st byte : %c\n", str[0]) // ok - fmt.Printf("2nd byte : %c\n", str[1]) // not ok - fmt.Printf("2nd rune : %s\n", str[1:3]) // ok - fmt.Printf("last rune : %s\n", str[11:]) // ok - - // disadvantage: each one is 4 bytes - runes := []rune(str) - - fmt.Println() - fmt.Printf("%s\n", str) - fmt.Printf("\t%d bytes\n", int(unsafe.Sizeof(runes[0]))*len(runes)) - fmt.Printf("\t%d runes\n", len(runes)) - - fmt.Printf("1st rune : %c\n", runes[0]) - fmt.Printf("2nd rune : %c\n", runes[1]) - fmt.Printf("first five : %c\n", runes[:5]) -} diff --git a/x-tba/strings-runes-bytes/04-masker-challenge/main.go b/x-tba/strings-runes-bytes/04-masker-challenge/main.go deleted file mode 100644 index 14ca092..0000000 --- a/x-tba/strings-runes-bytes/04-masker-challenge/main.go +++ /dev/null @@ -1,77 +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/ -// - -/* ------------------------------------------------------------- -RULES ------------------------------------------------------------- - -* You shouldn't use a standard library function. - -* You should only solve the challenge by manipulating the bytes directly. - -* Manipulate the bytes of a string using indexing, slicing, appending etc. - -* Be efficient: Do not use string concat (+ operator). - - * Instead, create a new byte slice as a buffer from the given string argument. - - * Then, manipulate it during your program. - - * And, for once, print that buffer. - ------------------------------------------------------------- -STEPS ------------------------------------------------------------- - -* Mask only links starting with http:// - -* Don't check for uppercase/lowercase letters - * The goal is to learn manipulating bytes in strings - * It's not about creating a perfect masker - - * For example: A spammer can prevent the masker like this (for now this is OK): - - "Here's my spammy page: hTTp://youth-elixir.com" - -* But, you should catch this: - - "Here's my spammy page: http://hehefouls.netHAHAHA see you." - "Here's my spammy page: http://******************* see you." -*/ -package main - -func main() { - // --------------------------------------------------------------- - // #1 - // --------------------------------------------------------------- - // Check whether there's a command line argument or not - // If not, quit from the program with a message - - // --------------------------------------------------------------- - // #2 - // --------------------------------------------------------------- - // Create a byte buffer as big as the argument - - // --------------------------------------------------------------- - // #3 - // --------------------------------------------------------------- - // 1- Loop and detect the http:// patterns - // 2- Copy the input character by character to the buffer - // 3- If you detect http:// pattern, copy the http:// first, - // then copy the *s instead of the original link until - // you see a whitespace character. - // - // Here: http://www.mylink.com Click! - // -> Here: http://************** Click! - // - - // --------------------------------------------------------------- - // #4 - // --------------------------------------------------------------- - // Print the buffer as a string -} diff --git a/x-tba/strings-runes-bytes/04-masker-challenge/spam.txt b/x-tba/strings-runes-bytes/04-masker-challenge/spam.txt deleted file mode 100644 index 6ad043d..0000000 --- a/x-tba/strings-runes-bytes/04-masker-challenge/spam.txt +++ /dev/null @@ -1,7 +0,0 @@ -Hi guys, - -Here is my new spammy webpage http://www.mysuperpage.com <-- This is my website! - -Please click on the link now!!! - -When you click, I will be rich, thanks! \ No newline at end of file diff --git a/x-tba/strings-runes-bytes/05-masker-solution/main.go b/x-tba/strings-runes-bytes/05-masker-solution/main.go deleted file mode 100644 index 3a1b635..0000000 --- a/x-tba/strings-runes-bytes/05-masker-solution/main.go +++ /dev/null @@ -1,80 +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/ -// - -/* -#1- Get and check the input -#2- Create a byte buffer and use it as the output -#3- Write input to the buffer as it is and print it -#4- Detect the link -#5- Mask the link -#6- Stop masking when a whitespace is detected -#7- Write http:// to the buffer, just before the link -*/ - -package main - -import ( - "fmt" - "os" -) - -const ( - link = "http://" - nlink = len(link) - mask = '*' -) - -func main() { - args := os.Args[1:] - if len(args) != 1 { - fmt.Println("gimme somethin' to censor!") - return - } - - var ( - text = args[0] - size = len(text) - buf = make([]byte, 0, size) - - in bool - ) - - for i := 0; i < size; i++ { - // slice the input and look for the link pattern - // do not slice it when it goes beyond the input text's capacity - if len(text[i:]) >= nlink && text[i:i+nlink] == link { - // set the flag: we're in a link! -> "http://....." - in = true - - // add the "http://" manually - buf = append(buf, link...) - - // jump to the next character after "http://" - i += nlink - } - - // get the current byte from the input - c := text[i] - - // disable the link detection flag - // this will prevent masking the rest of the bytes - switch c { - case ' ', '\t', '\n': // try -> unicode.IsSpace - in = false - } - - // if we're in the link detection mode (inside the link bytes) - // then, mask the current character - if in { - c = mask - } - buf = append(buf, c) - } - - // print out the buffer as text (string) - fmt.Println(string(buf)) -} diff --git a/x-tba/strings-runes-bytes/05-masker-solution/spam.txt b/x-tba/strings-runes-bytes/05-masker-solution/spam.txt deleted file mode 100644 index 6ad043d..0000000 --- a/x-tba/strings-runes-bytes/05-masker-solution/spam.txt +++ /dev/null @@ -1,7 +0,0 @@ -Hi guys, - -Here is my new spammy webpage http://www.mysuperpage.com <-- This is my website! - -Please click on the link now!!! - -When you click, I will be rich, thanks! \ No newline at end of file diff --git a/x-tba/strings-runes-bytes/08-wrapper-example/main.go b/x-tba/strings-runes-bytes/08-wrapper-example/main.go deleted file mode 100644 index 4efa1c3..0000000 --- a/x-tba/strings-runes-bytes/08-wrapper-example/main.go +++ /dev/null @@ -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 ( - "fmt" - "unicode" -) - -func main() { - text := `Galaksinin Batı Sarmal Kolu'nun bir ucunda, haritası bile çıkarılmamış ücra bir köşede, gözlerden uzak, küçük ve sarı bir güneş vardır. - -Bu güneşin yörüngesinde, kabaca yüz kırksekiz milyon kilometre uzağında, tamamıyla önemsiz ve mavi-yeşil renkli, küçük bir gezegen döner. - -Gezegenin maymun soyundan gelen canlıları öyle ilkeldir ki dijital kol saatinin hâlâ çok etkileyici bir buluş olduğunu düşünürler.` - - const maxWidth = 40 - - var lw int // line width - - for _, r := range text { - fmt.Printf("%c", r) - - switch lw++; { - case lw > maxWidth && r != '\n' && unicode.IsSpace(r): - fmt.Println() - fallthrough - case r == '\n': - lw = 0 - } - } - fmt.Println() -} diff --git a/x-tba/strings-runes-bytes/08-wrapper-example/story.txt b/x-tba/strings-runes-bytes/08-wrapper-example/story.txt deleted file mode 100644 index b8784a4..0000000 --- a/x-tba/strings-runes-bytes/08-wrapper-example/story.txt +++ /dev/null @@ -1,5 +0,0 @@ -Galaksinin Batı Sarmal Kolu'nun bir ucunda, haritası bile çıkarılmamış ücra bir köşede, gözlerden uzak, küçük ve sarı bir güneş vardır. - -Bu güneşin yörüngesinde, kabaca yüz kırksekiz milyon kilometre uzağında, tamamıyla önemsiz ve mavi-yeşil renkli, küçük bir gezegen döner. - -Gezegenin maymun soyundan gelen canlıları öyle ilkeldir ki dijital kol saatinin hâlâ çok etkileyici bir buluş olduğunu düşünürler. \ No newline at end of file diff --git a/x-tba/strings-runes-bytes/exercises/README.md b/x-tba/strings-runes-bytes/exercises/README.md deleted file mode 100644 index 36118cb..0000000 --- a/x-tba/strings-runes-bytes/exercises/README.md +++ /dev/null @@ -1,9 +0,0 @@ -TODO - -* Write a program that dumps the bytes of the given argument - * Get the first unicode char ([]rune) - * Get the last unicode char ([]rune) - -* In the masker program: - * Use copy instead of append when appendin the "http://" manually - * \ No newline at end of file diff --git a/x-tba/strings-runes-bytes/exercises/_exercise/main.go b/x-tba/strings-runes-bytes/exercises/_exercise/main.go deleted file mode 100644 index 12f580d..0000000 --- a/x-tba/strings-runes-bytes/exercises/_exercise/main.go +++ /dev/null @@ -1,36 +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/ -// - -// why maps instead of keyed arrays etc? -// 120k elements! - -package main - -import ( - "fmt" - "os" - "unicode/utf8" -) - -func main() { - args := os.Args[1:] - if len(args) != 1 { - fmt.Println("[emoji]") - return - } - - moods := [...]string{ - '😊': "a happy", - '😟': "a worried", - '😎': "an awesome", - '😞': "a sad", - '😩': "a crying", - } - - emoji, _ := utf8.DecodeRune([]byte(args[0])) - fmt.Printf("%s is %s emoji\n", args[0], moods[emoji]) -} diff --git a/x-tba/strings-runes-bytes/exercises/main.go b/x-tba/strings-runes-bytes/exercises/main.go deleted file mode 100644 index 8a99c7b..0000000 --- a/x-tba/strings-runes-bytes/exercises/main.go +++ /dev/null @@ -1,18 +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/ -// - -// + Masker : Use copy instead of append when appending the "http://" manually -// + Wrapper: Accept the width from the cmdline -// args, maxWidth := os.Args[1:], 40 -// if len(args) == 1 { -// maxWidth, _ = strconv.Atoi(args[0]) -// } - -package main - -func main() { -}