gokatas

package module
v0.28.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 12 Imported by: 0

README

Go Reference Go Report Card test and scan

Go katas

Katas (形) are practiced in martial arts as a way to internalize the movements and techniques so they can be executed and adapted under different circumstances, without thought or hesitation. Let's try the same with Go code.

Why

I've been learning to program in Go. I work in the sysadmin/devops and security areas so I don't normally get to program every day. But I still want to keep my coding skills fresh. Maybe even improve them. I use gokatas as one of the ways to achieve this.

How

The approach is pretty low-tech. Go katas is basically a list of packages and commands (package main) that you should understand and then be rewriting from scratch or partially. There's a command to show katas and your progress:

$ go run cmd/gokatas.go -c 2
Kata              Last done    Done  Level     Topics
----              ---------    ----  -----     ------
boring/boring     0 days ago     1x  beginner  concurrency, design
boring/channel    0 days ago     1x  beginner  goroutines, channels
areader           3 days ago     2x  beginner  interfaces, io.Reader
----                           ----
3                                4x 

It's important to practice regularly because repetition creates habits, and habits are what enable mastery. Start by taking baby steps. Set a goal that you can meet, e.g. 15 minutes every day before work. At first it's fine even if you only read through one of the beginner level katas. Use documentation or a search engine if you don't understand something.

After some time it will require much less will power to practice. Your programming moves will start looking simpler and smoother. If you feel comfortable enough with a kata, stop practicing it and pick another one that interests you and is slightly beyond your current ability.

Initial setup

  1. Install Go.

  2. Fork and then clone the repo: git clone git@github.com:<you>/gokatas.git.

  3. Start practicing:

cd gokatas
> katas.md # if you are not me :-)
go doc

Documentation

Overview

Package gokatas contains programming katas for memorizing and perfecting your Go movements. Katas are brief, well written Go programs.

Here's a typical practice cycle:

go run cmd/gokatas.go -c 2  # what kata should I practice today
code .                      # understand, delete and try to write the code back
vi katas.md                 # write down katas you've done (go doc KatasFile)

Index

Constants

View Source
const KatasFile = "katas.md"

KatasFile is a MarkDown file to track katas you've done. It looks like this:

  • 2022-09-13: boring/boring, boring/channel
  • 2022-09-10: areader

Variables

This section is empty.

Functions

func Print

func Print(katas []Kata, column int)

Print prints table with statistics about katas sorted by column.

Types

type Kata

type Kata struct {
	Name      string
	LastDone  time.Time
	TimesDone int
	Level     string
	Topics    []string
}

Kata represents a programming kata.

func Get

func Get() ([]Kata, error)

Get returns all existing katas and adds info about those you have done, i.e. written to KatasFile.

Directories

