Wednesday, August 31, 2016

Let's Go: Command-Line Programs With Golang

Overview

The Go Language is an exciting new language that gains a lot of popularity for a good reason. In this tutorial you'll learn how to write command-line programs with Go. The sample program is called multi-git, and it allows you to execute git commands on multiple repositories at the same time.

Quick Introduction to Go

Go is an open-source C-like language created at Google by some of the original C and Unix hackers, who were motivated by their dislike of C++. It shows in Go's design, which made several unorthodox choices such as eschewing implementation inheritance, templates, and exceptions. Go is simple, reliable, and efficient. Its most distinctive feature is its explicit support for concurrent programming via so-called goroutines and channels.

Before starting to dissect the sample program, follow the official guide to get ready for Go development.

The Multi-Git Program

The multi-git program is a simple but useful Go program. If you work on a team where the codebase is split across multiple git repositories then you often need to perform changes across multiple repositories. This is a problem because git has no concept of multiple repositories. Everything revolves around a single repository. 

This becomes especially troublesome if you use branches. If you work on a feature that touches three repositories then you will have to create a feature branch in each of these repositories and then remember to check out, pull, push, and merge all of them at the same time. This is not trivial. Multi-git manages a set of repositories and lets you operate on the whole set at once. Note that the current version of multi-git requires that you create the branches individually, but I may add this feature at a later date.

By exploring the way multi-git is implemented, you will learn a lot about writing command-line programs in Go.

Packages and Imports

Go programs are organized in packages. The multi-git program consists of a single file called main.go. At the top of the file, the package name 'main' is specified, followed by a list of imports. The imports are other packages that are used by multi-git.

For example, the fmt package is used for formatted I/O similar to C's printf and scanf. Go supports installing packages from a variety of sources via the go get command. When you install packages, they end up in a namespace under the $GOPATH environment variable. You can install packages from a variety of sources such as GitHub, Bitbucket, Google code, Launchpad, and even IBM DevOps services via several common version control formats such as git, subversion, mercurial and bazaar.

Command-Line Arguments

Command-line arguments are one of the most common forms of providing input to programs. They are easy to use, allow you to run and configure the program in one line, and have great parsing support in many languages. Go calls them command-line "flags" and has the flag package for specifying and parsing command-line arguments (or flags). 

Typically, you parse command-line arguments at the beginning of your program, and multi-git follows this convention. The entry point is the main() function. The first two lines define two flags called "command" and "ignoreErrors". Each flag has a name, a data type, a default value, and a help string. The flag.Parse() call will parse the actual command-line passed to the program and will populate the defined flags.

It is also possible to access undefined arguments via the flag.Args() function. So, flags stand for pre-defined arguments and "args" are unprocessed arguments. The unprocessed arguments are 0-based indexed.

Environment Variables

Another common form of program configuration is environment variables. When you use environment variables, you may run the same program multiple times in the same environment, and all runs will use the same environment variables. 

Multi-git uses two environment variables: "MG_ROOT" and "MG_REPOS". Multi-git is designed to manage a group of git repositories that have a common parent directory. That's "MG_ROOT". The repository names are specified in "MG_REPOS" as a comma-separated string. To read the value of an environment variable you can use the os.Getenv() function.

Verifying the Repository List

Now that it found the root directory and the names of all the repositories, multi-git verifies that each repository exists under root and that it is really a git repository. The check is as simple as looking for a .git sub-directory for each repository directory.

First, an array of strings named "repos" is defined. Then it iterates over all the repo names and constructs a repository path by concatenating the root directory and the repo name. If the [os.Stat()]() call fails for the .git subdirectory, it logs the error and exits. Otherwise, the repository path is appended to the repos array.

Go has a unique error-handling facility where functions often return both a return value and an error object. Check out how os.Stat() returns two values. In this case the "_" placeholder is used to hold the actual result because you only care about the error. Go is very strict and requires named variables to be used. If you don't plan to use a value, you should assign it to "_" to avoid compilation error.

Executing Shell Commands

At this point, you have your list of repository paths where we want to execute the git command. As you recall, we received the git command line as a single command-line argument (flag) called "command". This needs to be split into an array of components (git command, sub-command, and options). The whole command as a string is stored too for display purposes.

