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
View loop.go
package main
import "fmt"
func main() {
loops := 1
// while loop
for loops < 10 {
fmt.Println(loops)
@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!", "你好火星", "สวัสดีดาวอังคาร")
}
@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 / 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 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() {
@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 / swap.go
Created Sep 30, 2014
Multiple return values in Go
View swap.go
package main
import "fmt"
func swap(a, b int) (int, int) {
_a := a
_b := b
a, b = _b, _a
@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 / func.go
Created Sep 30, 2014
Function in Go
View func.go
package main
import "fmt"
func colormap(r uint8, g uint8, b uint8) (color map[string]uint8) {
color := map[string]uint8{
"r" : r
"g" : g,
"b" : b,
}
@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)
You can’t perform that action at this time.