Skip to content

Instantly share code, notes, and snippets.

View johnwesonga's full-sized avatar

johnwesonga

  • Bay Area
View GitHub Profile
@johnwesonga
johnwesonga / checker.go
Last active August 29, 2015 13:56
URL Checker
package main
import (
"bufio"
"fmt"
"io"
"log"
"net/http"
"os"
"sync"
@johnwesonga
johnwesonga / unique elements in a slice
Created August 22, 2013 00:29
Go code that ensures elements in a slice are unique
package main
import "fmt"
func uniqueNonEmptyElementsOf(s []string) []string {
unique := make(map[string]bool, len(s))
us := make([]string, len(unique))
for _, elem := range s {
if len(elem) != 0 {
if !unique[elem] {
@johnwesonga
johnwesonga / config
Created August 22, 2013 00:25
read yaml file in Go
username: admin
password: pass
@johnwesonga
johnwesonga / Go read file - option #2
Created August 22, 2013 00:23
Read file in Go using ioutil
package main
import (
"fmt"
"io/ioutil"
"strings"
)
func main() {
f, err := ioutil.ReadFile("sample.txt")
@johnwesonga
johnwesonga / Read file in Go option #1
Created August 22, 2013 00:20
Reading a file in Go using the os package
package main
import (
"fmt"
"log"
"os"
)
func main() {
f, err := os.Open("sample.txt")
@johnwesonga
johnwesonga / gist:5141298
Last active December 14, 2015 20:08
Python vs Go on string manipulation
In Python:
key = /cns/pb-d/home/engedu/text/shakespeare/hamlet:0000000000014fb9'
s = key.split("/")[-1]
parts = s.split(":")
print "%s:%s" % (parts[0], str(int(parts[1], 16)))
In Go:
import("fmt"
"strings"
"strconv"