Categories
Data Structure and Algorithm

Slice of Slice

https://play.golang.org/p/3HpTAxoPC6l

// in Go Data Structures and algorithms book
package main

// importing fmt package
import (
	"fmt"
)

// main method
func main() {
	var rows int
	var cols int
	rows = 7
	cols = 9
	
	// rows := 7
	// cols := 9
	
 	var twodslices = make([][]int, rows)
	var i int
	for i = range twodslices {
		twodslices[i] = make([]int, cols)
	}
	fmt.Println(twodslices)
}
Categories
Data Structure and Algorithm

Create and Print a 2D Slice

https://play.golang.org/p/F5MTsF_Z1J1

// in Go Data Structures and algorithms book
package main

// importing fmt package
import (
	"fmt"
)

// main method
func main() {
	var TwoDArray [8][8]int
	TwoDArray[3][6] = 18
	TwoDArray[7][4] = 3
	fmt.Println(TwoDArray)
}
Categories
Regular Expression

Literals in Regular Expression

Literals are the simplest form of pattern matching in regular expressions. They will simply succeed whenever that literal is found.

func Match 

func Match(pattern string, b []byte) (matched bool, err error)

Match reports whether the byte slice b contains any match of the regular expression pattern.

Example Code

package main

import (
	"fmt"
	"regexp"
)

func main() {
        pattern:="Hello"
        // Match() function return a boolean type value 
        // with boolean it limit us from extracting the match string value
	matched, err := regexp.Match(pattern, []byte(`World Hello`))
	// print value return from Match() func
	fmt.Println(matched, err)
	if matched {
	   fmt.Println("Found")
	} else {
	   fmt.Println("Not Found")
	}
}

Go Playground

https://play.golang.org/p/ts3SyaxKQgF

Resources

go doc regexp/syntax

https://pkg.go.dev/regexp?tab=doc#pkg-overview

Categories
Go Testing

Go Built-in Unit Testing

Naming conventions ( prefix with underscore)

suffix with underscore with the filename. For example, the hello.go is the source file then hello.go with test package will have the filename hello_test.go tells the go test command that this file contains test functions.

hello_test.go

Testing package

Importing the testing package is a must to be included along with other imported packages such as the “fmt” package that it commonly in use.

import (
    "testing"
)

Test command

At the command line where the source code directory, run the go test command to execute the test

go test

Implement a Test Functions

Expect results of the function

Prefix the Test to the function name. For example, TestHelloName()

// TestHelloName calls greetings.Hello with a name, checking 
// for a valid return value.
func TestHelloName(t *testing.T) {
    name := "Gladys"
    want := regexp.MustCompile(`\b`+name+`\b`)
    msg, err := Hello("Gladys")
    if !want.MatchString(msg) || err != nil {
        t.Fatalf(`Hello("Gladys") = %q, %v, want match for %#q, nil`, msg, err, want)
    }
}

Resources

https://golang.org/doc/tutorial/add-a-test

Categories
Language

Create a Module

https://golang.org/doc/tutorial/create-module

Categories
Git GitHub and Git Special Interest

GitHub Guides

https://guides.github.com/

Categories
Git

Understanding the GitHub flow

https://guides.github.com/introduction/flow/

Categories
Git

Creating a github.io personal website inside a GitHub repository


From https://guides.github.com/features/pages/

GitHub Pages are public webpages hosted and easily published through GitHub. The quickest way to get up and running is by using the Jekyll Theme Chooser to load a pre-made theme. You can then modify your GitHub Pages’ content and style remotely via the web or locally on your computer.

Create Your Website

Once you’ve signed in, you’ll create a new repository to get started.

On the new repository screen, you need to give this repository a special name to generate your website.

Your website’s files will live in a repository named username.github.io (where “username” is your actual GitHub user name). To begin setting up your site, you have to open the Settings tab

If you scroll down on the settings page, you’ll see the GitHub Pages section near the bottom. Click the Choose a theme button to start the process of creating your site.

Once you’ve clicked the button, you’ll be directed to the Theme Chooser. You’ll see several theme options in a carousel across the top of the page. Click on the images to preview the themes. Once you’ve selected one, click Select theme on the right to move on. It’s easy to change your theme later, so if you’re not sure, just choose one for now.

Here’s where you’ll write your own content (You can keep the default content for now, if you’d like).

Once you’re finished editing, scroll down to the bottom of the page and click Commit changes.

GitHub does all the work to direct visitors to username.github.io to view your new website. This can take up to 10 minutes. After some time has passed, you can open a new tab in your browser to go to your site!

Making Changes

One of the first things you can do is remove the default title of your index page, and add a friendlier message to it. Since this is a very quick change – and your first one – you’re going to make it on the default branch: master.

View the _config.yml file by navigating to it in the Code tab. You can edit the file by clicking on the pencil icon.

Currently your site has no set title, so we’re falling back to the name of the repo. To change this, I’m going to add the line “title: Welcome to the Octocat’s homepage!” to this file. Feel free to do the same, except for your own username.

Under this title, you can add a message about the purpose of the page and describe what you want people to do while they’re here. I’m going set mine to “Feel free to bookmark this to keep an eye on my project updates”

After you’re done making this small change, scroll to the bottom of the page to make your second commit. You have two places to write about this change: a subject and an extended description. The extended description is optional, so let’s leave a descriptive message in the subject.

When you’re done, click Commit changes and your updates will go live in just a few seconds!

Categories
Git

Connecting to GitHub with SSH

You can connect to GitHub using SSH.

About SSH→

Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username or password at each visit.

Checking for existing SSH keys→

Before you generate an SSH key, you can check to see if you have any existing SSH keys.

Generating a new SSH key and adding it to the ssh-agent→

After you’ve checked for existing SSH keys, you can generate a new SSH key to use for authentication, then add it to the ssh-agent.

Adding a new SSH key to your GitHub account→

To configure your GitHub account to use your new (or existing) SSH key, you’ll also need to add it to your GitHub account.

Testing your SSH connection→

After you’ve set up your SSH key and added it to your GitHub account, you can test your connection.

Working with SSH key passphrases→

You can secure your SSH keys and configure an authentication agent so that you won’t have to reenter your passphrase every time you use your SSH keys.

Categories
Git

Using SSH for not having to input passwords when passing Git commands

https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh