Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Joe Chasinga jochasinga

🏠
Working from home
Block or report user

Report or block jochasinga

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jochasinga
jochasinga / .bash_profile
Created Sep 29, 2014
GOPATH export after intallation of Go
View .bash_profile
export GOPATH=$HOME/Go
export PATH=$PATH:$GOPATH/bin
@jochasinga
jochasinga / hello_mars.go
Last active Aug 29, 2015
Hello Mars in Go
View hello_mars.go
package main
import "fmt"
func main() {
// Print string in English, Chinese and Thai
fmt.Println("Hello Mars!", "你好火星", "สวัสดีดาวอังคาร")
}
View variables.go
package main
import "fmt"
var global1 int // Declaring a variable with `var` keyword
var global2 int = 10 // Assigning a value to a variable right away
var global3 = "this is ok!" // Go infer type based on your value
// bad_var := "this doesn't work" // `:=` can be used only inside a function
func main() {
View loop.go
package main
import "fmt"
func main() {
loops := 1
// while loop
for loops < 10 {
fmt.Println(loops)
@jochasinga
jochasinga / if.go
Created Sep 30, 2014
If condition in Go
View if.go
package main
import "fmt"
func main() {
i := 1
for i <= 10 {
if i % 2 == 0 {
fmt.Println(i, "even")
} else {
@jochasinga
jochasinga / switch.go
Last active Aug 29, 2015
Switch in Go
View switch.go
package main
import "fmt"
func main() {
var input float64
fmt.Scanf("%f", &input)
switch input {
View array.go
package main
import "fmt"
func main() {
var x [5]int
x[4] = 100
fmt.Println(x)
}
@jochasinga
jochasinga / array_loop.go
Created Sep 30, 2014
Looping in an array
View array_loop.go
package main
import "fmt"
var arr = [10]int{ 1, 21, 35, 4, 30, 6, 12, 9, 4, 10 }
func main() {
// loop through arr and print out all values
for i := 0; i < len(arr); i++ {
fmt.Println(arr[i])
@jochasinga
jochasinga / loop_range.go
Created Sep 30, 2014
Special for loop in Go
View loop_range.go
package main
import "fmt"
var arr = [10]int{ 1, 21, 35, 4, 30, 6, 12, 9, 4, 10 }
func main() {
// loop through arr and print out all values
for _, v := range arr {
fmt.Println(v)
@jochasinga
jochasinga / embedded_map.go
Created Sep 30, 2014
Embedded Maps in Go
View embedded_map.go
package main
import "fmt"
func main() {
creatures := make(map[string]map[string]string)
creatures = map[string]map[string]string{
"P" : map[string]string{
"name" : "Pokemon",
You can’t perform that action at this time.