[ REVIEW ] PACKT Publishing’s Video courses on “Building Your First Application with Go”

Posted in Uncategorized with tags , , , , , , on April 25, 2014 by abhishekkr

Recently I was asked to review PACKT Publishing‘s Video courses on “Building Your First Application with Go” from Rostyslav Dzinko. I’ll accept I thought it would be just beginner’s stuff looking at the title, but designer of course has managed to bring in an interesting flow and some good practice points along the flow.

~Review~

The course structure is very broad, let not the course title make you take a narrow view. It covers from the mere basics of downloading and installing Golang compiler. Then slowly moves on to teach how to build a full working web application for image effects with some good dev practices.

What would you gain from it?

It’s formed of 8 fine sections which gradually make you familiar with different constructs of Golang internals.

The first section covers getting your workspace ready to try out Golang programming and strcture of a Golang program. It introduces to tools provided by Golang for seeking help, checking respective environment variables, lint formatting the code, running/building/installing Golang program. Shows example of a program taking input, processing the value and sending it to standard output. Then it ends with single line and multi-line style of commenting and quickly ends with introduction to Godoc way of Golang Code Documentation.

The second section starts with basic definitions of variable and constants, scope availability and then discusses the type inference capability. It details out all the important data types and example usages of each. In the end Narrator points to “strings” packages for learners to go and explore, which is good in a way not to serve everything on a platter. While giving intro to maps the Narrator also gives a taste of easy serialization/deserialization of data in Golang using example of “encoding/json” module.

The third section focuses on Control Structures. Covering if-else and switch-case for conditional logic, few variations of for for loop. It also talks of handling error and comma-ok notation returned.

The fourth section is about structuring the code with package and functions. Examples are given of functions, anonymous functions, packages, init functionality in packages and usability of deferred execution.

The fifth section familiarizes learners with the example of practicing Object Oriented Programming using Golang constructs. Narrator starts with insight on use of Structures in Golang with some examples and how can behaviors be added to Structures. A very good work has been done at explaining interfaces with gradual examples. It’s one of the philosophically misunderstood thus hated feature of Golang ad the Narrator has done a good job in averting that for beginners.

The sixth section is dedicated to one of the forte of Golang, concurrent system programming. Narrator shows some neat easy examples around usage of Goroutines and then brings in a better usable approach with “runtime” and “sync” package features. Then he explains well on role of Channels with good usecase examples. He showcases use of buffered channels, fan-in pattern, fan-out pattern also in a very simple but clear way.

The seventh section is their to make learners familiar with Golangs built-in package power for web application development. There are examples here for running a web server, handling routing, using HTTP GET request parameters. Narrator also gives a quick demo on using “Gorilla Web Framewoek“‘s routing and query param capabilities giving a sample Golang being ready for advanced web-app development. HTML Templating library is also covered in a decent manner. It ends with intro to panic and recover feature of Golang, which are not specific to web programming but specific to any good Golang project.

The eigth and final section is all about using what all has been covered so far and turning it into a real world web application capable of uplaoding an image; then performing color inversion and rotation on it. Narrator uses Golang’s “image” package for image transformations and the upload files are just kept in memory map of image filenames to file-data blobs. Then in the end he refactors the grown messy code into independent packages with real scenario implementation on interfaces. He also introduces a smal test case showing how code can be tested in Golang while introducing httptest library.

Occassional mentions of few philosophical decision is also there.

What could have been better?

(There is a fair possibility that I missed Narrator doing it but if I didn’t miss it.)

  • In third section Narrator doesn’t cover for-range usage, though uses it in fourth section and further later. Range brings a very widely implemented practically used power to for control structures.
  • Narrator forgot new behaviors can be added to any local type, not just structures. An example on this would have eased up how behaviors can be added to a local type declared on string (or other).
  • In Section 8, when Narrator starts to use “image” package for Image Upload and other actions… in certain functions (like HandleUpload) identifier of “image” name has been used. When “image” package is already imported, no identifier should have been named so. It doesn’t error out because “image” is not used in that function scope as a package, but it’s still not a good practice and can result into error as function get changed over time in real scenarios.
  • Some of the important philosophies that learners of this course shall look at after completing are, to have better understanding of certain things in Golang
  • Would have preferred if he did demo of “hello world” on play.golang.org and then moved to system installation with editor driven coding. It gives learners a very easy taste of it first and also show how easy is it to tryout Golang. Also play.golang.org can be projected as a starter place to browse through examples for more understanding of good and bad code.
  • One thing could have been improved on showmanship of course, that is showing build result of code in Editor windows’s pane. Almost all good editors today have addons for Golang providing this and lot more. Since Narrator was using “Sublime Text“, he could have used plugin “GoSublime“.

