Pages

Friday, June 29, 2018

Bash: How to uninstall custom go package via shell script?


The Go command line tool do not provide package cleaning option. At max it can remove object files and cached files which will remove executable file from bin folder and from pkg folder. But the source files would still be there.

So if you want to completely remove the package then you have to do it manually. Otherwise, create your own script to do this.  Alternatively, you can use below script. Just put it somewhere so that it could be globally accessible.

Here is a shell script that can completely clean the go package that you have installed by using go get <package> command.

File: goclean.sh

#!/bin/env bash

goclean() {
    local pkg=$1; shift || return 1
    local ost
    local cnt
    local scr

    echo "Clean removes object files from package source directories (ignore error)"
    go clean -i $pkg

    echo "Set local variables"
    if [ "$(uname -m)" == "x86_64" ]; then
        ost="$(uname)";
        ost="${ost}_amd64"
        cnt="${pkg//[^\/]}"
    fi

    echo "Delete the source directory and compiled package directory(ies)"
    if (("${#cnt}" == "2")); then
        rm -rf "${GOPATH%%:*}/src/${pkg%/*}"
        rm -rf "${GOPATH%%:*}/pkg/${ost}/${pkg%/*}"
    elif (("${#cnt}" > "2")); then
        rm -rf "${GOPATH%%:*}/src/${pkg%/*/*}"
        rm -rf "${GOPATH%%:*}/pkg/${ost}/${pkg%/*/*}"
    fi

    echo "Reload the current shell"
    if [ -e "~/.bashrc" ]; then 
        source ~/.bashrc
    elif [ -e "~/.bash_profile" ]; then 
        source ~/.bash_profile
    fi
}

if [[ "$1" == "" ]]; then 
    echo "Package name is missing!"
else 
    goclean $1
fi

exit 0

Usage

Save it in file named goclean.sh.

$ sh goclean.sh github.com/danwakefield/gosh

Alternatively, you can save it without extension as well like goclean. It would become more useful, if you would convert it into self-executable file.

$ chmod +x ./goclean 
$ goclean github.com/danwakefield/gosh

References

Originally, I found this code at stackoverflow.com provided by ecwpz91 but that didn't worked properly on my MacOS. So I have tweaked it a little bit to suite my machine.

If you're using MacOS then it would work like charm but I haven't tried it on any Linux machine. So guys, if you find it working properly at Linux then let the readers know about it in Comment section of this article.

Thursday, June 7, 2018

Blink: Eight factors will combine to create the first trillion-dollar company.

The Four Horsemen – Amazon, Apple, Facebook and Google – dominate not only our online experience but the whole corporate world. The Four have become the world’s most valuable companies. They’ve reached their success by appealing to our deep human desires while also engaging in some questionable practices. And while there’s no doubt they’ll be around for a while, at some point, one of Four might disappear, or a fifth horseman might arise. In the meantime, it’s best to learn how to thrive in the world they’ve created.

The Four Horsemen dominate the world today. But might a fifth horseman emerge and unsaddle these other riders?

If that were to happen, this fifth horseman could well become the first company with a market valuation of $1 trillion.

According to the author, there are eight attributes that a fifth horseman would need to possess in order to become the first trillion-dollar company. Since “trillion” is the key word, he calls these combined attributes the T Algorithm.

First is product differentiation. Each of the Four offer a superior product – Apple has the iPhone; Amazon can deliver within hours – so a challenging horseman would need a comparably superior product.

Second is visionary capital. The Four all offer a compelling vision for the future – and it’s this vision that attracts investors. Google, for instance, strives to organize all the information in the world, while Facebook wants to connect everyone on earth.

Third is global reach. A trillion-dollar company needs a product that can reach anyone, anywhere. So it will probably have to be at least partially digital.

Fourth is likability. In order to avoid regulatory intervention, the fifth horseman would need a very positive image. Right now, the Four aren’t looking as benign as they once did, and this is the main chink in their armor.

Fifth is vertical integration. For a company to be vertical, it must control different stages in both the production and distribution of its product. The Four all do this.

Sixth is artificial intelligence. The Four are data experts; they collect as much data as possible and, in the process, make their algorithms as smart as possible.

Seventh is accelerant. In order to attract top talent, a fifth horseman would need to be perceived as a company that could accelerate a person’s career.

And eighth is geography. Each of the Four is situated near a prestigious university – Stanford, UC Berkeley, the University of Washington – and they each have cultivated a good relationship with their neighboring academic institution. This allows them to recruit the best and brightest.

__
The above excerpt has been taken from The Four book authored by Scott Galloway.