Skip to content

Instantly share code, notes, and snippets.

View tevin-morake's full-sized avatar
😏

Tevin Morake tevin-morake

😏
View GitHub Profile
@tevin-morake
tevin-morake / update-golang.md
Created April 3, 2018 21:39 — forked from nikhita/update-golang.md
How to update the Go version

How to update the Go version

System: Ubuntu 14.04 (Trusty Tahr)

1. Uninstall the exisiting version

As mentioned here, to update a go version you will first need to uninstall the original version.

To uninstall, delete the /usr/local/go directory by:

@tevin-morake
tevin-morake / createindex.go
Created April 7, 2019 05:42
How to create an elastic search index with default mappings
mapping := `{"settings":{"number_of_shards":1,"number_of_replicas":0},"mappings":{"cities":{"properties":{"CompanyName":{"type":"text"},"Addresses":{"type":"text"},"PostCode":{"type":"text"}}}}}`
elasticSURL := "https://xxxxxx"
client, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetURL(elasticSURL))
if err != nil {
// handle error
}
info, code, err := client.Ping(elasticSURL).Do(context.Background())
if err != nil {
// handle error
@tevin-morake
tevin-morake / embedded_structs.go
Created April 7, 2019 21:38
Illustrates how to use embedded structs and access fields within embedded structs
package main
import (
"fmt"
)
/*
* With Embedded structs,the embedded fields are promoted to the parent struct
* For Example, the programmer struct is embedded within the staffMembers struct.
@tevin-morake
tevin-morake / reduce.go
Created April 8, 2019 12:00
Sometimes we need a simple way to reduce values in go, but we know that go isn't JS. This gist aims at mimicking the js reduce method
package main
import (
"fmt"
)
// This is my way of reducing in go
func main() {
reportMarks := []int{20, 45, 78, 3, 59, 95, 6}
totalMarks := sum(reportMarks...)
@tevin-morake
tevin-morake / closure_explained.go
Created April 10, 2019 00:46
Just explaining closure in go
package main
import (
"fmt"
)
/*
* What is Closure in go ?
* Closure is basically one scope enclosing other scopes .
* What does that mean ?
package main
import (
"fmt"
"sort"
)
type Person struct {
First string
Age int