Showing posts with label golang. Show all posts
Showing posts with label golang. Show all posts

Golang Development Environment with GVM in Ubuntu 18.10

It has been a while since I last looked at development using Golang. Since I was reading some Golang code during this period, might as well look at setting the Golang development environment in Ubuntu 18.10.

There are several ways to setup your Golang development environment. Two good choices are using the default package installation or using Go Version Manager (GVM). There are several options to choose from default packages management, either by DEB or Snap as shown below.
$ go

Command 'go' not found, but can be installed with:

sudo snap install go         # version 1.10.3, or
sudo apt  install golang-go
sudo apt  install gccgo-go 

However, if you want several different Go versions co-exist within the same machine or want to get the latest greatest version, Go Version Manager (GVM) will be the preferred choices. While my preference choice is to use existing package manager (simpler and easier), it's good to look into other approaches. Hence, our focus of this post will be on GVM.

Some prerequisites. Please install and remove some packages (if you have existing Go installed).
$ sudo apt install curl git mercurial make binutils bison gcc build-essential
$ sudo apt remove golang-go
$ sudo snap remove go

Next, download and install the gvm installer. Yes, we all know downloading and running Bash script from the Interweb is rather stupid and insecure. But what the heck.
$ zsh < < (curl -s -S -L
Cloning from to /home/ang/.gvm
Created profile for existing install of Go at "/snap/go/3039"
Installed GVM v1.0.22

Please restart your terminal session or to get started right away run
 `source /home/ang/.gvm/scripts/gvm`

Reload your Bash file settings.
$ source ~/.zshrc

Find the most recent 5 stable releases.
$ gvm listall | grep -v -E '(release|beta|rc)' | sort -rn -t. -k2,2 | head -n 5

Install the binary.
$ gvm install go1.11.2 --binary

Set and use the default binary.
$ gvm use go1.11.2 --default
Now using version go1.11.2

Now check your installation.
$ which go

Now, check your Golang related environment paths.
$ gvm pkgset list

gvm go package sets (go1.11.2)

=> global

See the environment settings of the `global` profile.
$ gvm pkgenv global

If you don't like Gvm and want to nuke the whole installation.
$ gvm implode

This Week I Learned - 2017 Week 00

Happy new year!

2017, the year of the fire rooster. It will be interesting to see what this year will unfold itself. The plan will still remain the same every year. The usual stay alive and healthy, more reading, learning, writing, coding, and producing as well as build new habits. In other words, do, try, make more mistakes. As they said, "One who makes no mistakes make nothing at all". Be constant aware of you thoughts and actions. Live in the moments. There is a Zen saying, "When hungry, eat. When tired, sleep". Nevertheless, do plan ahead and learn from your past. In short, continue what you planned last year and adjust accordingly.

Learning reflection for 2016. I wrote 58 posts last year. Still a firm believer of quantity over quality. Writing is like exercising, you need to practice persistently to get better. However, blindly deliberate practice without any targets may be wasteful and leads to no where. Still something to ponder about. What I learned last year? Mostly Perl and Git as well as others stuff in between. When there are always rooms for improvement, all these exposure to new old stuff (Perl is damn old anyway) did satisfy my intellectual curiosity. Exposure to C++ for the last two months was interesting. It really piqued my interesting on static type programming languages.

As usual, here we go, something new I've learned this week.

#1 According to ISO 8601, the definition of week 01 if 1st Jan falls on Monday till Thursday. If it falls on Friday till Sunday, it's still the last week of previous year. However, there is no week 00. Nevertheless, I still prefer to call it week 00, as 1st Jan signifies a fresh start.

#2 Information overload? Thinking of applying digital minimalism? (via HN). FOMO is probably is main cause to our digital clutter. Unless these digital tools can bring values to your offline life, ditch them. Likewise, I still have a long way to go with my minimalist lifestyle, not everything fit into one bag yet. There are literally thousands of things I wish to ditch away. Still, one thing at a time.

#3 The D programming language. If you're doing doing development for quite some time and follow the programming language trend, you probably heard about this programming language. I've stumbled upon this again while doing some C++ coding. Developed as an alternative or replacement to C++, it still failed, after all these years, to gain any traction (based on my reading and impression of Thoughtworks' Technology Radar, HN, and Dlang subreddit). It was one year ago since Andrei Alexandrescu quit his secure job at Facebook (get a big pay cut but financially still ok) to push D forward on full time basis, does it really helps?

I played and read through the documentation, on the surface, it's looks quite nice, Python-like syntax with C/C++ speed but isn't Golang or Nim existed for the same reason? Nevertheless, the documentation was fun to read. Love the Contract Programming, especially the Invariants.  The wiki post on Components Programming Using D (ala functional programming) was one of the most interesting read on programming language this new year.

While we at it, some adjustments are needed to get Dlang to work in Ubuntu 16.10.

First, setup the APT repository for D.
$ sudo wget \
-O /etc/apt/sources.list.d/d-apt.list

$ sudo apt-get update && sudo apt-get -y --allow-unauthenticated install \
--reinstall d-apt-keyring && $ sudo apt-get update

$ sudo apt install dmd

Next, generate the sample hello word project.
$ dub init hello
$ cd hello/source

However, you will encounter error below during compilation.
$ dmd app.d
/usr/bin/ld: app.o: relocation R_X86_64_32 against symbol `__dmd_personality_v0' 
can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libphobos2.a(exception_249_55a.o): 
relocation R_X86_64_32 against symbol `__dmd_personality_v0' can not 
be used when making a shared object; recompile with -fPIC

Add these additional options to get it to run.
$ dmd app.d -fPIC
Edit source/app.d to start your project.

Compile and run on-the-fly.
$ rdmd -fPIC app.d
Edit source/app.d to start your project.

This Week I Learned - 2016 Week 41

Last week post or the whole series.

This is probably the unexpected way or the one-liner new way to purge old Linux kernels. You will need to install byobu (text-based window manager and multiplexer) as the Bash script is part of the package. Why I need to purge the old kernels? Well, I can't upgrade to Ubuntu 16.10 because `/boot` partition don't have enough free spaces.
$ sudo apt install byobu
$ sudo purge-old-kernels

Epoch, the start of a time, is commonly used in computing as a point of reference or date arithmetic. For Unix, the epoch starts from Jan 1, 1970. And I thought that was the standard epoch time used for every Operating System. I didn't realize that for Windows as well as for other platforms, the epoch time was different and it's set to Jan 1, 1601 (represented in FILETIME structure), a few hundres years earlier than Unix epoch time. Why? 1601 is the first year of 400-years cycle of Gregorian calendar.

Conversion between two epoch system times is straight forward using the simple formulae or another approach to calculate the different between two values, which is 11644473600 seconds. (Note that Windows tick is 100-nano seconds interval, which is 10000000). If you have a Windows epoch timestamp (18-digits), use this site to convert to normal date.

Using Git in Windows? Do use the Perforce's P4Merge as git merge tool for the three-ways merging tasks. Learned this while watching how other developer works. You can pick up a lot by watching how others works. Do keep that in mind.

Almost at the end of the year, maybe this is the right time to pick up Golang? Don't like buying Go books, well, someone recommended me to pick up "The Little Go Book".

Looking for beautiful real-time log analyzer? Try GoAccess, which is depends on gwsocket, a RFC 6455 compliant web socket server.. I should install this for my homelab later.

Testing your web application locally but wants to simulate different IP addresses? Try IP Spoofing to simulate HTTP requests

Using testing in C++, use Google Test. Going to try this in coming days if I can get my C++ development environment working.

This Week I Learned - 2016 Week 05

Last week post.

#1 Reply 1988. Highest rated drama in Korea cable television as the time of writing. Heart-warming family Korean drama about a group of neighbouring families and friends set in 1988. Lots of nostagia look back in the eighties. Interestingly, the genre of the drama is known as coming of age where we follow the growth of the characters from youth to adulthood. One of the drama's original sound track (OST), "A Little Girl" (a remake) caught my attention. It has been a while since I've mesmerized by any OST. Frankly speaking, the best kdrama I've watched so far. And lastly, why 1988? Is the year that Korea hosted the Summer Olympics which leads to a significant political and social changes.

#2 TypeMatrix. (via Arcachne Webzine) Another ergonomic keyboard but without splitting the layout into half but instead more sensible keys placement, for example, large Enter key in the center.

#3 Visualizing Concurrency in Go. (HN dicusssion) Visually intriguing but 2D representation is still better than 3D, for example, like UML sequence diagram? Would be even better if we can have step-by-step tracing of the code and the visualizing simultaneously.

#4 Overpass Web Font, free/libre font by Red Hat. Primary used for the company own branding.

#5 Docker Official Images Are Moving to Alpine Linux. The sentiment in HN discussion does not agree with such approach. Furthermore, docker-slim was created to solve fatty container issue using your favourite GNU/Linux distros.

Golang Installation in Ubuntu 13.10

Based on this instruction, not the cleanest package-based installation.

Install the necessary packages
$ sudo apt-get install golang bzr

Create and set the $GOPATH
$ mkdir $HOME/Project/go
$ export $GOPATH=$HOME/Projects/go

Obtain and install the godeb utility. Note that the tool is located in launchpad, hence the need of bzr version control in step 1.
$ go get

Test our installation of godeb.
$ $GOPATH/bin/godeb --help

Remove the existing old Golang binary of version 1.1.2.
$ sudo apt-get remove golang

List all available version and install the latest version
$ $GOPATH/bin/godeb list
$ sudo dpkg -i --force-overwrite go_1.2-godeb1_amd64.deb

How An Expert And Beginner Code Fizz Buzz in Go

This complex solution for Fizz Buzz in Go caught my attention. Decided to write a simpler version for comparison. Still trying my to grok the former code which uses Go's channel to implement concurrency. It has been a while since I last read Go's code, let alone such complex one (for me). Still a lot to catch up.

On a related note, Fizz buzz, which I always thought the typical common way to filter programmer who can or can't code, is actually a children game that teach them about division.