Now, you're all set to iterate over each repository and execute the git command in each one. The "for ... range" loop construct is used again. First, multi-git changes its working directory to the current target repo "r" and prints the git command. Then it executes the command using the exec.Command() function and prints the combined output (both standard output and standard error). 

Finally, it checks if there was an error during execution. If there was an error and the ignoreErrors flag is false then multi-git bails out. The reason for optionally ignoring errors is that sometimes it's OK if commands fail on some repos. For example, if you want to check out a branch called "cool feature" on all the repositories that have this branch, you don't care if the checkout fails on repositories that don't have this branch.

Conclusion

Go is a simple yet powerful language. It's designed for large-scale system programming but works just fine for small command-line programs too. Go's minimal design is in stark contrast to other modern languages like Scale and Rust that are very powerful and well-designed too, but have a very steep learning curve. I encourage you to try Go and experiment. It's a lot of fun.


by Gigi Sayfan via Envato Tuts+ Code

This Week in Mobile Web Development (#123)

Read this on the Web

Mobile Web Weekly August 31, 2016   #123
Brian Rinaldi recommends
On The Mobile Web in Mobile Web Weekly — There was some public discussion after last week’s issue regarding Mobile Web Weekly, so I share the history of the newsletter and my own thoughts on the topics we cover. Please leave comments with your own opinions.
Brian Rinaldi
Chris Brandrick recommends
Ways To Reduce Content Shifting on Page Load — Any time a browser has to recalculate the positions of elements in a document, a reflow occurs which can affects performance and the user experience. How can these shifts be minimized?
Smashing Magazine
Holly Schinsky recommends
Start Building with Web Bluetooth and Progressive Web Apps — How to use Web Bluetooth to control any Bluetooth Low Energy device directly from your PC or smart phone as a Progressive Web App.
Uri Shaked
Sponsored
Get 5+ Engineering Job Offers in 1 Week — With Hired, companies apply to hire you - get salary and equity offers before you interview from companies like Facebook, Postmates, & Square
Hired.com

Holly Schinsky recommends
Getting Started with Meteor and Onsen UI — How to leverage Meteor and it’s integrated JavaScript stack with Onsen UI to build hybrid apps.
Fran Dios
Brian Rinaldi recommends
Adding Analytics to a React Native App — React Native is a great framework for building cross-platform apps, and Wern Ancheta looks at adding user analytics with Keen.io and Segment.io.
Sitepoint
Brian Rinaldi recommends
Element Queries: the Future of Responsive Web Design — A look at where media queries fall short and how element queries could potentially alleviate those issues.
Louie R.
Holly Schinsky recommends
The Duel: React Native vs. Cordova — A comparison of two choices for mobile-oriented JavaScript development, React Native and Cordova.
Johannes Stein
Brian Rinaldi recommends
Modernizing OAuth Interactions in Native Apps for Better Usability and Security — Google will soon stop allowing OAuth requests to Google in embedded browsers known as “web-views.”
Google Developers Blog
Brian Rinaldi recommends
Mozilla's LocalForage For Key-Value Storage In Ionic Framework — Use Mozilla’s localForage library as a more compatible storage solution for Ionic Framework Android and iOS mobile applications.
Nic Raboy
Holly Schinsky recommends
Automate Your Ionic Package Build with Wercker — How to use wercker (developer automation tooling) to automate your Ionic mobile app package builds.
De Ville Weppenaar
Brian Rinaldi recommends
Scanning Barcodes with NativeScript and Angular 2 — How to build a NativeScript app that scans barcodes and stores/retrieves product information from a NoSQL database.
Nic Raboy
Brian Rinaldi recommends
How We Made The RioRun Progressive Web App — Some of the lessons and challenges the Guardian team faced when experimenting with a progressive web app for their Olympics app.
Guardian US interactive team
Holly Schinsky recommends
15 Tips for Cross-Device Optimisation — Key rules to remember when optimizing/testing your sites to ensure compatibility on a wide range of devices.
Craig Sullivan
Brian Rinaldi recommends
Test On The Right Mobile Devices — An updated list of which devices to test based on the traffic of your site and geography of visitors using BrowserStack’s data.
BrowserStack
Holly Schinsky recommends
Why “Progressive Web Apps Vs. Native” Is The Wrong Question to Ask — Dan discusses popular misconceptions about Progressive Web Apps and provides some information on recent updates to help dispel them.
Dan Dascalescu
Brian Rinaldi recommends
Installing AMP in WordPress — A walkthrough on installing the AMP (Accelerated Mobile Pages) plugin for WordPress and the Yoast SEO Glue for the AMP plugin.
Jeff Reifman
Sponsored
Get Ready for the Launch of Angular 2: Rangle’s Online Training Program — Rangle offers this free Angular 2 online training program for JavaScript developers. Register now to join the session on September 20-21.
RANGLE.IO

Curated by Brian Rinaldi and Holly Schinsky for Cooper Press.
Cooper Press is located at Office 30, Fairfield Enterprise Centre, Louth, LN11 0LS, UK
Update your email address
or stop receiving MWW here


by via Mobile Web Weekly

The OpenTypes

opl-small

Minimal One Pager for 'The OpenTypes', a book for typography lovers by Richards Partners.

by Rob Hope via One Page Love

5 Ways to Enhance YouTube Videos for Marketers

mf-enhance-youtube-videos-600

Do you use YouTube for your business? Looking for ways to create more visibility for your videos? YouTube offers a number of helpful features to optimize your videos for more views, subscribers, or conversions. In this article, you’ll discover five ways to improve the performance of your YouTube videos. #1: Add a Watermark to Your [...]

This post 5 Ways to Enhance YouTube Videos for Marketers first appeared on .
- Your Guide to the Social Media Jungle


by Mohammad Farooq via

“I use my strengths and weaknesses to add value to my team : Ask Me Anything.”

In today’s diverse landscape of work places and situations, finding a team that is a good cultural fit is as important as finding a job.

Being able to define achievable team goals that work for every member is key to moving forward in a cohesive, productive, and fulfilling way – it’s how we make meaningful work.

Understanding your personal strengths and weaknesses and learning how to harness those in a way that adds value to your team can go a long way towards making you all happier and more efficient.

Natalie Eustace embarked on a personal journey of discovery to overcome challenges and bring her best to the dispersed team with which she works.

The Details

Meet Natalie Eustace

Natalie Eustace

Natalie is a UX Designer with Wynyard Group – a market leader in serious crime fighting software used by governments and financial institutions.

Starting in the role as a graduate and working her way up, Natalie works in a geographically widespread team who have to work hard to find ways to work cohesively together, with ideation and communication proving to be ongoing challenges.

How to Ask Your Questions

If you can’t make the live session but have questions, we’d love to collect them ahead of time and we’ll ask Natalie on your behalf. You can submit your questions here. We’ll publish the responses (along with the full transcript) in the days following the session.

How does Ask Me Anything work?

These sessions run for approximately an hour and best of all, they don’t cost a cent. We run them in our dedicated public Slack channel. That means that there is no audio or video, but a full transcript will be posted up on here in the days following the session. If you’re not familiar with Slack, you’ll need to request an invite to our channel the first time only – from then on you’re part of the family and you’ll have automatic access to new sessions.

The post “I use my strengths and weaknesses to add value to my team : Ask Me Anything.” appeared first on UX Mastery.


by Sarah Hawk via UX Mastery

Femme Fatale Studio

Femme Fatale is a creative studio focusing on culture, luxury, editorial & art. Somewhere between sophistication and simplicity.
by via Awwwards - Sites of the day

Tuesday, August 30, 2016

How to create Shareable Content Using Infographics

How to create Shareable Content Using Infographics

We are becoming more used to be served business statistics on an eye-catching infographic design rather than listed monotonously in a word document. We don’t mind the colours and imagery which comes along with infographics because it is in our nature to be captured by visuals!

Infographics come in all shapes and sizes, however, if you have missed them they tend to be super long graphics that are easy to scroll through and understand no matter what your background in the relevant subject is.

Infographics can be extremely valuable to your company and they may even boost the reach of your business through social media sharing and blogs! If you are a small business looking to adapt to big business trends infographics are an excellent start.

Let’s look at how you can create shareable content through infographics, that will grab your target audience’s attention.

by Guest Author via Digital Information World