Use Byte Slice Instead of Strings

Hello Folks. This is just a quick post on the topic and a reminder for myself and everybody to ALWAYS USE []BYTE INSTEAD OF STRINGS. []Byte is marginally faster than a simple Strings. In fact, I would say using []byte should be the standard instead of strings. Sample code: package solutions import "fmt" const ( //INPUT input INPUT = "1321131112" //LIMIT limit LIMIT = 50 ) //LookAndSay translates numbers according to Look and Say algo func LookAndSay(s string, c chan string) { charCount := 1 look := "" for i := range s { if i+1 < len(s) { if s[i] == s[i+1] { charCount++ } else { look += fmt....

December 29, 2015 · 2 min · hannibal

Recursive Letter Frequency Count

Hello everybody! I wanted to do a sort post about word frequency count. I did it many times now and I was curious as how a recursive solution would perform as opposed to looping. So I wrote it up quickly and added a few benchmarks with different sized data. First…. The code: var freqMap = make(map[string]int, 0) func countLettersRecursive(s string) string { if len(s) == 0 { return s } freqMap[string(s[0])]++ return countLettersRecursive(s[1:]) } func countLettersLoop(s string) { for _, v := range s { freqMap[string(v)]++ } } Very simple....

December 23, 2015 · 1 min · hannibal

Go Development Environment

Hello folks. Here is a little something I’ve put together, since I’m doing it a lot. Go Development Environment If I have a project I’d like to contribute, like GoHugo, I have to setup a development environment, because most of the times, I’m on a Mac. And on OSX things work differently. I like to work in a Linux environment since that’s what most of the projects are built on....

December 8, 2015 · 1 min · hannibal

Go JIRA API client

Hi folks. So, I was playing around and created a client for JIRA written in Go. It was nice to do some JSON transformation. And sending POSTS was really trivial. It’s still in it’s infancy and I have a couple of more features I want to implement, but, here is the code. package main import ( "bytes" "encoding/json" "flag" "fmt" "io/ioutil" "log" "net/http" "os" "github.com/BurntSushi/toml" ) var configFile = "~/.jira_config.toml" var parameter string var flags struct { Comment string Description string IssueKey string Priority string Resolution string Title string Project string } //Issue is a representation of a Jira Issue type Issue struct { Fields struct { Project struct { Key string `json:"key"` } `json:"project"` Summary string `json:"summary"` Description string `json:"description"` Issuetype struct { Name string `json:"name"` } `json:"issuetype"` Priority struct { ID string `json:"id"` } `json:"priority"` } `json:"fields"` } //Transition defines a transition json object....

November 20, 2015 · 3 min · hannibal

Go Progress Quest

Hi Folks. I started to build a Progress Quest type of web app in Go. If you’d like to join, or just tag along, please drop by here => Go Progress Quest and feel free to submit an issue if you have an idea, or would like to contribute! I will try and document the Progress. Thank you for reading! Gergely.

November 9, 2015 · 1 min · hannibal

Circular buffer in Go

I’m proud of this one too. No peaking. I like how go let’s you do this kind of stuff in a very nice way. package circular import "fmt" //TestVersion testVersion const TestVersion = 1 //Buffer buffer type type Buffer struct { buffer []byte full int size int s, e int } //NewBuffer creates a new Buffer func NewBuffer(size int) *Buffer { return &Buffer{buffer: make([]byte, size), s: 0, e: 0, size: size, full: 0} } //ReadByte reads a byte from b Buffer func (b *Buffer) ReadByte() (byte, error) { if b....

October 15, 2015 · 1 min · hannibal

DataMunger Kata with Go

Quickly wrote up the Data Munger code kata in Go. Next time, I want better abstractions. And a way to select columns based on their header data. For now, this is not bad. package main import ( "bufio" "fmt" "log" "math" "os" "regexp" "strconv" "strings" ) //Data which is Data type Data struct { columnName string compareOne float64 compareTwo float64 } func main() { // datas := []Data{WeatherData{}, FootballData{}} fmt.Println("Minimum weather data:", GetDataMinimumDiff("weather....

October 4, 2015 · 2 min · hannibal

Sieve of Eratosthenes in Go

I’m pretty proud of this one as well. package sieve //Sieve Uses the Sieve of Eratosthenes to calculate primes to a certain limit func Sieve(limit int) []int { var listOfPrimes []int markers := make([]bool, limit) for i := 2; i < limit; i++ { if !markers[i] { for j := i + i; j < limit; j += i { markers[j] = true } listOfPrimes = append(listOfPrimes, i) } } return listOfPrimes }

July 30, 2015 · 1 min · hannibal