Global variable for never changing regex

Quick reminder. If you have a never changing regex in Go, do NOT put it into a frequently called function. ALWAYS put it into a global variable. I’ll show you why. Benchmark for code with a variable in a frequently called function: BenchmarkNumber-8 30000 41633 ns/op BenchmarkAreaCode-8 50000 27736 ns/op BenchmarkFormat-8 50000 29263 ns/op PASS ok _/phone-number 5.110s Benchmark for code with the same variable outside in a global scope:...

August 16, 2016 · 1 min · hannibal

How to do Google sign-in with Go

Hi folks. Today, I would like to write up a step - by - step guide with a sample web app on how to do Google Sign-In and authorization. ...

June 12, 2016 · 6 min · hannibal

Wercker Fixed

Hi Folks. So Wercker was not working. After a minor modification it seems to be okay now. The config file needed for it to work looks like this: box: golang build: steps: - arjen/hugo-build: theme: redlounge deploy: steps: - install-packages: packages: git - leipert/git-push: gh_oauth: $GIT_TOKEN repo: skarlso/skarlso.github.io branch: master basedir: public The modification is the box type to golang and removed ssh-client from packages. Thanks, Gergely.

March 9, 2016 · 1 min · hannibal

Wercker Test

Basics This is a wercker Test.

March 4, 2016 · 1 min · hannibal

Wercker Test

Basics This is a wercker Test.

February 10, 2016 · 1 min · hannibal

Doing CORS in Go with Gin and JSON

Basics Hello folks. This will be a quick post about how to do CORS with jQuery, Gin in Go with a very simple ajax GET and Json. I’m choosing JSON here because basically I don’t really like JSONP. And actually, it’s not very complicated to do CORS, it’s just hidden enough so that it doesn’t become transparent. First, what is CORS? It’s Cross-Platform Resource Sharing. It has been invented so that without your explicit authorization in the header of a request, Javascript can’t reach outside of your domain and be potentially harmful to your visitors....

February 2, 2016 · 4 min · hannibal

My Journey in advent of code

Hello folks. I wanted to share with you my tale of working through the problems with Advent Of Code. It is a nice tale and there are a few things I learned from it, especially in Go, since I used that solve all of the problems. So, let’s get started. Solving the problems The most important lesson I learned while doing these exercises was, how to solve these problems. A couple of them were simple enough to not have to over think it, but most of them got very tricky....

January 22, 2016 · 8 min · hannibal

Improving performance with byte slice and int map

Hello Folks. Today I would like to share with you my little tale of refactoring my solution to Advent Of Code Day 13. It’s a lovely tale of action, adventure, drama, and comedy. Let’s being with my first iteration of the problem. package main import ( "bufio" "fmt" "math" "os" "strconv" "strings" "github.com/skarlso/goutils/arrayutils" ) var seatingCombinations = make([][]string, 0) var table = make(map[string][]map[string]int) var keys = make([]string, 0) //Person a person type Person struct { // neighbour *Person name string like int } func main() { file, _ := os....

January 5, 2016 · 7 min · hannibal

Byte arrays and Channels

Hi folks and a Happy new Year! Today, I would like to show you some interesting things you can do with channels. Consider the following simple example. package main import "fmt" func main() { generatedPassword := make(chan int, 100) correctPassword := make(chan int) defer close(generatedPassword) defer close(correctPassword) go passwordIncrement(generatedPassword) go checkPassword(generatedPassword, correctPassword) pass := <-correctPassword fmt.Println(pass) } func checkPassword(input <-chan int, output chan<- int) { for { p := <-input //Introduce lengthy operation here // time....

January 1, 2016 · 4 min · hannibal

Use Byte Array 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