Overall

It’s a lot more hands-on than theory which is great. Though out of 8 sections, first 7 sections are mainly focussed towards beginners in Golang who want have a complete understanding of it and are preapred well for it (they are like covering Effective Go in a video). Still the last 8th section can be utilized by even intermediate level Golang developers who understand the constructs of it but face hard time bringing in good development practices they have been using in other programming languages. I felt some bits missing here and there which I’ve already mentined in “What could have been better?” para above.

There two good things about this course that I want to highlight: * Usage of examples and then building over them for coming part of course showcases how to finely grow a spiked Golang code. * Cleverly covering few good developer practices by hugely improving upon the mess of code written for “First Application (WIMP)”. The coding practice worried me in intial part of the section but when Narrator refactored it, the intention was clear.

Overall, it’s a good course for anyone trying to get started in learning Golang or are in their early stages.

[tekwalk] xopen : shell function to have verbose xdg-open : Mac’s “open” alternative for Linux

Posted in AbhishekKr, Blogroll, install-on-linux with tags , , , , , , , on March 4, 2014 by abhishekkr

tekwalk.blogspot.in [13/Feb/2014]

http://tekwalk.blogspot.in/2014/02/xopen-shell-function-to-have-verbose.html

I have been using xdg-open for sometime now, it’s a utility similar to “open” utility popular among MacOSx users.

It enables you to open any file in the default “open with” program assigned to it’s type. So, just passing any type of file to this utility would let you open it in the program it’s supposed to open.

What is xdg-open?
source[1]: https://wiki.archlinux.org/index.php/xdg-open
source[2]: http://linux.die.net/man/1/xdg-open

There is just this little shell function, that makes your xdg-open usage a bit more verbose in case of errors (bad-syntax/ghost-file/ghost-program/open-failure) faced about the reason for it. And also shortens the access util name obviously.

xopen ()
{
xdg-open “$@”;
_TMP_EXITCODE=$?;
if [ "${_TMP_EXITCODE}" == "1" ]; then
echo “[ERROR:] Error in command line syntax”;
else
if [ "${_TMP_EXITCODE}" == "2" ]; then
echo “[ERROR:] One of the files passed on the command line did not exist”;
else
if [ "${_TMP_EXITCODE}" == "3" ]; then
echo “[ERROR:] A required tool could not be found”;
else
if [ "${_TMP_EXITCODE}" == "4" ]; then
echo “[ERROR:] The action failed”;
fi;
fi;
fi;
fi;
return $_TMP_EXITCODE
}

…read full blogpost here

[just.few.tuts] golang ~ get local changes into GOPATH without pushing them upstream

Posted in AbhishekKr, Blogroll, tutorial with tags , , , , on March 4, 2014 by abhishekkr

justfewtuts.blogspot.in [3/Feb/2014]

http://justfewtuts.blogspot.in/2014/02/golang-get-local-changes-into-gopath.html

To get your local Golang repo’s sym-linked at your GOPATH and local changes available…