Path Synopsis
Package areader implements io.Reader with a type that emits an infinite stream of the ASCII character 'A'.
Package areader implements io.Reader with a type that emits an infinite stream of the ASCII character 'A'.
cmd
Areader reads three bytes from A into a slice.
Areader reads three bytes from A into a slice.
Package battery gets MacBook battery status.
Package battery gets MacBook battery status.
cmd
Boring contains various Go concurrency patterns in the form of boring conversations.
Boring contains various Go concurrency patterns in the form of boring conversations.
channel
A channel allows for communication and synchronization between goroutines.
A channel allows for communication and synchronization between goroutines.
generator
Generator is a function that returns a channel.
Generator is a function that returns a channel.
lockstep
Lockstep makes Ann and Joe talk in lockstep (one after another).
Lockstep makes Ann and Joe talk in lockstep (one after another).
multiplex
Multiplex lets talk Ann or Joe (whosever is ready) using fanIn function.
Multiplex lets talk Ann or Joe (whosever is ready) using fanIn function.
select
Select statement is another way to handle multiple channels.
Select statement is another way to handle multiple channels.
selectquit
Use quit channel to stop the conversation.
Use quit channel to stop the conversation.
Bytecounter shows how to use interfaces.
Bytecounter shows how to use interfaces.
Clock2 is a TCP server that periodically writes the time.
Clock2 is a TCP server that periodically writes the time.
Print statistics about katas you've done.
Print statistics about katas you've done.
Package compress compresses files.
Package compress compresses files.
cmd
Compress files concurrently using a wait group.
Compress files concurrently using a wait group.
Package cookie writes and reads a (not signed and not encrypted) HTTP [cookie].
Package cookie writes and reads a (not signed and not encrypted) HTTP [cookie].
cmd
Web server that sets a cookie and shows that client sent it back.
Web server that sets a cookie and shows that client sent it back.
Package count2 counts lines in input.
Package count2 counts lines in input.
cmd
Package count3 uses "functional options" pattern to set zero or more options.
Package count3 uses "functional options" pattern to set zero or more options.
cmd
Package count5 accepts input also from one or more files supplied as command line arguments.
Package count5 accepts input also from one or more files supplied as command line arguments.
cmd
Package counter implements an integer counter that can only be incremented.
Package counter implements an integer counter that can only be incremented.
cmd
Counter creates an integer counter, increments it, prints it and resets it.
Counter creates an integer counter, increments it, prints it and resets it.
Package countgo counts files with extension ".go" in fs.FS.
Package countgo counts files with extension ".go" in fs.FS.
cmd
Countgo counts files with .go extension in supplied directory or in ".".
Countgo counts files with .go extension in supplied directory or in ".".
Cryptopals shows basic crypto operations.
Cryptopals shows basic crypto operations.
Dirs shows how to work with filesystem directories.
Dirs shows how to work with filesystem directories.
Dup2 prints the count and text of lines that appear more than once in the input.
Dup2 prints the count and text of lines that appear more than once in the input.
Dup3 prints the count and text of lines that appear more than once in the named input files.
Dup3 prints the count and text of lines that appear more than once in the named input files.
Echo prints its command-line arguments.
Echo prints its command-line arguments.
Echosrv is a web server that echoes the path component of the URL.
Echosrv is a web server that echoes the path component of the URL.
Package enum shows idiomatic way to implement an enumerated type:
Package enum shows idiomatic way to implement an enumerated type:
cmd
Enum shows how to use enumerated type.
Enum shows how to use enumerated type.
Fetch prints content found at URLs defined as command line arguments.
Fetch prints content found at URLs defined as command line arguments.
Fetchall ranges over the CLI arguments (that should be URLs) and fetches each of them.
Fetchall ranges over the CLI arguments (that should be URLs) and fetches each of them.
Fibchan implements a function that returns a channel generating Fibonacci sequence.
Fibchan implements a function that returns a channel generating Fibonacci sequence.
Fibfunc implements a function that returns a function (a closure) generating Fibonacci sequence.
Fibfunc implements a function that returns a function (a closure) generating Fibonacci sequence.
Fibspin calculates 46th number from the Fibonacci sequence.
Fibspin calculates 46th number from the Fibonacci sequence.
Findlinks2 does an HTTP GET on each URL, parses the result as HTML, and prints the links within it.
Findlinks2 does an HTTP GET on each URL, parses the result as HTML, and prints the links within it.
Generics shows the basics of generics.
Generics shows the basics of generics.
Package geometry defines simple types for plane geometry.
Package geometry defines simple types for plane geometry.
Google is a toy search engine using the Go concurrency patterns from the boring folder.
Google is a toy search engine using the Go concurrency patterns from the boring folder.
v2.0
V2.0 runs the three kinds of search concurrently using the fan-in pattern.
V2.0 runs the three kinds of search concurrently using the fan-in pattern.
v2.1
V2.1 times out the search after 80ms using the timeout pattern.
V2.1 times out the search after 80ms using the timeout pattern.
v3.0
V3.0 introduces replication.
V3.0 introduces replication.
Package kv implements key-value store that persists data to disk.
Package kv implements key-value store that persists data to disk.
Package logger uses channels to implement non-blocking logging.
Package logger uses channels to implement non-blocking logging.
cmd
Log handles logging gracefully.
Log handles logging gracefully.
Myprint shows how come fmt.Print can print (any number of) arguments of any type.
Myprint shows how come fmt.Print can print (any number of) arguments of any type.
Netcat1 is a read-only TCP client.
Netcat1 is a read-only TCP client.
Netcat2 is a read/write TCP client.
Netcat2 is a read/write TCP client.
Noescape shows how to suppress html/template auto-escaping behavior for fields that contain trusted HTML data.
Noescape shows how to suppress html/template auto-escaping behavior for fields that contain trusted HTML data.
Package older finds files older than a given duration.
Package older finds files older than a given duration.
cmd
Outline prints the structure of the HTML node tree supplied on STDIN.
Outline prints the structure of the HTML node tree supplied on STDIN.
Panic describes and shows how panic and defer work.
Panic describes and shows how panic and defer work.
Parsejson parses a JSON string and prints it out.
Parsejson parses a JSON string and prints it out.
Pingpong shows how (un-buffered) channels are used for communication and synchronization between goroutines.
Pingpong shows how (un-buffered) channels are used for communication and synchronization between goroutines.
https://github.com/jreisinger/homepage/blob/master/notes/go/pointers.md
https://github.com/jreisinger/homepage/blob/master/notes/go/pointers.md
Primesieve is a concurrent prime sieve.
Primesieve is a concurrent prime sieve.
Package promyaml shows how to get (Prometheus) configuration from YAML file.
Package promyaml shows how to get (Prometheus) configuration from YAML file.
Proxy is a simple proxy that mediates TCP traffic between client and upstream.
Proxy is a simple proxy that mediates TCP traffic between client and upstream.
Package repike is a Go [rewrite] of Rob Pike's regex [matcher] that handles:
Package repike is a Go [rewrite] of Rob Pike's regex [matcher] that handles:
cmd
Package reverse reverses a string.
Package reverse reverses a string.
Package rot13 implements an io.Reader that reads from an io.Reader, modifying the stream by applying the rot13 algorithm to it.
Package rot13 implements an io.Reader that reads from an io.Reader, modifying the stream by applying the rot13 algorithm to it.
cmd
Decode message encoded with rot13 cipher.
Decode message encoded with rot13 cipher.
Package search implements linear and binary search algorithms.
Package search implements linear and binary search algorithms.
Shop4 is a web shop selling shoes and socks.
Shop4 is a web shop selling shoes and socks.
https://github.com/jreisinger/homepage/blob/master/notes/go/slices.md
https://github.com/jreisinger/homepage/blob/master/notes/go/slices.md
Sortbooks sorts a collection of books.
Sortbooks sorts a collection of books.
Package sqrt calculates square root: given number x, we want to find the number z for which z² is most nearly x.
Package sqrt calculates square root: given number x, we want to find the number z for which z² is most nearly x.
Package sum sums a list of integers using loop and divide-and-conquer technique.
Package sum sums a list of integers using loop and divide-and-conquer technique.
Sample functions using switch statement.
Sample functions using switch statement.
Tcpscanner reports open TCP ports on a host.
Tcpscanner reports open TCP ports on a host.
Package thumb explores three common concurrency patterns for executing all the iterations of a loop in parallel.
Package thumb explores three common concurrency patterns for executing all the iterations of a loop in parallel.
cmd
Thumb generates thumbnails for the supplied JPEG pictures.
Thumb generates thumbnails for the supplied JPEG pictures.
The thumbnail package produces thumbnail-size images from larger images.
The thumbnail package produces thumbnail-size images from larger images.
Tictactoe creates a a tic-tac-toe board as a slice of string slices.
Tictactoe creates a a tic-tac-toe board as a slice of string slices.
Timer times out a goroutine that emits Go pointer types over a channel.
Timer times out a goroutine that emits Go pointer types over a channel.
Package weather shows how to build an API client.
Package weather shows how to build an API client.
cmd
Package word provides utilities for word games.
Package word provides utilities for word games.
Package write shows how to write programs manipulating files with test-first approach (TDD).
Package write shows how to write programs manipulating files with test-first approach (TDD).
z
Package z takes lines from stdin, makes them into tasks that get processed and printed.
Package z takes lines from stdin, makes them into tasks that get processed and printed.
lookup-v1
A faster version of lookup-v0.sh that handles errors and can be generalized.
A faster version of lookup-v0.sh that handles errors and can be generalized.
lookup-v2
Lookup version that uses z package.
Lookup version that uses z package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL