Skip to content

Instantly share code, notes, and snippets.

View roylee0704's full-sized avatar
🧘‍♂️

roylee0704

🧘‍♂️
  • Bangkok, Thailand
View GitHub Profile

Setting up Vim as your Go IDE

The final IDE

Intro

I've been wanting to do a serious project in Go. One thing holding me back has been a my working environment. As a huge PyCharm user, I was hoping the Go IDE plugin for IntelliJ IDEA would fit my needs. However, it never felt quite right. After a previous experiment a few years ago using Vim, I knew how powerful it could be if I put in the time to make it so. Luckily there are plugins for almost anything you need to do with Go or what you would expect form and IDE. While this is no where near comprehensive, it will get you writing code, building and testing with the power you would expect from Vim.

Getting Started

I'm assuming you're coming with a clean slate. For me this was OSX so I used MacVim. There is nothing in my config files that assumes this is the case.

@roylee0704
roylee0704 / strcmp.go
Created May 12, 2016 10:43
strings comparison snippet
func compare(s, t string) bool {
if len(s) != len(t) {
return false
}
for i := range s {
if s[i] != t[i] {
return false
}
}
return true
@roylee0704
roylee0704 / substr.go
Created May 12, 2016 11:24
substring implemented naively.
func naive_substr(s, t string) bool {
if len(s) > len(t) {
return false
}
for i := 0; i < len(t)-len(s); i++ {
if !compare(s, t[i:len(s)+i]) {
return false
}
}
@roylee0704
roylee0704 / prehash_tuple.py
Created May 15, 2016 11:21
python prehash implementation of tuple type. (simplified version)
def hash(tuple):
mult = 1000003
x = 0x345678
for index, item in enumerate(tuple):
x = ((x ^ hash(item)) * mult) & (1<<32)
mult += (82520 + (len(tuple)-index)*2)
return x + 97531
@roylee0704
roylee0704 / prehash_str.py
Created May 15, 2016 11:22
Python hash implementation of type str.
def hash(string):
x = string[0] << 7
for chr in string[1:]:
x = ((1000003 * x) ^ chr) & (1<<32)
return x
@roylee0704
roylee0704 / prehash_customtype.py
Created May 15, 2016 11:39
Python prehash implementation of custom type.
class CustomType:
def __init__(self,name,location,length):
self.name = name
self.location = location
self.length = length
def __hash__(self):
return hash((self.name, self.location))
@roylee0704
roylee0704 / balancer.go
Created May 21, 2016 09:25 — forked from angeldm/balancer.go
Rob Pike balancer for go
package main
import (
"container/heap"
"fmt"
"math/rand"
"time"
)
const nRequester = 100
type intHeap []int
func (h intHeap) Less(i, j int) bool {
return h[i] < h[j]
}
func (h intHeap) Len() int {
return len(h)
}
USER=
PASS=
REPO=
ORG=
PROJECT="$USER"
#uncomment $PROJECT if your are creating labels for organisation.
#PROJECT="$ORG"
# Delete default labels
@roylee0704
roylee0704 / goupdate.sh
Last active August 18, 2016 07:11
do it every go version update.
brew update
brew upgrade go
gometalinter --update --install --force
# for atom.
gocode close && go get -u github.com/nsf/gocode