goenv_link(){
  if [ $# -ne 2 ]; then
    echo "Links up current dir to it's go-get location in GOPATH"
    echo "SYNTAX: goenv_linkme  "
    return 1
  fi
  _REPO_DIR=$1
  _REPO_URL=$2

  _TMP_PWD=$PWD
  cd $_REPO_DIR

  if [ -d "${GOPATH}/src/${_REPO_URL}" ]; then
    echo "$_REPO_URL already exists at GOPATH $GOPATH"
    go get "${_REPO_URL}"
    return 1
  fi
  _REPO_BASEDIR=$(dirname "${GOPATH}/src/${_REPO_URL}")
  if [ ! -d "${_REPO_BASEDIR}" ]; then
    mkdir -p "${_REPO_BASEDIR}/src"
  fi

  ln -sf "${PWD}" "${GOPATH}/src/${_REPO_URL}"
  go get "${_REPO_URL}"

  cd $_TMP_PWD
}

alias goenv_linkme="goenv_link $PWD"

…read full blogpost here

[just.few.tuts] go get pkg ~ easy made easier for project dependency management

Posted in AbhishekKr, Blogroll, tutorial with tags , , , , , , on March 4, 2014 by abhishekkr

justfewtuts.blogspot.in [5/Dec/2013]

http://justfewtuts.blogspot.in/2013/12/go-get-pkg-easy-made-easier-for-project.html

For past sometime I’ve been trying out ways to improve practices upon awesome capabilities from GoLang. One of the things have been having a ‘bundle install’ (for ruby folks) or ‘pip require -e’ (for python folks)  style capability… something that just refers to an text file part of source code and plainly fetches all the dependencies path mentioned in there (for all others).

It and some other bits can be referred here…
https://github.com/abhishekkr/tux-svc-mux/blob/master/shell_profile/a.golang.sh#L31

… …  …

What it do?

If ran without any parameters. It checks for current working directory for a file called ‘go-get-pkg.txt’. If not found creates one empty file by that name. To be done at initialization of project. If found, then it iterates through each line and pass it directly to “get get ${line}”. If ran with parameters. Each parameter is treated as path to files similar to ‘go-get-pkg.txt’ and similar action as explained previously is performed on each file.

Sample ‘go-get-pkg.txt’ file
-tags zmq_3_x github.com/alecthomas/gozmq github.com/abhishekkr/levigoNS github.com/abhishekkr/goshare

…read full blogpost here

[just.few.tuts] systemd enabled lightweight NameSpace Containers ~ QuickStart Guide

Posted in AbhishekKr, tutorial with tags , , , , , , , , , , on November 19, 2013 by abhishekkr

justfewtuts.blogspot.in [15/Nov/2013]

http://justfewtuts.blogspot.in/2013/11/systemd-enabled-lightweight-namespace.html

systemd (for some time now) provides a powerful chroot alternative to linux users for creating quick and lightweight system containers using power ofcgroups and socket activation.

There is a lot more to “systemd” than this, but that’s for some other post. Until then can explore it, starting here.

There is a utility “systemd-nspawn” provided by systemd which acts as container manager. This is what can be used to easily spawn a new linux container and manage it. It has been updated with (the systemd’s amazing trademark feature) Socket Activation.

This enables any container to make parent/host’s systemd instance to listen at different service ports for itself. Only when those service ports receive a connection, these container will spawn and act to it. Voila, resource utilization and scalability concepts.
More of this can read in detail at: http://0pointer.de/blog/projects/socket-activated-containers.html

Here we’ll see some way to quickly start using it via some custom made commands.

…..

…..

…..read full blogpost here

[hackersmag] HTTP Referer Spoofing, don’t get confused, don’t worry, Block or Avoid

Posted in AbhishekKr, security with tags , , , , , , , , on November 19, 2013 by abhishekkr

hackersmag.blogspot.in [30/Oct/2013]

http://hackersmag.blogspot.in/2013/10/http-referer-spoofing-dont-get-confused.html

HTTP Referer?
It’s an optional HTTP Request Header which can be set to URI to inform the WebServer the source URI which led the client to current URI.

Analytics Benefit:
It’s useful for Web content publishers for analysis sake as per which are the web portals that are attractive more visitors to that URI.

Security Benefit:
It has also been seen to be used as an extra layer of check by WebApps to confirm if the requested URI has been accessed via proper channels and respond accordingly.

HTTP Referer Spoofing ?

As other popular spoofing attack this doesn’t involve attacker trying to hide their identity.

…..
…..

Threat ?
There are potential 2 types of threats which arise from it:
…..
….. 
Solution ?
…..
…..
read full blogpost here

[tux-install] Counter-Strike (Steam) on ArchLinux via Wine

Posted in AbhishekKr, install-on-linux with tags , , , , , , , , on November 19, 2013 by abhishekkr

tuxinstall.blogspot.in [30/Oct/2013]

http://tuxinstall.blogspot.in/2013/10/counter-strike-steam-on-archlinux-via.html

get the required base package available at archlinux

sudo pacman -S –noconfirm wine winetricks

sudo pacman -S –noconfirm wine_gecko wine-monoq4wine

try to get “steam” installed the proper way

winetricks steam

if the above command fails the next two commands shall do the job, although you’ll need to download aria2.exe (and unzip) and maybe SteamInstall.msi (if not found)

msiexec /i ~/.cache/winetricks/steam/SteamInstall.msi

wine arial32.exe /Q

now the system is ready to run Steam Client, try following script to run it (otherwise there might be some font not displaying or other issues)

#!/bin/bash

export WINEPREFIX=$HOME/.steam

export WINEDEBUG=-all

nice -n 19 wine ~/.wine/drive_c/Program\ Files\ \(x86\)/Steam/Steam.exe -no-dwrite

#####end-of-script

using it you can start your Steam Client, then it’s common way as other platforms to log-in to your Steam Account and install Counter Strike or any other game you play

…source blog here

Follow

Get every new post delivered to your Inbox.