Skip to content

Instantly share code, notes, and snippets.

@megabites2013
Created March 30, 2021 13:21
Show Gist options
  • Save megabites2013/3cfe50a724af511e8bb14468798eac03 to your computer and use it in GitHub Desktop.
Save megabites2013/3cfe50a724af511e8bb14468798eac03 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sort"
"time"
)
type User struct{
Name string
Email string
age int
}
func Reverse(s string) string {
runes := []rune(s)
for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
runes[i], runes[j] = runes[j], runes[i]
}
return string(runes)
}
func main(){
fmt.Println(time.Now().Format(time.Stamp))
var numbers [5]string
numbers[0] = "un"
numbers[1] = "deux"
numbers[2] = "trois"
numbers[3] = "quatre"
numbers[4] = "cinque"
fmt.Println(numbers)
var colors = [4]string{"rojo","gris","azul","verde"}
fmt.Println(colors)
fmt.Println(colors)
fmt.Println(len(colors))
var lifeBooster float64 = 99.2
lifeBoosterRef := &lifeBooster
lifeBooster = lifeBooster * 2.2
fmt.Println(lifeBooster)
fmt.Println(*lifeBoosterRef)
var p *int
if p != nil{
fmt.Println("P is having a value: ", *p)
} else{
fmt.Println("Watchout for nil values")
}
var thing = []string{"maleta","ropa","reloj"}
fmt.Println(thing)
thing = append(thing, "bolso")
fmt.Println(thing)
thing = append(thing[1 : len(thing)-1])
fmt.Println(thing)
heros := make([]string, 3, 3)
heros[0] = "thor"
heros[1] = "ironman"
heros[2] = "spiderman"
fmt.Println(heros)
heros = append(heros, "deadpool")
fmt.Println(heros)
fmt.Println(cap(heros))
myInts := []int{4, 7, 3, 2, 8}
isSorted := sort.IntsAreSorted(myInts)
fmt.Println("Are ints sorted: ", isSorted)
score := make(map[string]int)
score["nicholas"] = 89
fmt.Println(score)
score["josh"] = 34
score["ron"] = 23
score["sam"] = 56
score["vicky"] = 78
fmt.Println(score)
getRonScore := score["ron"]
fmt.Println(getRonScore)
delete(score, "vicky")
fmt.Println(score)
for k, v := range score{
fmt.Printf("Score of %v is %v\n", k, v )
}
rob := User{"rob", "[email protected]", 18}
fmt.Printf("%+v\n", rob)
var sam = new(User)
sam.Name = "sam"
sam.Email = "[email protected]"
sam.age = 21
fmt.Printf("%+v\n", sam)
var tobby = &User{"tobby", "[email protected]", 24}
fmt.Printf("%+v\n", tobby)
fmt.Println("Nicholas' program")
sayHello()
fmt.Println("This is my program")
fmt.Println(Reverse("hello"))
fmt.Println("iam a string!")
start := 1
things := []string{"maleta","bolso","boleta","vaso","casa"}
fmt.Println(things)
for i := 0; i < 10; i++{
fmt.Println(i + start)
}
for i := 0; i < len(things); i++{
fmt.Println(things[i])
}
for i := range things{
fmt.Println(things[i])
}
for start < 100{
start += start
if start == 32{
continue
}
fmt.Println("bacon is ", start)
}
}
func sayHello(){
fmt.Println("Hello, What's up?")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment