You are on page 1of 109

Using Ansible To Deploy

Cacti For Monitoring


An Introduction
To gRPC
` 120
ISSN-2456-4885

Volume: 05 | Issue: 08 | Pages: 108 | May 2017

I built C++
primarily for myself
and my colleagues

Sharpen Your
Programming
SkillS
Programming With
Shell Scripts
A Guide To Programming In
Perl, PHP And Python

Dart: An Easy, Scalable


And Multi-purpose
Programming Language

Case Study: Vodafone Deploys Open An Interview With


Source To Reduce Vendor Lock-in Bjarne Stroustrup, Creator Of C++
ISSN-2456-4885

Admin
24 Handling Large Files
Using Open Source Tools
29 DevOps: Using Ansible to
Deploy Cacti for Monitoring
36 The Basics of Vulnerability
Assessment and Penetration
Testing

Developers
38 Exploring Sinatra
41 Scala: The Powerhouse of
Apache Spark
44 An Introduction to gRPC
50 Qt Programming for HTTP
Programming the Internet of
58
REST Clients
54 A Quick Look at
Programming with Shell Things Using Contiki and Cooja
Scripts
62 A Guide to Programming in
Perl, PHP and Python
69 Python: The User Friendly
Language for Coding
73 An Introduction to HTML5
78 Top IDEs for Raspberry Pi
83 Using State Machines
to Build Better Software
85 Qt: The Cross-Platform
Development Toolkit
87 Creating the Sliding Number
Game in App Inventor 2
Dart: An Easy, Scalable and Multi-
91 Searching Text Strings from
Files Using Python purpose Programming Language 65
Open Gurus
94 Hack the Bootsector
and Write Your Own! R EGUL AR FEATURES
102 Beaglebone Black: Flashing 06 FOSSBytes 14 New Products 104 Tips & Tricks
eMMC through an SD Card

4 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Editor
Rahul chopRa

Editorial, SubScriptionS & advErtiSing


Delhi (hQ)
d-87/1, okhla industrial area, phase i, new delhi 110020
ph: (011) 26810602, 26810603; Fax: 26817563
E-mail: info@efy.in

MiSSing iSSuES
e-mail: support@efy.in

back iSSuES
Kits n Spares
new delhi 110020
ph: (011) 26371661, 26371662
E-mail: info@kitsnspares.com

nEwSStand diStribution
ph: 011-40596600
E-mail: efycirc@efy.in
advErtiSEMEntS
mumbai
ph: (022) 24950047, 24928520
E-mail: efymum@efy.in

beNGaluRu
ph: (080) 25260394, 25260023
E-mail: efyblr@efy.in

PuNe
ph: 08800295610/ 09870682995
E-mail: efypune@efy.in

GuJaRaT
ph: (079) 61344948
E-mail: efyahd@efy.in

Vodafone Deploys Open Source


99
chiNa
power pioneer group inc.
ph: (86 755) 83729797, (86) 13923802595

to Reduce Vendor Lock-in


E-mail: powerpioneer@efy.in

JaPaN
tandem inc., ph: 81-3-3541-4166
E-mail: tandem@efy.in

Columns
20
SiNGaPORe
publicitas Singapore pte ltd

16 CodeSport
ph: +65-6836 2272
E-mail: publicitas@efy.in

I built C++ 18 Exploring Software: TaiwaN


J.k. Media, ph: 886-2-87726780 ext. 10
primarily for Diaspora: The Free, E-mail: jkmedia@efy.in

Distributed Social
myself and my
Network
uNiTeD STaTeS

colleagues E & tech Media


ph: +1 860 536 6677
E-mail: veroniquelamarque@gmail.com

Reco
mm
end
ed
Sys printed, published and owned by ramesh chopra. printed at tara
te m
Re
qu
ire
art printers pvt ltd, a-46,47, Sec-5, noida, on 28th of the previous
me
nt
. nts month, and published from d-87/1, okhla industrial area, phase i, new
e
em

delhi 110020. copyright 2017. all articles in this issue, except for
:P
lac

4,
1G
ep

Live
er

BR

interviews, verbatim quotes, or unless otherwise explicitly mentioned,


fre

AM
a

,
or

will be released under creative commons attribution-noncommercial


DV

Bjarne Stroustrup, creator of C++


17.04
in f

D-R
efy.

OM

3.0 unported license a month after the date of publication. refer to


rt@

Driv
ppo

http://creativecommons.org/licenses/by-nc/3.0/ for a copy of the


e
at su

licence. although every effort is made to ensure accuracy, no responsi-


does not work properly, write to us

bility whatsoever is taken for any loss due to publishing errors. articles
that cannot be used are returned to the authors if accompanied by a
May 2017
self-addressed and sufficiently stamped envelope. but no responsibility
is taken for any loss or delay in returning the material. disputes, if any,

DVD of The MonTh


will be settled in a new delhi court only.
VD
this D
ase
In c

Heres the latest version of SubScRiPTiON RaTeS


Ubuntu for your desktop. Year Newstand Price You Pay Overseas
(`) (`)
Ubuntu 17.04 Desktop Five 7200 4320
three 4320 3030
Lubuntu 17.04 one 1440 1150 uS$ 120

106
CD Team
e-mail: cdteam@efy.in

KDE Neon kindly add ` 50/- for outside delhi cheques.


please send payments only in favour of eFY enterprises Pvt ltd.
Rocksor 3.9.0 non-receipt of copies may be reported to support@efy.indo mention
your subscription number.

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 5


FOSSBYTES Compiled by:
Jagmeet Singh

It was all about the future of Red Hat Gluster Storage 3.2
containers at the Bangalore lowers data integrity costs
Container Conference
Red Hat has announced the new
version of Gluster Storage 3.2. The
update comes preloaded with several
Bangalore Container performance improvements as well
Conference (BCC), held as deeper integration with Red Hat
on April 7 at Bengaluru, OpenShift Container Platform.
was Indias first conference Focusing on performance
focused on container improvements, Red Hat Gluster
technologies, and attracted Storage 3.2 provides data integrity
more than 250 delegates. at a lower cost. There is enhanced
Containers are eating integration with OpenShift Container
the world. It has been Platform that brings native support for
Docker, Docker, everywhere advanced storage services like geo-
for the last few years, said replication and in-flight encryption for
Hari Kiran, one of the organisers of the Bangalore Container Conference (BCC) applications deployed in containers.
and co-founder of CodeOps Technologies. Red Hat Gluster Storage 3.2
When asked about what prompted him to conduct an event like BCC, Kiran marks a milestone in the life of the
told Open Source For You, Given the fact that there is substantial interest in product. It brings together a number
container technologies among developers in India, we realised that the time is ripe of innovations that are relevant to the
for organising Indias first conference on this topic. modern CIO, said Ranga Rangachari,
All the tickets for BCC 2017 were sold out a month before the conference vice president and general manager of
date. The conference hosted Evan Powell, chairman of OpenEBS, and Ian Lewis, storage, Red Hat.
developer advocate at Google, who travelled from the US and Japan, respectively. Red Hat claims that the upgraded
Both the experts were featured at the keynote sessions. OpenShift Container Platform
In his opening address, Powell spoke about the relationship between support can enable three times as
DevOps and containers. He explained how the DevOps industry is expected to many persistent volumes per cluster.
significantly benefit from the container ecosystem and its technologies. The newly added improvements also
Lewis began his keynote on standards-based containerisation with offer a smaller hardware footprint
Kubernetes and explained why standards are important. He elaborated on how through arbiter volumes and shrink
they allow interoperability between systems and the right level of abstraction at infrastructure costs while maintaining
each part of the stack. data integrity. They also fix the
Organisations are increasingly adopting containers and related technologies in problem of data mismatch between
production and want to learn from others successes, failures and best practices. two nodes.
Hence, the theme chosen for the conference was Containers in production. Customers running traditional NAS
Following the talks by the experts, there was a panel discussion on using use cases for backup/restore can achieve
containers in production. The conference also featured two workshops. Open data integrity, while hyper-converged
Source For You was the media partner for the event. configurations in branch offices can
save on hardware costs, power and data
Microsoft fixes OneDrive performance issue on Linux centre space. The software package also
Microsoft has finally fixed the infamous OneDrive performance issue that was comes with the Nagios framework to
widely reported by Linux users. The monitor storage operations.
slow access to OneDrive on Linux-based The latest Gluster Storage version
distros had downgraded the experience has also fixed to scale metadata-
for many on the open source platform. intensive operations for large files.
The performance issue was due to a Red Hat believes that faster metadata-
forced Windows user-agent string on intensive operations can improve daily
Chrome and Firefox based browsers operations by 8x. The new release
on Linux. Some users even felt that is focused on the software-defined
Microsoft was deliberately causing performance hiccups for Linux users. storage industry.

6 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


FOSSBYTES

Microsoft has responded to a thread in Hacker News announcing the fix. Infosys embraces open source,
According to Edgar Hernandez from the OneDrive team, the StaticLoad.aspx page joins network community
that pre-fetches resources in the background for Office apps was a less efficient Indian IT services giant, Infosys, has
technique causing the earlier-mentioned issue. He also clarified that the issue was joined the Open Invention Network (OIN)
not intentional. as a community member. The new move
The pre-fetching optimisation was disabled, and it will be enabled again soon will enable the Bengaluru-headquartered
after an update for StaticLoad.aspx has been tested on Linux and released. We company to share its developments with
apologise for the inconvenience this may have caused, Hernandez wrote. over 2,000 member companies in the OIN
Alongside announcing the fix, Hernandez promised thorough Linux testing in community, which is funded by Google,
the future. Microsoft apparently wants to make sure that OneDrive is a productive IBM, NEC, Philips, Red Hat and SUSE.
service for as many users as possible. We appreciate Infosys leadership
in joining OIN and believe that those
SAP joins Hyperledger Project to embrace open source who look to the company for inspiration,
blockchain developments both in and outside of India, will see
SAP SE, the company known for its proprietary enterprise software offerings, is the wisdom it has demonstrated by
finally moving on the open source path and has joined the Hyperledger Project as supporting patent non-aggression
a premier member. The new development will allow SAP to utilise the advanced in Linux and adjacent open source
blockchain technology driven by open source collaboration. technologies, said Keith Bergelt, CEO of
As a part of the new collaboration, Dominik Heere, vice president of innovation Open Invention Network.
engineering, SAP Innovation Centre Network, will represent SAPs content on the Infosys considers open source software
Hyperledger governing board. Based in Walldorf, Germany, SAP is set to enable as the primary engine of innovation
blockchain technology in existing and new business scenarios for its enterprise that will help boost areas such as cloud
clients through the Hyperledger computing, Big Data, artificial intelligence,
Project. The community-driven DevOps and modern Web frameworks.
blockchain developments will be Joining OIN will be vital for the company
implemented across SAPs entire to expand its IT presence by not just sharing
portfolio, including the SAP Ariba its developments with other community
network. members but also enabling it access to the
In joining Hyperledger, we intellectual property of member companies
plan to share our expertise and without paying a royalty fee.
knowledge to help bring open Infosys is actively taking open source
distributed ledger technology and open source based products to all our
to all businesses, said Juergen Mueller, chief innovation officer, SAP, in a joint enterprise customers, so we are extremely
statement. We believe blockchain is a transformative technology for enterprise excited to become a part of OIN. We
businesses. We are committed to advancing its adoption via the creation of new encourage others to join it as well and
standards, use cases, platforms and open applications, he added. support this very important initiative,
Led by the Linux Foundation, the Hyperledger Project aims to develop a model said Navin Budhiraja, SVP and head,
of a commonly distributed ledger that lets organisations build and run industry- architecture and technology, Infosys.
specific applications, platforms and hardware systems to support their industrys North Carolina-based OIN is the
business transactions. More than 122 members have already joined the project, leading patent non-aggression community
which is what seems to have persuaded SAP to also do so. to promote the deployments of Linux and
Having support from an enterprise software and cloud leader like SAP is an other related open source technologies.
important step in the right direction. The diversity of our members is a real strength, Patents owned by the OIN community are
as we look to advance open blockchain technology POCs, pilots and production licensed royalty-free to help companies
deployments across many industries this year, said Brian Behlendorf, executive expand and enhance their existing
director, Hyperledger. offerings and promote open source.
SAP is planning to enable use cases like provenance scenarios, digital object Prior to Infosys, German automaker
representations and collaborative transaction executions. Daimler had joined OIN. The parent
IBM also recently joined the Hyperledger Project to enter the growing company of Mercedes-Benz is aiming
blockchain space. The IT giant has announced its own blockchain ecosystem called to leverage open patents to upgrade
the IBM Blockchain that is backed by the collaborative consortium. intelligent vehicle technologies.

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 7


FOSSBYTES

Google set to speed up Huaweis KunLun server to run SUSE Linux Enterprise Server
Android security update Huawei has announced its partnership with SUSE to bring SUSE Linux Enterprise
releases Server as the preferred standard OS for its KunLun RAS 2.0. The open source
Google is working on upgrading the platform supposedly comes with reliability, availability and serviceability features
security update system for Android. for the server, and the combination brings an always online offering for enterprises.
The search giant has started working At CeBIT 2016, Huawei and SUSE jointly launched KunLun as the worlds
with third-party manufacturers and first 32-socket mission critical server. That tie-up influenced both the companies
cell phone carriers to improve the to move a step ahead and ultimately made SUSE Linux Enterprise Server the
speed of security updates and make preferred standard operating system.
the open source platform more secure. Now we bring our partnership to a new level by releasing the industrys first
Almost half of Android users standard Linux OS that supports KunLun RAS 2.0. The OS will help KunLun
do not receive important security deliver reliability that is parallel to, and even surpasses that of traditional high-end
updates. Google pushed updates to UNIX servers. These benefits will translate into a better return on investment for our
735 million devices last year, but customers, said Wang Zhen, vice president for IT, server product line, Huawei.
half of them did not receive the The operating system for KunLun is based on SUSE Linux Enterprise Server
patch from device manufacturers. 12 Service Pack 2. It supports RAS 2.0 features that allow customers to add or
Therefore, the company is aiming to remove CPU and memory resources without shutting down the system.
push the updates within just a few SUSE leads the industry by releasing the preferred standard OS that supports
days from release by working with KunLun RAS 2.0 features, including CPU and memory hot swap, said Ralf Flaxa,
carriers and manufacturers. president of engineering at SUSE. The SUSE team led by Flaxa is also developing
an in-service kernel upgrade feature in order to deliver all the latest updates to the
Linux-backed platform.
Huawei has designed KunLun to address the high reliability, performance and
scalability requirements of mission-critical environments by leveraging the x86
ecosystem. The company claims that the server can overcome the longstanding
restrictions of enclosed architectures.

We provided monthly security Google releases Android O and aims to improve battery life
updates for all supported Pixel and While you might be waiting to test your apps on Android Nougat, Google has
Nexus devices throughout 2016, and moved a step ahead and released the first developer preview of Android O. The
we are thrilled to see our partners focus of the new open source project is supposedly to improve battery life and
invest significantly in regular enhance performance on compatible devices.
updates as well. There is still a lot of Battery life is one big concern on Android devices. Though Android engineers
room for improvement, however, at Google had tried to fix various bugs on its Lollipop, Marshmallow and the recent
Googles Android security team Nougat versions, the issue persists on almost all the smartphones and tablets.
members Adrian Ludwig and Mel But with Android O, the Sunder Pichai-led team is planning to deliver a better
Miller, wrote in a blog post. experience by enabling some automatic limits on apps running in the background.
Pushing the updates to Android This advances the power optimisation that was a part of the Nougat release last year.
devices, except the Nexus and Pixel Building on the work we began in Nougat, Android O places a big priority
models, is a complex process. Device on improving a users battery life and a devices interactive performance. To
manufacturers and carriers have make this possible, we have put additional automatic limits on what apps can
to compile the patch to match the do in the background, in three main areas implicit broadcasts, background
devices requirements. services and location updates, explains Dave Burke, vice president of
Working with manufacturers engineering at Google, in a blog post.
and carriers to restructure the The latest changes supposedly enable apps to have minimal impact on the
updates release system can certainly hardware and this enhances the battery life.
speed up the delivery schedule Developers are recommended to learn the tweaks to make their apps
of security updates for Android. compatible with the new background limits. Google has already got documentation
However, it is impossible to ensure ready on background execution limits and background location limits to make
the protection of the over 1.4 billion things easier for app makers.
Android users worldwide. Alongside the enhancements to improve battery life, Android O is all about an

8 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


FOSSBYTES

upgraded experience. There are new notification channels that work to enable app- LibreELEC adds support for
defined categories for notification content. The operating system also works with auto- Raspberry Pi Zero W
fill APIs to add login details and repetitive information automatically to certain forms. The Linux community has received
The Android O additionally includes some root-level changes to improve the a new LibreELEC update that comes
existing user experience. There are font resources in XML as well as adaptive icons with native support for Raspberry Pi
and a wide gamut of colour capabilities for apps. Zero W. The latest release also comes
Google has also provided a large number of Java 8 language APIs and runtime with a new Kodi version.
optimisations to take on other mobile platforms including iOS. You can download Dubbed as LibreELEC 8.0.1, the
the very first Android O Developer Preview on your Nexus or Pixel device. The new new version is specifically designed
version comes with an updated SDK to make development even easier. Moreover, an to upgrade the experience across a
emulator has been specifically designed to test Android Wear 2.0 apps on Android O. variety of hardware. The very first
A manual download and Flash is currently the only available channel to install the noticeable change in the update is
O release on compatible devices. But you should only install the preview to test your the support for Raspberry Pi Zero W,
development skills, as some hidden bugs can affect the performance of your device. which was recently launched with
wireless connectivity options.
Orgs, the team collaboration software from npm, becomes free
for open source developers
npm Inc., the parent company of Node.js, has announced that it has made its
developer collaboration tool free for open source projects. Called Orgs, the tool is
popular among JavaScript and Node.js developers.
The free version is only available for open source projects. But those using
Orgs for private packages still need to
opt for the premium subscription of US$
7 per month/per user.
npm has decided to offer the free
version to support development in open
source. Making it easier to collaborate
on open source projects benefits the
whole community, because anything Additionally, the LibreELEC
that reduces friction in software development makes it easier for everyone to build team has provided improvements for
amazing things, said Isaac Z. Schlueter, CEO of npm Inc., in a statement. the Raspberry Pi 3 board. You can
With this development, open source teams can now use advanced capabilities experience the improved software
like role-based access control, package search and semantic versioning for free. HEVC decoding, as well as support
npm can simplify the particular kind of dependency between two software packages for Fe Pi audio cards and Cirrus
or modules in any project. Besides, Orgs can help users share and manage code Logic DAC. Users opting for the
packages among team members. Kodi media player can also enjoy the
advantage of the new maintenance
Netflix debuts on Linux with HTML5 video playback release and receive its fresh build
A long time after its arrival on proprietary platforms, media streaming service with fixes to upgrade the user
Netflix has finally arrived on Linux. Mozillas Firefox browser has received experience.
Netflixs official support to play premium HTML5 content. The LibreELEC 8.0.1 release
While Google Chrome had enabled Netflix video playback support on Linux includes Linux 4.9.13 on generic,
back in 2014, Firefox has become the first Web browser to deliver premium video Raspberry Pi and Raspberry Pi 2
content in HTML5 on the open source operating system. devices. However, on the Amlogic
Starting today, users of Firefox can also enjoy Netflix on Linux. This marks aarch64, the update comes with the
a huge milestone for us and our partners, including Google, Microsoft, Apple and dated Linux 3.14 kernel.
Mozilla, that helped make it possible, the Netflix team, comprising engineers You can download LibreELEC
Nicholas Eddy, Matt Trunnell and Kevin Gallagher, reported in a recent blog post. 8.0.1 directly from the official
In 2013, Netflix added HTML5 support for premium videos to deliver an LibreELEC website. It can be
improved experience over the previously supported Silverlight. It also omitted the installed through an SD card or a
need for plugins to enable video playback. USB drive.

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 9


FOSSBYTES

Our excitement about HTML5 video has remained strong over the past four
years. Plugin-free playback that works seamlessly on all major platforms helps us
deliver compelling experiences no matter how you choose to watch, the Netflix
engineering team reported.
Going forward, Netflix is aiming to enhance video streaming using 4K (Ultra-
HD) resolution as well as HDR support. Hardware such as Netflix-supported
televisions and Google Chromecast are already supporting Dolby Vision and
HDR10 formats. These features are likely to reach Linux systems following their
debut on Windows and Mac machines.
In the meantime, you can start watching Netflix videos on your Linux OS by
installing at least Firefox 47. The update is initially bringing out content in 720p
(HD), though it would be expanded to 1080p at a later stage.

NEC joins FIWARE Foundation to add open source flavour to


smart city systems
NEC Corporation, the company behind major IT-integrating network technologies,
has joined the non-profit FIWARE Foundation as a platinum member. This is to
enable open source technologies for smart city focused systems.
FIWARE works as an open
source middleware platform
designed to promote the cross-
industry use of data and promote
service collaborations among the
companies and municipalities that
provide public services. The solution
was developed under the European
Unions Future Internet Public-
Private Partnership (FI-PPP) project.
It has been adopted by a large number of cities and companies across Europe and
some other parts of the world.
The FIWARE Foundation is a visible commitment of European businesses to
bring more innovative Internet services to consumers, citizens, businesses and the
public sector, said Ulrich Ahle, CEO of the FIWARE Foundation. We welcome
NEC as a platinum member of the FIWARE Foundation, and are looking forward to
writing the future story of FIWARE together with NEC, he added.
NEC will join the board of directors and technical steering committee of the
FIWARE Foundation that serves the community as the decision-making authority
for FIWARE technologies. The NEC team will also contribute to development,
standardisation and promotion of FIWARE technology to accelerate smart city and
smart industry businesses utilising Internet of Things (IoT).
NEC will provide advanced social solutions and contribute to the realisation of a
super smart society (Society 5.0), for which FIWAREs unique capabilities, including
cross-industrial use of data and service collaborations, will play a crucial role, said
Yasunori Mochizuki, senior vice president of IoT strategy, NEC Corporation.
The Germany-headquartered FIWARE Foundation is empowering some of
the leading smart city projects worldwide. There are FIWARE-based solutions in
Santander, Spain, to advance the waste collection management service in the city.
Wellington in New Zealand has also deployed the open source software to forecast
traffic volumes and analyse environmental situations.
NEC is set to leverage FIWARE to develop a model for industrial waste
collection services in Kawasaki City in Japan. This would be the first project on
Japanese soil to use the advanced middleware solution.

10 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


FOSSBYTES

Microsoft brings Black Duck open source tools to Visual Studio


Microsoft is integrating the automated, open source code management program Audacity 2.1.3 comes with
Black Duck Hub with its Visual Studio package. Black Duck (based in new scrubbing features
Massachusetts in the US) has also joined the Microsoft Visual Studio Program as a Audacity, the open source audio
premier level partner. editing software, has been updated to
Black Duck Hub is capable of enhancing the code through software version 2.1.3. The new maintenance
composition capabilities and offers a large amount of data to identify security holes. update comes with scrubbing features
KnowledgeBase, the database behind Black Duck Hub, includes data on more than to ease the editing process.
2 million open source projects and over 79,000 known vulnerabilities. This enables One of the first changes that you
the program to scan your code and look for different security issues. will notice in Audacity 2.1.3 is the
Microsoft recognises the importance of open source in application Scrub Ruler and Scrub Toolbar to
development and the many economic and productivity reasons for its rapidly improve the scrubbing experience.
expanding use. We are pleased that Microsoft also sees value in bringing Black There is also a new generator for
Ducks open source licence and security compliance capabilities to the Microsoft Sample Data Import, and you can
Visual Studio continuous integration platform, said Lou Shipley, CEO, Black create a higher quality audio file
Duck, in a joint statement. using Change Pitch and Change
Black Duck Hub helps you prioritise and track your efforts. Also, the code- Tempo effects.
checking service will be able to guide you on whether the open source code used in The new Audacity version is
your project has any licensing issues. powered by the SBSMS algorithm
The Visual Studio extension of Black Duck Hub scans for open source code that ensures lossless content and
in your TFS (Team Foundation Service) and TS (Team Services) builds. It scans unchanged selection length. There is
the code for security vulnerabilities and other components for licence compliance also an updated click track generator
issues. The tool also allows you to monitor the code written by your employees. that comes with Swing amount
Black Duck and Microsoft are offering Hub support to developers with a 14-day control. In addition to the major new
free trial. A video tutorial has also been produced to ease the integration process. features, the updated Audacity has
If you do not want to analyse your code on Visual Studio, you can use Black Duck included a new timer record function.
Hub on programming tools developed by IT giants like HPE and IBM. However, The software also sends you an alert if
Microsoft has also convinced the Black Duck team to join its Visual Studio Partner your system is low on disk space.
Program to extend the service access for its integrated development environment.

IBM, Red Hat partner to develop open source hybrid cloud


IBM and Red Hat have announced a strategic collaboration to build an open source
hybrid cloud based on OpenStack. The new partnership will persuade enterprise
customers to opt for IBM Private Cloud to install the Red Hat OpenStack Platform
and Red Hat Ceph Storage.
As a result of this move, IBM and Red Hat will jointly market and sell their
cloud deployments. Our collaboration with IBM is aimed at helping enterprise
customers more quickly and easily embrace the hybrid cloud, said Radhesh
Balakrishnan, general manager of OpenStack, Red Hat, in a joint statement. Additionally, Audacity has added
Now, customers who do not have the in-house expertise to manage OpenStack a function that can save you from
infrastructure can more confidently consume Red Hat OpenStack Platform and Red accidentally cancelling a recording.
Hat Ceph Storage on IBM Private Cloud, Balakrishnan added. Through the latest There are also tweaks to help you mix
deal, IBM and Red Hat are set to offer a hybrid cloud infrastructure with OpenStack MP3 files while exporting.
APIs. Both the companies are also set to enable their clients with a workload The Audacity team has developed
migration option directly via Red Hat Cloud Access. some new keyboard shortcuts as well.
The strategic collaboration between IBM and Red Hat is designed to You can easily move to the next or
enable clients to more easily adopt open source products and OpenStack cloud previous label by pressing the Alt +
software while preserving their existing investments and creating new business Right or Alt + Left key combinations.
opportunities, said Zane Adam, vice president for IBM Cloud. IBM has been Similarly, the shortcut for Play/Stop
looking to expand in the cloud space for a long time. The company partnered and Set Cursor has been changed from
with Dell EMC-owned VMware last year, and is already running the VMware Shift + A to just X.
management platform on its cloud.

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 11


FOSSBYTES

Likewise, as open source software is dominating the cloud space, IBM aims
Asttecs launches open to succeed in the market by partnering with its market leaders. Hybrid cloud
source CRM suite application management company, Cloudsoft, is already using the combined service
Months after delivering a community- by deploying its Red Hat Enterprise Linux workloads in IBMs cloud solution. This
backed communication solution, use case is likely to be expanded over time.
Asttecs has launched its open A cloud-first strategy has become the new normal for a majority of our
source CRM application suite. The enterprise clients worldwide who are leveraging IBM Cloud as a key driver for
new development, called AstCRM, digital transformation, Adam said.
is designed to enable enterprises
to manage all their customer Microsofts Project Olympus enlightens open source cloud path
engagement needs using the power of About four months after its official launch, Project Olympus by Microsoft has
open source. finalised its future moves and expanded open source hardware development by
Leveraging expertise in open adding semiconductor manufacturers like
source, our objective is to provide NVIDIA, Intel, Qualcomm, AMD and
customers with best-of-breed Cavium. The new development is aimed at
enterprise-grade applications, while bringing full-fledged cloud hardware closer
focusing mainly on the must-have to the open source community.
features of a customer relationship Microsoft had announced Project
management solution and major Olympus in October last year to deliver a
workflows, said Manjunath R.J., next-generation cloud hardware design, based on the companys massive belief
CEO of AstCRM. in the success of open source. While the initial model is yet to be finalised, the
Asttecs is targeting the CRM Redmond company now plans to make open source cloud hardware a reality.
package at large enterprises and SMEs Microsoft is working closely with the Open Compute Project (OCP) team
(small and medium enterprises). to enable its Project Olympus as an open source cooperative standard for server
The solution can be used to improve hardware that will provide both cloud and enterprise services. At the 2017 OCP US
prospect and customer experiences Summit, the software giant announced that Project Olympus had attracted the latest
by automating sales, marketing in silicon innovation offering an advanced model for emerging cloud workloads
and support tasks, while delivering such as Big Data analytics, machine learning and artificial intelligence.
business-enhancing insights. To reach a large number of projects, Project Olympus standards will be seen
in next generation Intel Zeon and AMD processors. The hardware standard will
also support ARM processors by Qualcomm and Cavium. Interestingly, this
will open up new verticals since ARM-based chips have till now never been
associated with Microsoft software.
This is a significant moment as we usher in a new era of open source
hardware development with the OCP community. We intend Project Olympus to
provide a blueprint for future hardware development and collaboration at cloud
speed, said Kushagra Vaid, general manager for Azure hardware infrastructure,
Microsoft, in a statement.
To accomplish the customer Microsoft aims to build hardware that is robust, flexible as well as scalable in
relationship process, AstCRM terms of capacity. The best part is, this standard is CPU independent. Moreover,
includes major applications for tasks the collaborative agreement between Project Olympus and the chipmakers will
such as lead management, contact ensure this independence.
management, account management, Apart from supporting advanced hardware, Microsoft is projecting a strong
ticket management, role management and quantifiable foundation for cloud software development with Project Olympus.
and activity management. Azure is expected to enable this software foundation through some of the recent
The suite allows users to access open source projects.
customer data via a Web browser. The rapid rate of cloud adoption is already indicative of the fact that the
There are integrated plugins for future of computing is on the cloud. Therefore, a universal standard like Project
Outlook, Thunderbird, Firefox and Olympus is likely to help software makers be less dependent on hardware
Gmail to let users configure the CRM drivers and CPU specifications.
using their email accounts.
For more news, visit www.opensourceforu.com

12 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


new products
Wireless headphones
Price: from Plantronics
` 7,000
Audio communications equipment
manufacturer, Plantronics, has Price:
unveiled its latest over-the-ear ` 13,000
wireless headphones, the Backbeat
Pro 2, which offer good audio
Waterproof quality and some smart features. The months of deep sleep hibernation if

Bluetooth
music pauses automatically once the inadvertently left on.
headphones are removed and resumes The Backbeat Pro 2 comes with
speakers from when they are put on again. additional features like multi-device
Ultimate Ears The headphones come with on- connectivity to connect up to two devices
demand active-noise cancellation, 24- simultaneously and to switch between
Custom in-ear headphones manufacturer hour battery life, along with Plantronics them easily. Built-in dual microphones
and Logitech brand Ultimate Ears has signature audio technologies like rich enable the user to switch into a phone call
launched its latest Bluetooth portable bass, crisp highs and natural mid- while using the headphones.
speaker, the UE Wonderboom. The tones. They are equipped with Class 1 The Plantronics headphones are
device is said to offer 360-degree Bluetooth, which gives an impressive travel-friendly as they are designed with
sound for up to 10 hours on a single 100 metre range when paired with any fold-flat ear-cups and a protective sleeve.
charge. It enables users to enjoy non- Class 1 Bluetooth device. They are available via online retail stores.
stop music and can be fully charged in The headphones smart power
less than three hours. management technologies offer up Address: Plantronics India Pvt Ltd,
Company sources claim that the to 24 hours of non-stop playback 608, 6th Floor, Vipul Square, Sushant
speaker can withstand a drop from on a single charge, up to 21 days Lok, Phase 1, Gurugram 122002;
a height of up to 1.52m (5 feet). It of standby power and up to six Ph: 91-124 4105192/93
features a hanging loop on top, through
which it can be attached to a bag, cycle,
etc. The music can be controlled via Server SSDs from
the speaker itself, which lets the user Kingston
control the volume and skip a song. The
speaker comes with IP67 certification, Kingston, the multinational computer
making it dust- and water-resistant. It technology corporation that develops
can be immersed in up to 1 metre of and manufactures Flash memory Price:
liquid for 30 minutes, making it perfect products and other memory devices, has ` 19,999 for 480GB
for poolsides, beaches or rainy days. unveiled its latest cloud based storage ` 35,000 for 960GB and
Supporting a mobile range of device the DC400 SSD. ` 36,000 for 1.6TB
up to 33 metres, the device can be Ideal for read-intensive applications
paired with approximately eight other such as boot, Web servers and lower data of 400GB, 480GB, 800GB, 960GB,
Bluetooth enabled Wonderboom rate, operational databases and analytics, 1.6TB and 1.8TB. The 400GB, 800GB
speakers, and can be connected to two the DC 400 SSD offers good quality of and 1.6TB capacities are performance
source devices. service for data centre customers. optimised with greater IOPS for faster
The UE Wonderboom speakers are The device features enterprise-class application performance.
available in grey, black, red, blue and reliability with end-to-end data path The SSDs are available online and
pink via online and retail stores. protection and firmware implemented at retail stores.
power-loss-protection (pFAIL). The SSD
Address: Logitech Electronics India is a good front-loading server storage Address: Kingston India, Liaison
Pvt Ltd, 601, Raja House, 30-31, option, being a combination of high Office, 808, Palm Spring Centre,
Nehru Place, New Delhi 110019; IOPS, low latency and advanced data Above Croma, Link Road, Malad West,
Ph: 011- 47306600 protection. It is available in capacities Mumbai 400064; Ph: 91-22-42230300

14 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Dual camera smartphone from Micromax
Indian consumer electronics company, and 128GB of onboard storage, which is
Micromax, has made a strong further expandable via a microSD card. It
comeback with the launch of its latest runs on Micromaxs Qiku 360 interface
smartphone, the Dual 5, which sports with Android 6.0 Marshmallow.
a dual camera on the rear. The device Powered by a 3,200mAh battery,
sports twin 13 megapixel sensors on the smartphone comes with Quick
the rear, both with an f/1.8 aperture. Charge 3.0 which can charge the
One sensor captures in monochrome phone to full capacity in just 45
and the other in colour. Apart from minutes. The connectivity options of
this, there is the 13 megapixel front the device include 4G VOLTE, Wi-Fi
camera for selfies. 802.11ac, Bluetooth v4.1, a 3.5mm
Apart from its imaging audio jack and USB Type-C along
capabilities, the flagship device Price: with sensors like an accelerometer,
features a 13.9cm (5.5 inch) full ` 24,999 an ambient light sensor, a gyroscope,
HD super AMOLED display with infrared sensor, etc.
2.5D Corning Gorilla Glass 3 for The Micromax Dual 5 is available
protection. A fingerprint sensor on edges, which gives the phone a via online and retail stores.
the rear panel recognises fingerprints premium look.
within 0.2 seconds, according to The Dual 5 is powered with an Address: Micromax House, 90 B,
company sources. It sports an all- octa-core Qualcomm Snapdragon 652 Sector 18, Gurugram 122015; Ph:
metal unibody design with chamfered processor, coupled with 4GB of RAM 91-124-4811000

Karbonns pocket-friendly
4G smartphones
Mobile device manufacturer, Karbonn Sleek comes with a 5 megapixel rear
Mobiles, has introduced two new 4G and 2 megapixel front camera.
enabled smartphones the Karbonn The Karbonn Aura Note 4G is the
Aura Sleek 4G and Aura Note 4G, first fingerprint sensor device from the
both offering the latest features at an company. It comes with a 13.9cm (5.5
affordable price, making them quite inch) HD screen, 720x1280 display and
popular among the youth. IPS full lamination. With a 1.25GHz
The Aura Sleek 4G comes with quad core processor, the device is
a 12.7cm (5 inch) FWVGA IPS full backed with a huge 2800mAh battery, a
lamination display, perfect for video flashlight, 2GB RAM and 16GB ROM.
Price:
streaming and games. It is powered It runs on Android 6.0 Marshmallow
by a 1.1GHz quad-core processor and has an SD card port with memory ` 5,290 for Aura
with an internal memory of 1GB expandable up to 32GB. It offers front Sleek and ` 6,890
RAM and 8GB ROM. Backed and rear 5 megapixel cameras. for Aura Note
with a 2000mAh battery, the device The Aura Sleek is available in
runs on Android 6.0 Marshmallow, champagne white, black and grey, while Address: Karbonn Mobiles Pvt Ltd,
comes with a microSD card port the Aura Note 4G is available in premium D-170, Okhla Industrial Area, Phase 1,
and supports up to 32GB of external finishes of matte black and metallic New Delhi-110020;
memory. As for the camera, the Aura champagne via online and retail stores. Website: support@jainaindia.com
The prices, features and specifications are based on information provided to us, or as available on various
websites and portals. OSFY cannot vouch for their accuracy. Compiled by: Aashima Sharma

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 15


CODE
SPORT
In this months column, we continue our discussion on deep learning.
Sandya Mannarswamy

W
hile we have been discussing deep 4. Regularisation techniques are widely used
learning in the last few columns, a few to avoid over-fitting of the neural network
readers asked me to share interview parameters to training data so that the
questions on this topic as well as on general machine constructed network can still generalise well for
learning. So, in this months column, we focus on unseen test data. Can you explain the differences
some of the common interview questions, and I between L1 regularisation and L2 regularisation
request readers to send me your email replies to these methods? When would you use the first option
questions. I will feature them in our next column instead of the second? If you change the network
when we discuss the answers to these questions. learning rate, does it impact the choice of your
1. In last months column, we had discussed regularisation parameter lambda?
auto encoders and how they can be used for 5. You have been given a neural network and
dimensionality reduction. I had mentioned that it training data of size N. How would you
is possible to achieve a dimensionality reduction determine whether the constructed network
of the input representation by having a hidden suffers from the problem of over-fitting?
layer of smaller dimensions compared to the input 6. One of the several other techniques used to avoid
representation dimensions. Now the question to over-fitting is employing drop-out while training a
our readers is the following: Is it always necessary neural network. In simple terms, drop-out implies
to have a hidden layer of smaller dimensions in having a percentage of neurons inactive while
an auto-encoder? If you build an auto-encoder training the network for a fixed number of mini-
in which you have the hidden layer whose epochs and then repeating this process a number
dimensions are larger than the input layer, can you of times, having a different set of neurons inactive
justify why you chose to do so? each time. After completing training, the learnt
2. Continuing on the subject of auto-encoders, why do weights of the neurons are scaled down. Can you
we really need them for dimensionality reduction? explain why this is needed? Also, can you explain
Most of you would be familiar with dimensionality the intuition behind drop-out in terms of why it
reduction techniques such as Principal Components can help avoid over-fitting?
Analysis (PCA). What is the advantage of using 7. One way of thinking about the drop-out technique
auto-encoders for dimensionality reduction of data is that by having a certain percentage of neurons
compared to a PCA based approach? (Clue: Think inactive for each learning phase, we actually train
of linear vs non-linear.) a different neural network and then combine these
3. Given that deep neural networks need large different networks to obtain the final network.
amounts of training data to generalise well, Can you think of any other technique in machine
can you explain methods by which you can learning whereby you can combine different weak
artificially increase the size of your training data? learners to build a strong learner?
(Clue: Think of transformations such as scaling, 8. Different activation functions can be employed
rotation and translation. While it may be obvious for the neurons such as rectilinear, tan-h,
in the case of image data sets to employ these sigmoid, etc. Can you explain the factors
transformations to increase the size of training involved in the choice of activation functions?
data, what kind of transformations can you Are there any criteria that a function needs to
employ in the case of text data?) satisfy, for it to be considered as an activation

16 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Guest Column CodeSport

function in a neural network trained using back of these hyper-parameters and how they impact the
propagation? classification test accuracy? How would you choose the
9. In a neural network built for classification problems, appropriate values for the hyper-parameters?
the output layer typically has neurons whose activation One of the best resources for learning about the
function is a softmax activation function. Can you explain basic concepts of neural networks is the free online book
why you should use a softmax function for the output layer from Michael Nielsen available at http://neuralnetwork
of a classification network? (Clue: Think about how the sanddeeplearning.com/index.html. I would suggest that our
softmax function is defined and how it can be interpreted readers go through this short book before they attempt to read
as a probability.) through the voluminous deep learning text book from Prof.
10. The back-propagation algorithm is the anchor behind the Bengio et al, available at http://www.deeplearningbook.org/. I
ability to train very large and deep neural networks. Can like Nielsens book, especially because he has provided short
you explain the intuition behind the back-propagation Python code snippets for different concepts and you can try
algorithm? Instead of using back-propagation, I design a them out quickly as you read through the chapters. Another
method wherein I disturb the weight of one of the arbitrary great resource to get familiar with deep learning concepts
neurons in the network and measure its impact on the cost is the repository of articles and tutorials available at https://
function, to determine the gradient of the cost function with deeplearning4j.org/tutorials.
respect to that weight. While this approach certainly seems Given the enormous number of papers and articles
simple compared to the complicated back-propagation available in this space, it can be very confusing for a novice
algorithm, explain why this is not a scalable approach? computer science student who wants to gain expertise in
11. Recall the fact that back-propagation is built on the deep learning. While there are online courses available
premise of computing the gradient of the cost function with from Coursera (Prof. Hintons course on neural networks)
respect to each of the weights, and using the computed and Udacity (a deep learning nano-degree), I would suggest
gradient to update the weights for the next pass. What are that you also read through one of the above-mentioned
the criteria a reasonable cost function needs to satisfy for text books in order to get the mathematical concepts clear,
back-propagation to be applied? instead of just viewing neural networks as a black-box
12. Different cost functions can be applied for a neural network machine learning algorithm. This would allow you to
such as the quadratic cost function, the cross entropy cost understand and appreciate the application of different neural
function, etc. Can you explain why you may prefer a cross- networks to different problems. For instance, you may want
entropy cost function over a quadratic cost function? (Clue: to dig deeper into why convolutional networks, which were
Think of the slowdown in learning for a quadratic cost originally envisaged for image recognition, are also useful
function when a neuron is near saturation.) in text processing tasks such as sentence classification or
13. Continuing the question of cost functions, very often people document classification. More importantly, as you use some
use a sigmoid activation function for the output layer along of the standard neural net architectures for specific text
with a cross-entropy cost function; or a softmax output layer processing problems such as sentiment analysis or topic
with log likelihood cost function. Can you use a softmax modelling, you will understand how different architectures
layer with the cross-entropy cost function? Explain the need to be tuned for different tasks. We will discuss more
reasons behind your choice. (Clue: Think of interpreting the about this in our next column.
softmax layer output as a probability distribution.) If you have any favourite programming questions/
14. How can you compare the performance of two different software topics that you would like to discuss on this forum,
machine learning algorithms? For example, consider that please send them to me, along with your solutions and
you have been given two learners one based on support feedback, at sandyasm_AT_yahoo_DOT_com. Till we meet
vector machines and another that uses neural networks for again next month, wishing all our readers a wonderful and
classifying documents. Let us also assume that the SVM productive month ahead!
based learner performs better than the neural network based
learner when the training data size is M, whereas the neural
By: Sandya Mannarswamy
network performs better than SVM when the training data
The author is an expert in systems software and is currently
size is much less than M, but is poorer in performance by working as a research scientist at Xerox India Research
a few points when comparing training data sizes of M and Centre. Her interests include compilers, programming
above. Which training algorithm would you prefer in that languages, file systems and natural language processing.
If you are preparing for systems software interviews, you
case, and can you explain the rationale behind your choice?
may find it useful to visit Sandyas LinkedIn group Computer
15. When we discussed neural networks in our previous Science Interview Training India at http://www.linkedin.com/
column, I did not go into much detail about the hyper- groups?home=HYPERLINK http://www.linkedin.com/group
parameters of the learning framework such as the learning s?home=&gid=2339182&HYPERLINK http://www.linkedin.
com/groups?home=&gid=2339182gid=2339182
rate, number of mini-epochs, etc. Can you explain some

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 17


Exploring Software Guest Column

Diaspora: The Free,


Distributed Social Network
Anil Seth

This month, the author explores Diaspora software, which


is free and can be used to set up non-profit distributed
social networks. A group of independently owned nodes can
interoperate to form a network.

D
iaspora (wiki.diasporafoundation.org) is a Ruby on BalancerMember unix:///home/diaspora/diaspora/tmp/
Rails application for social networking, designed diaspora.sock|http://
to run as a federated system. Each Diaspora server </Proxy>
is called a pod, and you can join one of the public pods. # SSLEngine On
There are a few with the in domain as well. You can select SSLCertificateFile /etc/pki/tls/certs/localhost.crt
a pod using the guidelines on the Diaspora wiki or use the SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
site https://podupti.me/. SSLCertificateKeyFile /etc/pki/tls/certs/localhost.key
In this article, we will explore how to set up a personal
pod. This may be useful in an organisation or a group, as it Once the installation is successful, you can start the
can encourage sharing and networking between colleagues. browser and explore further.
An additional advantage is that, as it is open source, code
can be added to make it more useful for any special needs Usage
of the common interest group. Sharing concepts are very similar to how it is done on G+
(Google Plus). Relationships are asymmetric. You create
Installation aspects, which are identical to circles in G+. You add
The installation of Diaspora is complex but not very people you know to one or more aspects. They will be
difficult. Instructions are available on the wiki for various notified that you are sharing posts with them. However, it
Linux distributions as well as for MacOS and for Windows. is up to them to decide whether to include you in an aspect
The instructions for Fedora 22 are fine for Fedora 25 as or not. If they dont, the posts you share with them will not
well, with some minor differences. show up in their stream.
The following line created a little confusion: You can share your posts with one or more aspects, or
the public. However, your post will go to a users stream,
curl -L https://s.diaspora.software/1t | bash provided this user is following you. This means that you
need to be one of this users aspects.
I misread 1 in 1t as the letter L and not the Re-sharing of posts is tighter. Only public posts can be
number 1! re-shared. You need to keep in mind that someone may re-
For testing, you can use a dummy URL and self-signed share your private post by using copy-paste.
certificates. However, for production, you will need valid In addition to seeing posts from people you follow, you
certificates and a valid domain. The dummy URL should be may also view posts based on your interests. This is similar
in the /etc/hosts file so that the browser can find it. to the micro-blogging sites. You can specify your interests
The configuration files are in .yml and, hence, by selecting a list of hashtags. A public post that contains
indentation is as critical as in Python code. one of the hashtags in your list of interests will also be
To get the Apache reverse proxy to work, you need shown on your stream.
to make sure that mod_ssl is installed. Modification
of the sample configuration file for Apache is fairly Networking
straightforward. You need to take care of the file names, Diaspora pods do not synchronise, which is fine. There is
e.g., for the proxy and SSL settings, as follows: no reason for a pod to keep track of all the traffic. If a user
on one pod is following a user on another pod, then the
<Proxy balancer://upstream> relevant posts will be forwarded. However, if the receiving

18 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Admin Overview Guest Column Exploring Software

5. Audit logging Zabbix can easily be run on a number of operating


6. Easy configuration systems like:
7. Agent-less monitoring Linux
8. Web interface IBM AIX
pod is not operational for an extended period, these posts as the List of social networking websites on Wikipedia
9. Extensive visualisation options FreeBSD
may not be delivered. illustrates. Other social networks may be small but can still
10. JMX monitoring NetBSD
You will see the public posts related to hashtags from serve a significant social need.
OpenBSD
your own pod. In addition, your pod can be configured to If pods are hosted by common interest groups but are
Configuring Zabbix
receive public posts from a relay server. The scope can be
Mac OS
still part of a federated environment, it would make it
There are primarily four ways of getting Zabbix on your Solaris
for all the posts or just for a list of hashtags. The pod may easy for people to join and find others whom they wish to
system: Windows
also opt to send public posts to a relay server. The default share their interests with. Since advertising revenue is not
1. Installing it from distribution packages.
options are false. at stake, the numbers do not need to be absurdly huge in
2. Downloading the latest source archive and compiling it Zabbix version releases
order to be successful.
yourself. The first public version of Zabbix was released in 2001 and
Alternatives Diaspora and Facebook were created by college
3. Installing it from the containers. was called Zabbix 1.0alpha1. But the first stable version 1.0
The primary open source alternative to Diaspora is students! So, colleges seem to be the ideal places to set up
4. Downloading the virtual appliance. was released in 2004. After this, a new stable release came out
Friendica. It is written using the LAMP stack and has federated servers and change the world.
every one-and-a-half years. The latest Zabbix 3.2.3 version was
built-in support for the Diaspora protocol. Hence, users
Requirements
on Friendica and Diaspora can share messages with
released on December 21, 2016. The release date of various
Memory: Zabbix requires both physical and disk memory. A versions can be obtained from the Zabbix website.
each other. The site https://the-federation.info/ gives By: Dr Anil Seth
minimum of 128MB of physical memory and 256MB of disk
information about the servers running the Diaspora By: Neetesh Mehrotra
memory are required to start it. The author has earned the right to do what interests him. You
protocol. Another interesting project supporting the The
CPU: Zabbix, especially the database, may require can author is online
find him employed at TCS as a systemshttp://sethanil.
at http://sethanil.com, engineer. He is
Diaspora protocol is Hubzilla. interested in Java
significant CPU resources depending on the number of blogspot.com, anddevelopment
reach him viaand automation
email testing. He
at anil@sethanil.com.
Is there any hope for the alternatives? Probably yes, can be contacted at mehrotra.neetesh@gmail.com.
monitored parameters and the chosen database engine.

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 19


88 | MARCH 2017 | OPEN SOURCE FOR YOU | www.OpenSourceForU.com
For U & Me Interview

I built C++
primarily for myself and
my colleagues
When we think about programming, its C++ that first comes to mind. Thats because of
the immense popularity and broad applicability of the general-purpose programming
language that debuted back in 1983. Since then, it has influenced many modern
languages, including C#, D and even Java. But what makes C++ important in the world
of generation-next computers and devices like smartphones and embedded hardware?
Jagmeet Singh of OSFY tries to get the answer to this question in a conversation
with none other than the creator of C++, Bjarne Stroustrup. Edited excerpts...

Q What prompted you to


develop C++?
I needed a language that could be
and my colleagues. However, the
range of projects, the demands and the
hardware at Bell Labs were very wide,
Once the language was ready,
its installation and portability on a
variety of hardware and operating
used to manipulate hardware directly so the language had to be very flexible systems was quite tough. Similarly,
and use all the available hardware to cope with all of that. educating people on how to use the
resources well. I also needed a new techniques and language features
language that allowed me to handle
complexity. Though C could be used
in manipulating hardware and Simula
Q What were the prime
challenges you faced when
building C++?
was also a big challenge.
It was not all that easy because for
the first years I was the only person
could handle complexity, there wasnt a There were many challenges because working on C with Classes. My
language that could do both. Therefore, I was building a tool for practical use, colleagues were most supportive, but
I started to build one, by adding rather than as an academic project there was no official C++ project with a
Simulas class ideas to C. for publication. A tool has to be good budget; basically, the help I offered to a
enough for everything its users need; range of Bell Labs projects allowed me

Q For whom did you build the


initial C++ model?
just being the best in the world for
one or two things is not sufficient
to develop C++.

I wanted that language for myself, to


help build a distributed system based
on UNIX. Before I even finished my
for success.
The very first challenge that I
faced was the languages design. The
Q Why was there a need for
C++ when C already existed
in the computing world?
language, my friends and colleagues question that arose was what features I built C++ on C because I did not
at Bell Labs started to use it for their do my colleagues and I need in order to want to build from scratch. That
projects, often simulation projects simplify our code. Implementing those would not have resulted in a useful
because the very first library I built features so that they were affordable tool within a reasonable time frame.
for C with Classes (as I called my to use in real-world development and However, C could not, and still cannot,
language) was a co-routine library. execution environments was also quite manage complexity as well as C++.
I built C++ primarily for myself hard, initially. The C language, and how it is used,

20 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Interview For U & Me

has evolved over the years -- often


under the influence of C++. When
I started with C with Classes, the
Q How has C++ evolved in the
programming space?
For the first 10 years or so, the user
computation and graphics to the
list of use cases.

use of sets of functions as opaque


interfaces (which today is Cs most
effective abstraction mechanism) was
population of C++ doubled every 7.5
months. Currently, there are about 4.5
million users of C++, and that number is
Q Is it the open source practice
that led to the early success
for programming languages such
not common. It has been conjectured growing by about 100,000 a year. as C and C++?
that this developed partly in response Moreover, C++ is used all over No. The early success of C and C++
to the classes and virtual functions of the world, and heavily in finance, predates the emergence of open source.
C++. K&R C did not offer function banking, games, front offices, telecom, However, AT&T did the next best thing
prototypes, //, const, inline and more; electronics, marketing, manufacturing and allowed the use of C and C++
those came from my work with and retail. From my own experience, I compilers and libraries for a very low
C++. Even GCC (GNU Compiler can add embedded systems, scientific price. For non-profit organisations,
Collection) that was first released in
1987 is a C++ program now.

Bjarne Stroustrup,
creator of C++
For U & Me Interview

C++ cost US$ 75, which was the price


of the magnetic tape on which it was
shipped (source and binary); organised
Further, C++ is one of the few
languages that allow you to use a wide
range of fundamental programming
Q How important, do you
think, is readability in a
programming language?
distribution over the Internet was still in techniques. It also allows you to work in Readability is essential. If you cannot
the future, back then. Soon, AT&T gave most industries. read the code, you cannot maintain it
the specifications of C and C++ to the and cannot discuss or argue about how
ISO so everyone could use them, and I
personally helped other organisations
with getting C++ compilers written.
Q There are different compilers
available for C++. Which one
is the best, in your view, and why?
correct it is. Todays C++ is so much
more readable than older C++ or C.
I am working on an ambitious
Nowadays, there are, of course, I do not have a favourite compiler for project to define what modern C++
open source and proprietary C++ C++. I use several. The major C++ code -- using C++11, C++14, C++17
implementations. To ensure the wide compilers are all good. They have and beyond should look like. It is
reach of my work, I deliberately (with good standard conformance, generate called the Core Guidelines, and is an
the agreement of AT&T) refrained from good code and have good supporting open source project with editors from
patenting anything related to C++. toolsets and fundamental libraries. Morgan Stanley, Microsoft, Red Hat
You can choose a C++ compiler based and Facebook.

Q Do you see any programming


languages today that can
replace C++? Or can we call it
on specific needs such as the ability
to use specific hardware or specific
programming techniques, specific
We are aiming for completely
type-safe and resource-safe code,
without limitations on expressibility
irreplaceable? environments, portability or a certain or performance. Code conforming
I do not see a current language that could toolset like GDB or Visual Studio. to the Core Guidelines is far more
replace C++ across its range of uses. regular and readable than most current
Its combination of hardware access and code. Moreover, we are working on
zero-overhead abstraction is still unique. tools for the automatic enforcement
However, nothing lasts forever. of these guidelines.
Eventually, a current language will
acquire sufficient facilities or a new
language will come along. C++ has
certainly been at the top of the game
Q Do you see any big
difference between
computer systems and
for almost 30 years. That is not bad, embedded devices that are
especially given that C++ never had a designed for the Internet of
powerful owner or a marketing budget.
Q Unlike Python and Java,
C++ has not yet become the
Things (IoT) ecosystem?
There are differences such as

Q What are the major features


that make C++ an easier
option compared to C?
perfect choice for embedded
engineers. Do you think the focus
should now also be on connected
application binary interfaces (ABIs) and
security concerns, but the fundamental
programming needs and constraints are
C++ offers you a better type system, devices? the same, and I think they favour C++.
classes with constructors and Python and Java are not perfect
destructors, overloading, native support
for object-oriented programming,
support for generic programming as
choices for embedded systems either.
C++ is critical when you need to
squeeze performance or energy
Q How do you plan the
revisions of C++ standards?
We just moved C++17 out of a national
well as compile-time programming. efficiency (say, enhancing battery vote. It will be the ISO C++ standard later
life) out of a gadget, but no one this year. C++20 will be the standard

Q Why do aspiring developers


need to learn C++ to
survive in the growing world of
language is the best for everything
and everybody. There is a lot of C++
embedded system code. It is worth
after that in 2020. For C++20, we will
code for concepts, modules and possibly
contracts and co-routines. It could be
computers? remembering that embedded systems an exciting major revision and change
I do not know if they need to learn include a vast range of things from the way we program, but all of this will
C++, but they should want to. It is one coffee machines to jet plane flight depend on the standards committees
of the most widely used languages and controls, from fuel injectors to stereo willingness to accept change.
among the most flexible. It is also one amplifiers, and from lithium ion battery Concepts are shipping in GCC, while
of the languages that delivers the best controllers to self-driving cars. There modules are shipping in Microsoft and
performance, is very popular and allows is a corresponding range of needs for co-routines are available in Microsoft
you direct access to hardware resources. programming techniques and tools. and Clang. More implementations are

22 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Interview For U & Me
efy dvd
in the works, so my dreams have some code, by which I mean code that more everything just does not work. It is
that accuracy
concrete is compromised. If
foundation. directly expresses its intent and runs not feasible for large code bases and
the Itreactive component is used
is extremely difficult for in
a group faster using fewer resources. inefficient for small ones.
a high-frequency circuit, be aware
of 200 to make plans and stick to them. So, look for good code navigation

Q
of the period length while handling
Some of us in the committee try, though. Spending hours on the code tools like IDEs and, of course, hope for
this value. In general, circuit simu-
is not an easy task for young helpful colleagues who will spend time
lation speed is measured in steps
Q What are all the scheduled
per second.
features in the C++17
standarddown
that will
programmers. What valuable tips
can they get from you that will
introducing you to the code base and
its associated tools (debuggers, build
Getting to advance
actual help them work comfortably on systems and test suites).
the present programming
simulation new projects? If you want to use C++, take care to
experience? The code is where ideas turn into learn it well. In particular, learn to use
Simulating with SimulIDE is easy
Compared to C++11 and C++14, practical results. We cannot just write modern C++ well. Do not just repeat the
a power button is your control key.
C++17 does not offer anything that papers or manuals. In fact, we must errors of the past. You can write so much
Simply click on it and you will
will fundamentally change the way you produce code that actually works. better C++11 than you could write in the
see the circuit getting into action.
program. It does not change the way Before adding to a code base, you styles of the 1990s.
Observe the outputs you defined
you think about constructing a program. have to understand some of it. You can
to learn how the changes you Fig. 4: Working with Arduino Uno
Thus, by
made
minor
to my
new results.
littleOn
theusual
update. It
forinstalling
everybody.
definition,
schematic
does, however,
it is a in
resulted

Importantly,
offer a
most
get a general understanding of some
code
so
a
ontop-down,
change
but toJust
are provided.
(such as to
be able
fix a bug)
to make
import the
yousee
Q
near
Finally, where do you see the
with programming
other examples.world
future?
May in
be the
you
SimulIDE package, files into the tool and you will could try your hand at some new
an exclusive folder is created. Thisin
C++17 features are already shipping needsimulation
the to understand
for the code inside-out,
yourself. Hopefully,
fun game. it will be easier to read, write
the major
should beimplementations; I suspect
used as your workspace particularly what affects
Being a hobbyist-oriented this line tool,
of and maintain code. I do not want to
these implementations will
for all further designs with this all be tool. code and in turn, what this
users of SimulIDE have developed line of code write science fiction, so I will not go into
feature-complete before 2017 is out. affects? Anything that helps read the Priya Ravindran
details. is M.Sc
But I expect that (electronics) from
C++ and I will
The folder also contains an exclu- many games like the once-popular VIT University, Vellore, Tamil Nadu. She loves
siveWhat matters
folder, with the new
for example, where features
files code and
Snake navigate
and Flappythrough it, helps.
Bird, samples make a significant positive contribution
to explore new avenues and is passionate
is how
for they can
designs likebe used to DACs
op-amp, write better
and Linear
of which reading or trying
are also to understand
provided along to thatwriting
about future.

Would You
Like More
DIY Circuits?

www.efymag.com electronics for you Plus | aPril 2017 iii


www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 23
Admin Overview

Handling Large Files


Using Open Source Tools
Handling large log files is problematic. Systems administrators must be able to open them to
view and act upon the vital information they contain. Text editors are the best option for this
task. Here is a review of a selection of these editors for our readers.

I n almost every project we work on, we need to deal with


files. Consider the following scenarios:
As a systems administrator, you need to deal with large
some specific application, a text file is created by the user
in a word processor, and a data file stores data pertaining
to a specific application for later use. Data files can be
system log files every day (in gigabytes), which are very stored as text files or as binary files, and are particularly
difficult to handle. helpful when debugging a program.
As a developer, you may have to deal with huge
application log files or application source code files. The need to handle large files carefully
As a tester, you may have to deal with the large-sized data The files generated in the situations mentioned earlier
files generated as the output of some process, and need to could be of any size, format or encoding. Besides, they
validate a particular attribute present in those files. may or may not contain the text in specific formats, such as
There may be various other scenarios as well but, comma-separated values (CSV), log data files (LDF) and
generally, all these data and log files are text files. The master data files (MDF). These large text files may also vary
difference between a log file, a text file and a data file is with respect to the lines they have or the reason they need
that a log file is generated automatically to keep track of to be opened for. For example, the event log files for some

24 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Overview Admin

Notepad

The C:\User\Abder-Rahman\Desktop\hg38.txt file is too large for


Notepad.

User another editor to edit the file.

OK

Figure 1: Error with Notepad for a file size greater than 1GB
(Image source: www.google.com)
Figure 2: Notepad++ text editor logo (Image source: www.google.com)
common applications that generate a large amount of data
could be more than 1GB in size and we may need to read Has the multi-document and multi-view feature.
them. As the file size increases, handling them becomes Regular expression and the multiple file search, mark and
a tedious task. Generally, we come across the following replace feature is supported.
issues while attempting to handle large files: Full drag-and-drop support.
The system may hang while attempting to open large Support for a multi-language environment support.
(GB) log files. Being built for the Windows platform, it can also run on
The system will slow down due to full RAM usage by the Linux, UNIX and Mac OS X (using Wine).
opened large text file while the editor is in use. Macro recording and playback.
While attempting to open some 1GB sized text files, the Zooming for those afflicted with sore eyes from staring at
built-in text editor of the Windows application, Notepad, computer screens.
can show some serious error messages like The file is too Comes in both installer and zipped versions for people
large for Notepad. In such cases, we need to use another who don't have admin rights on their work computers.
editor to edit the file.
To interpret the information of these files carefully Disadvantages
without facing such issues, we need some good editors that Third party program (Wine) needed to run the application
allow us to open, read and edit the files. So lets discuss some on Mac OS X.
basic editor tools, which could be handy for these tasks. Remote file editing does not support HTTP, SSH or
WebDAV.
Open source tools to handle large files
Glogg
Notepad++ Glogg is a multi-platform, open source GUI application
Notepad++ is an advanced and feature-rich sibling of the tool for viewing and searching large, complex log and
Notepad text editor that you find in the Windows OS. It is data files. It is a very quick tool as it reads data directly
for those who want a very simple and easy UI with a great from disk and does not load it entirely into memory, which
feature set, as it is clean, very fast and an excellent way to
get work done. It is a lightweight replacement for Notepad,
and is better than Microsoft Notepad in every possible way.
It supports multiple tabs to open different files in a single
window. It also supports multiple programming languages.
Some of the languages supported by Notepad++ are C, C++,
Java, C#, XML, HTML, PHP, JavaScript, VB/VBS, SQL,
Perl, Python, UNIX shell script, etc.
Notepad++ is commonly known as the best HTML editor.
It supports coloured lines and reports code error at the same
instant. Besides, its functionality can be extended by using
the hundreds of available plugins.
Key features
WYSIWYG (What You See Is What You Get).
User defined syntax highlighting and auto-completion. Figure 3: Log file opened with Glogg (Image source: www.google.com)

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 25


Admin Overview

enables it to open very large files for viewing. Glogg is a


read-only editor and does not come with a lot of features.
However, it is very useful in the overall handling of large
files. It can be interpreted as a graphical combination of
Grep with fewer commands.

Key features
It is very quick while handling large files as it directly
reads from the disk without loading into memory.
Runs on UNIX-like systems, Windows and Mac (using
the Qt software development framework).
It automatically updates the log with auto-refresh features
in real-time.
Lines in a file can be marked while reading and they can
be combined later.
It supports keyboard commands like vim/less to move
around the file. Figure 5: Tool options with ConTEXT editor (Image source: www.google.com)

Disadvantages configuration files.


You cant edit files as it is a read-only text editor. It has a good ability to work with files on a remote server
Download link: http://glogg.bonnefon.org/download.html using a terminal over SSH.
Vim is open source and free to use.
Vim Its core functionalities can be extended using various
VI (Visual Interactive) is one of the main editors for UNIX plugins with support for Vim.
systems and Vim is a multi-platform clone of this text editor.
It has been written by the Disadvantages
Dutch programmer, Bram Vim is generally for advanced users. It is not easy to
Moolenaar, who is an active master it quickly but, once done, it provides you with the
member of the open source power that no other text editor can give you.
software community. Vim
stands for Vi Improved. It is ConTEXT
considered one of the most ConTEXT is a small, fast and very useful open source text
popular text editors among editor for Microsoft Windows. It has been developed to serve
developers and is perfectly as a powerful tool for software developers.
customisable. It is famous
for two reasons. First, it Key features
Figure 4: Vim text editor logo (Image supports complete keyboard It is very good at handling large files.
source: www.google.com) operations without any need It has powerful syntax highlighting for multiple languages
for the mouse and, second, like C#, C/C++, Java, etc.
Vim is present in almost every UNIX-based machine. It is a It can open multiple files at once.
free text editor, which needs a terminal shell environment, and It supports more than 20 languages like English,
it is also available as GVim, which is Vim with a built-in GUI. Spanish, French, etc.
For new users, it is sometimes hard to interact with Vim We can compare multiple files in it.
because this editor does not prompt the user for the next Search and replace with regular expressions.
instructions. To learn the basic commands through gaming, It has user definable execution keys, depending on
you can refer to http://vim-adventures.com/. the file type.
Powerful command line handler.
Key features Customisable with syntax highlighter colours, cursors,
It supports keyboard based operations fully. margins, gutter, line spacing, etc.
Its performance with handling large files is very good. Search and replace text in all open files at one go.
Portability and ubiquity is a key feature of Vim. Download link: http://www.contexteditor.org/downloads/
Vim is customisable. You can Google for .vimrc, dotfile Source code repository path: https://code.google.com/
and VimScript to find examples of preconfigured Vim archive/p/contexteditor/

26 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Overview Admin

Do-it-yourself

Figure 6: EditPad is very good with regular expressions

EditPad Lite
EditPad Lite is a general-purpose text editor. It can
be used to easily edit any kind of plain text file. It
displays content instantly because it uses pointers to
access the file directly, rather than to read the entire
file into memory at once. EditPad Lite has all the
essential features to make text editing easy.

Key features
Fig.Full Unicode
7: Start support,
Simulation windowincluding complex scripts
and right-to-left scripts.
It does editing of files directly in Windows,
UNIX and Mac with text encoding (code pages)
and line breaks.
Working with multiple files is very easy using
the tabbed interface.
You can undo and redo all open files infinitely,
even after you save the file.
It supports large files and long lines very well.
It prevents any data loss by automatic backup and
Fig. 8: sim-Default window
saves working copies of files.
Its powerful search-and-replace option with
literal search terms is a worthy feature.
Regular expressions that can span multiple lines.

Disadvantages
It supports Windows only.
It is only free for personal use.

EmEditor
This is a powerful editor with some very great features
like
Fig.Unicode
9: Adding support and
wave to the coloured syntax highlighting.
project
It supports multi-platform files, and many files can
be sumptions into consideration
opened concurrently. for easing
It uses an effective the operations
approach
to read large files as it spills the content onto the disk pin
of the circuit. While data input pin and address
may have any value depending on the specifications of
memory used and your need, clock used in the circuit
is active high.
Enable pin triggers the circuit when it is active
high, and read operation is performed when read/
write pin is high, while write operation is performed www.lulu.com
when read/write pin is active low. www.magzter.com
Software Createspace.com
Verilog has been used for register-transfer logic cod- www.readwhere.com
Figure
ing7: and
EmEditor tool logo (Image
verification. Thesource: www.google.com)
bottom-up design has been

www.EFYmAg.com ElEctronics For You | April 2017 113


www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 27
Admin Overview

rather than loading it to memory. This helps it to open very supports C++, HTML, CSS, and JavaScript.
large files with ease. One major feature of EmEditor is that Visual Studio Code: This is another free text editor
it auto-detects if the CSV file has an uneven number of created by Microsoft under the MIT licence.
columns, and it tries to fix it at the same time. Its large file GNU Emacs: This is a very popular text editor
controller helps it to read large files at once. derivative of the Emacs family, created by Richard
Stallman for the GNU projects.
Key features
Easily handles files up to 248 GB. Tips to handle large files
It can split large files and can also Do not close large files immediately after viewing
combine files into one. them. You will be dealing with a lot of information
Syntax highlighting and regular expressions are some and you wouldnt want to close a file only to realise
of its main coding features. that you need it open again. And besides, large files
Customisable interface and quick launch makes the take time to open but, after that, its all fine.
user experience better. It is good to have complete documentation of all the
Various free plugins make this tool more productive. findings of large log files, as we may forget these later
Powerful and scriptable macros. when we need to use them and end up wasting time in
The word count plug-in allows you to count reopening the same large file.
specific terms or characters. It is a good practice to keep your RAM as free as
Split window (up to four panes). possible as most text editors load the files into the
Has the auto-save and auto-indent features. RAM to read them.
Support for external tools includes launching external More than a text editor, it's a RAM issue. If you want
programs via keyboard shortcuts or toolbar buttons. to edit a 5GB file and you do not have enough free
RAM, then you will have to close any other open
Disadvantages application to handle the opening of the large file,
Some of its features are available only on the pro carefully.
edition, which is not free. Instead of using a text editor tool, you may go ahead
with the good old Grep command, or you could use
LogExpert the split function to split the large file into multiple
This is a Windows tail program, which serves as a GUI files of smaller sizes, which are easy to handle.
replacement for the UNIX tail command. It is very good You can use cmd to open large files in Windows.
at reading large files, and is free for commercial as well as First, open cmd with Start>Run. Navigate to your file
non-commercial use. location and then type the following command:

Key features type <filename.extension> | more


It has a plugin API for log file data sources.
It supports the tail program and Unicode. Now the cmd window will show you a screen with
Multiple plugin support is available from third party. the contents of the file. This happens quickly for large
MDI-interface with tabs. files also, without any time lag. You can copy the
It has a search function including regular expressions. details from there as well.
We can bookmark the search result and can add
comments to bookmarks.
Any change in the log file automatically gets
updated in the same log file that is being used by the
References
LogExpert too. [1] https://en.wikipedia.org/wiki/
It has a very flexible filter view. [2] https://www.petri.com/
[3] http://www.technoreply.com/
We can highlight lines with search criteria.
Columnizer is its key feature, which helps it to split log
file lines into several multiple columns for some well-
By: Aakash Beniwal
defined log file formats.
The author works with Infosys Limited, Pune, as a testing
engineer and has an experience of 2.5 years in that domain.
Other alternatives to consider He can be reached at aakashnavodaya@gmail.com.
Atom: This is a freeware open source solution that

28 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Admin

DevOps: Using Ansible to Deploy


Cacti for Monitoring
In this third article in the DevOps series, we will install and set up Cacti, a free and open
source Web-based network monitoring and graphing tool, using Ansible.

C
acti is written in PHP and uses the MySQL database ansible_user=root ansible_password=password
as a backend. It uses the RRDtool (Round-Robin
Database tool) to handle time series data and has built- Add an entry for centos in the /etc/hosts file as
in SNMP support. Cacti has been released under the GNU indicated below:
General Public License.
192.168.122.98 centos
Setting up Cacti
We will use a CentOS 6.8 virtual machine (VM) running on The contents of the all.yml for use with the playbook are
KVM to set up Cacti. Just for this demonstration, we will as follows:
disable SELinux. You will need to set the following in /etc/ ---
selinux/config and reboot the VM: mysql_cacti_password_hash: "{{ vault_mysql_cacti_password_
hash }}"
SELINUX=disabled
mysql_username: "{{ vault_mysql_user }}"
When used in production, it is essential that you enable mysql_password: "{{ vault_mysql_password }}"
SELinux. You should then test for Internet connectivity from
within the VM. The Cacti.yml playbook is located in the ansible/
The Ansible version used on the host Parabola GNU/ playbooks/configuration folder.
Linux-libre x86_64 is 2.2.1.0. The ansible/inventory/kvm/
directory structure is shown below: Vault
Ansible provides the Vault feature, which allows you to store
ansible/inventory/kvm/inventory sensitive information like passwords in encrypted files. You
ansible/inventory/kvm/group_vars/all/all.yml can set the EDITOR environment variable to the text editor of
your choice, as shown below:
The IP address of the guest CentOS 6.8 VM is provided in
the inventory file as shown below: $ export EDITOR=nano

centos ansible_host=192.168.122.98 ansible_connection=ssh In order to store our MySQL database credentials, we will

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 29


Admin Lets Try

create a vault.yml file as indicated below: - wait_for:


port: 80
$ ansible-vault create inventory/kvm/group_vars/all/vault.yml
A yum update is first performed to sync with the
Provide a password when prompted, following which, package repositories. The httpd Web server and a few other
the Nano text editor will open. You can enter the following packages are then installed. The server is started, and the
credentials and save the file: Ansible playbook waits for the server to listen on port 80.

--- MySQL and PHP


vault_mysql_cacti_password_hash: The MySQL, PHP and RRDTool packages are then installed,
"*528573A4E6FE4F3E8B455F2F060EB6F63ECBECAA" following which the SNMP and MySQL servers are started as
shown below:
vault_mysql_user: "cacti"
vault_mysql_password: "cacti123" - name: Install MySQL, PHP packages
hosts: centos
You can edit the same file, if you wish, using the become: yes
following command: become_method: sudo
gather_facts: true
$ ansible-vault edit inventory/kvm/group_vars/all/vault.yml tags: [database-web]

It will prompt you for a password, and on successful tasks:


authentication, your text editor will open with the decrypted - name: Install database/web packages
file contents for editing. package:
name: "{{ item }}"
Apache state: latest
Cacti has many dependency packages, and the first software with_items:
that we will install is the Apache HTTP server. - mysql
- mysql-server
--- - MySQL-python
- name: Install web server - php-mysql
hosts: centos - php-pear
gather_facts: true - php-common
tags: [httpd] - php-gd
- php-devel
tasks: - php
- name: Update the software package repository - php-mbstring
yum: - php-cli
name: '*' - php-process
update_cache: yes - php-snmp
- net-snmp-utils
- name: Install HTTP packages - net-snmp-libs
package: - rrdtool
name: "{{ item }}"
state: latest - name: Start snmpd server
with_items: service:
- wget name: snmpd
- nano state: started
- httpd
- httpd-devel - name: Start mysqld server
service:
- name: Start the httpd server name: mysqld
service: state: started
name: httpd
state: started - wait_for:

30 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Admin

port: 3306 sql file needs to be imported and the cacti user needs to be
given the SELECT privilege to do this.
Cacti
Cacti is available in the EPEL repository for CentOS. The - name: For bug https://github.com/Cacti/cacti/issues/242
GPG key for the CentOS repositories is enabled before hosts: centos
installing the EPEL repository. Ayum update is performed become: yes
and the Cacti package is installed. A Cacti user is then created become_method: sudo
in the MySQL database. gather_facts: true
tags: [bug]
- name: Install Cacti
hosts: centos tasks:
become: yes - name: Import mysql_test_data_timezone.sql
become_method: sudo mysql_db:
gather_facts: true state: import
tags: [cacti] name: mysql
target: /usr/share/mysql/mysql_test_data_timezone.sql
tasks:
- name: Import EPEL GPG key - name: Grant privileges
rpm_key: mysql_user:
key: http://dl.fedoraproject.org/pub/epel/RPM-GPG- name: cacti
KEY-EPEL-6 append_privs: true
state: present priv: 'mysql.time_zone_name:SELECT'
state: present
- name: Add YUM repo
yum_repository: It is a good practice to have a separate playbook for such
name: epel exceptional cases. In future, when you upgrade to newer
description: EPEL YUM repo versions that have bug fixes, you can simply skip this step.
baseurl: https://dl.fedoraproject.org/pub/
epel/$releasever/$basearch/ Configuration
gpgcheck: yes The last step involves configuring Cacti.

- name: Update the software package repository - name: Configuration


yum: hosts: centos
name: '*' become: yes
update_cache: yes become_method: sudo
gather_facts: true
- name: Install cacti tags: [config]
package:
name: "{{ item }}" tasks:
state: latest - name: Create a database for cacti
with_items: mysql_db:
- cacti name: cacti
state: present
- name: Create cacti database user
mysql_user: - name: Import cacti.sql
name: cacti mysql_db:
password: "{{ mysql_cacti_password_hash }}" state: import
encrypted: yes name: cacti
priv: '*.*:ALL,GRANT' target: /usr/share/doc/cacti-1.0.4/cacti.sql
state: present
- name: Update database credentials in config file
Fixing a bug lineinfile:
The time zone data is missing in this MySQL version (5.1.73- dest: /etc/cacti/db.php
8). In order to resolve this bug, the mysql_test_data_timezone. regexp: {{ item.regexp }}

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 31


Admin Lets Try

line: {{ item.line }} - name: Start mysqld server


with_items: service:
- { regexp: ^\$database_username, line: $database_ name: mysqld
username = {{ mysql_username }}; } state: restarted
- { regexp: ^\$database_password, line: $database_
password = {{ mysql_password }}; } - wait_for:
port: 3306
- name: Allow port 80
shell: iptables -I INPUT 5 -p tcp --dport 80 -m state - name: Start the httpd server
--state NEW,ESTABLISHED -j ACCEPT service:
name: httpd
- name: Update access in cacti.conf for httpd state: restarted
replace:
dest: /etc/httpd/conf.d/cacti.conf - wait_for:
regexp: {{ item.regexp }} port: 80
replace: {{ item.replace }}
with_items: A database called cacti is created for the application, and
- { regexp: Require host localhost, replace: the cacti.sql file is imported into it. The database credentials
Require all granted } are updated for the Cacti application. The firewall rules are
- { regexp: Allow from localhost, replace: Allow then updated to allow incoming HTTP requests for port 80.
from all } The periodic cron poller is then enabled in /etc/cron.d/cacti:

- lineinfile:
dest: /etc/cron.d/cacti
regexp: ^#(.*)$
line: \1
backrefs: yes

Figure 3: Installation type

Figure 1: License agreement

Figure 2: Pre-installation checks Figure 4: Binary location and version

34 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Admin

Figure 5: Directory permission checks

Figure 8: Changing the password

Figure 6: Template set-up

Figure 9: Cacti Web UI

configuration/cacti.yml --ask-vault-pass

It will prompt you for the Vault password, following


which all the playbooks will be completed. You can then
open http://192.168.122.98/cacti to accept the GNU
General Public License agreement. After you agree to the
terms of the licence, click Next. The Cacti installation
wizard shows the pre-installation checks, which should
not have any errors. This is followed by the selection of
the installation type, binary location, version, and the
directory permission checks. You can then decide on the
templates you would like to set up, following which a user
login is provided. The default user name and password is
Figure 7: User login admin:admin and you will be immediately prompted to
change the password after logging in. You can then proceed
*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller. to log in to the Cacti dashboard. Figures 1 to 8 give the
php > /dev/null 2>&1 screenshots of the Cacti Web UI installation for reference.
A screenshot of Cacti graphing for memory usage is
The MySQL and HTTP servers are then restarted. shown in Figure 9.

The result By: Shakthi Kannan


The entire playbook can now be invoked as follows:
The author is a free software enthusiast and blogs at
shakthimaan.com.
$ ansible-playbook -i inventory/kvm/inventory playbooks/

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 35


Admin Insight

The Basics of
Vulnerability Assessment and
Penetration Testing
In these days of widespread Internet usage, security is of prime importance. The almost
universal use of mobile and Web applications makes systems vulnerable to cyber attacks.
Vulnerability assessment can help identify the loopholes in a system while penetration
testing is a proof-of-concept approach to actually explore and exploit a vulnerability.

C
yber attacks are increasing every day with the Helps identify programming errors that can lead
increased use of mobile and Web applications. to cyber attacks
Globally, statistics show that more than 70 per Provides a methodical approach to risk management
cent of the applications either have vulnerabilities which Secures IT networks from internal and external attacks
could potentially be exploited by a hacker, or worse, they Secures applications from business logic flaws
have already been exploited. The data losses due to this Increased ROI on IT security
are typically of two types. Either the data is confidential to Protects the organisation from loss of reputation
the organisation or it is private to an individual. Regardless and money
of the category, data losses result in the loss of money or
reputation. This article explores a technical process that can Why are systems vulnerable?
be adopted by industries and organisations to protect their There are primarily two main reasons for systems being
intellectual property, and if implemented correctly, will vulnerablemisconfiguration and incorrect programming
result in better risk management. practices. In the case of networks, devices such as routers,
For those who are new to Vulnerability Assessment and switches and servers, as well as firewalls and IPS systems
Penetration Testing (VAPT), this is a technical assessment are either misconfigured or, in some cases, not configured
process to find security bugs in a software program or a at all, thus running default settings. As an example, almost
computer network. The network may be a LAN or WAN, all firewalls have a default built-in user account with the
while the software program can be a .exe running on a name,admin. Typically, the password for it is also set
server or desktop, a Web/cloud application or a mobile to admin, by default, or something even easier to guess.
application. Before we get into the technical aspects of Looking at the example of servers, installing a database server
VAPT, lets look at a few of its benefits. leaves us with an sa account, which has a blank password.

36 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Insight Admin

As for programming errors, a user input taken from a


Web application form may be directly sent to a backend
database server without parsing it. This can lead to a
parameter manipulation attack or SQL injection attack.
Another example of programming errors would be a Web
service accepting requests without performing adequate
authentication, thus leaking data inadvertently. This shows us
that it is human error that leads to vulnerable systems, which
could be exploited easily by attackers, to compromise data
confidentiality, integrity and availability.

What is vulnerability assessment?


Vulnerability assessment (VA) is a systematic technical
approach to find the security loopholes in a network or Figure 2: Web VAPT process
software system. VA is entirely a process of searching and
finding, with the objective that none of the loopholes are Differences between VA and PT
missed. It primarily adopts a scanning approach which is done VA and PT differ from each other in two aspects. The VA
both manually and performed by certain tools. The outcome process gives a horizontal map into the security position of
of a VA process is a report showing all vulnerabilities, which the network and the application, while the PT process does
are categorised based on their severity. This report is further a vertical deep dive into the findings. In other words, the
used for the next step, which is penetration testing (PT). VA is VA process shows how big a vulnerability is, while the PT
usually a non-intrusive process and can be carried out without shows how bad it is. There is one more subtle difference.
jeopardising the IT infrastructure or application's operations. Due to the nature of work involved in each process, a VA can
be carried out using automated tools, while a PT, in almost
What is penetration testing? all cases, is a manual process. This is because PT essentially
A penetration test (PT) is a proof-of-concept approach to simulates what real hackers would do to your network or
actually explore and exploit vulnerabilities. This process application. Figures 1 and 2 shows the VAPT process for
confirms whether the vulnerability really exists and network and Web applications, respectively.
further proves that exploiting it can result in damage to the
application or network. The PT process is mostly intrusive VAPT tools
and can actually cause damage to the systems; hence, a lot While there are multiple tools available in the market, those
of precautions need to be taken before planning such a test. listed below are well-known for their usability. Although
The outcome of a PT is, typically, evidence in the form of a these tools are mentioned as VAPT tools, most of them
screenshot or log, which substantiates the finding and can be a essentially provide VA only and leave the PT part to the
useful aid towards remediation. As a summary, shown below ethical hackers to be done manually. There are a couple
are the steps involved in the VAPT process. of tools, though, which are powerful PT tools, and are
Scanning the network or application mentioned as such in the list below.
Searching for security flaws Nmap
Exploiting the security flaws Acunetix
Preparing the final report of the test Nessus
OpenVAS
Nexpose
BurpSuite (PT)
Metasploit (PT)
There are two important terms that an ethical hacker must
know, especially while using these tools. These are: false
positive and false negative.
A false positive is when a vulnerability actually does
not exist, but it gets reported. A false negative is when a
vulnerability actually exists but it is not reported. A false
positive can be a nuisance resulting in a waste of time for
an ethical hacker, whereas a false negative can be really

Figure 1: Network VAPT process Continued on page 40...

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 37


Developers Lets Try

Exploring Sinatra
This basic introduction to Sinatra can be used by interested readers as a starting
point, from where they can move on to the vast resources online.

R
uby, a mature language, is used in many applications of which let you manage and install multiple Ruby versions.
but Web development is what it is mostly used for. Installing it is as easy as using the following command:
Whenever someone recommends Ruby for Web
development, the first thing that comes to mind is Ruby gem install sinatra
on Rails. Granted, its a great Web framework for rapid
prototyping, and has excellent documentation, tooling and Basic use cases
community, but there are times when using Rails is an Sinatra is a DSL (domain specific language), which helps in
overkilllike when you want a simple solution without reducing the effort to churn out a Web application. To run
having to navigate between files and directories and just Sinatra locally, there is no configuration needed.
want the work done. Or, when you want a quick solution to a
problem but dont want to fiddle through configurations. For require sinatra
such cases, Sinatra might be the right tool for you.
Sinatra is named after the famous American singer and # Associates Root of the website with following code block
actor, Frank Sinatra. It was designed and developed by Blake when a get request is processed
Mizerany, with a huge list of contributors and backing from
many companies like Travis CI. Sinatra is a library and not a get / do
framework, which means it doesnt do many things under the Hello World
hood and lets you handle the logic, which is a great thing if End
you want control.
Sinatra executes a code block by matching it with an
Installation HTTP verb like GET, POST and a URL location like /user, /
Sinatra is easy to install. The only obvious requirement is important. In the above example, when some program makes
Ruby. If you dont have Ruby installed, try rbenv or rvm, both a GET request to the root /, it will execute the code block and

38 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Developers

Hello World will be returned by the server to the user, because the trailing slash, so that both http://localhost:4567/42
in Ruby, the last statement is treated as the return statement. and http://localhost:456/42/ are legal.
To run the code, type the following command:
curl --request GET --url http://localhost:4567/send/42/
ruby hello.rb
Sending message to room no 42
The following output should be visible with some variation,
depending on your version of Ruby and the backend server: Splat (*), or what is commonly known as the
wildcard operator, will allow anything and is accessible
== Sinatra (v1.4.8) has taken the stage on 4567 for via a special parameter named splat which is an array of
development with backup from Puma all the values captured by splat against *.

Puma starting in single mode... get /mix/*/with/*/? do


* Version 3.6.2 (ruby 2.2.4-p230), codename: Sleepy Sunday I have #{params[:splat]} and I am going to mix
Serenity #{params[:splat].first} with #{params[:splat].last}
* Min threads: 0, max threads: 16
* Environment: development end
* Listening on tcp://localhost:4567
Use Ctrl-C to stop curl --request GET --url http://localhost:4567/mix/apple/
with/oranges/
If you open http://localhost:4567 you will see a Hello
World message. I have ["apple", "oranges"] and I am going to mix apple
Sinatra has a params hash to capture parameters passed to with oranges
the route. A small excerpt is shown below:
There are many ways to play with routes, but
post /secret do covering them all would be beyond the scope of
Message is #{params[:message]} this article.
end One cool thing that you can quickly do with Sinatra
is make APIs, which generally dont require any interface
The following code displays the parameter named and most of them are stateless. In the following example,
message which was POSTed to /secret. All the parameters we will make a simple API that returns all environment
sent to a route are available in hash named params. If we variables available on the machine in JSON format. For
make a POST request with the message meet me at Coffee JSON conversion, we need a JSON parser and generator,
Shop as follows: which Ruby already ships with.
Content type tells Sinatra to explicitly specify itself in
curl --request POST --url http://localhost:4567/ the response header.
secret?message=meet%20me%20at%20Coffee%20shop
# Load the JSON library
we will get the following output: require json

Message is meet me at Coffee shop


get /json do
Sinatra routes can contain regular expressions, named content_type :json
parameters and wild card expressions, as well. ENV.to_h.to_json # To json converts the ENV which was
converted into hash to json
get '/send/:room/?' do end
"Sending message to room no #{params[:room]}"
end curl --request GET --url http://localhost:4567/json

This time we dont need to pass the parameter explicitly; The output may vary depending on the system and
it has become a part of the URL itself and it will just configuration:
work, and like in the previous instance, the parameters are
available via params hash. The interesting bit in the route is {
/?; it is used so that the route will work with and without "PWD": "/home/jatin/Area_51/sinatra_example",

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 39


Developers Lets Try

"HOME": "/home/jatin", Plugins and libraries


"LC_CTYPE": "en_US.UTF-8", There are innumerable libraries available for Ruby, in general,
"BROWSER": "/usr/bin/chromium", and almost of all them will work with Sinatra but there are some,
"JOURNAL_STREAM": "8:20822", like those listed below, that are a must have.
"XDG_SESSION_TYPE": "x11", Shotgun: It lets you reload the server on file changes,
"XDG_SESSION_DESKTOP": "gnome-xorg", enabling faster development.
"GJS_DEBUG_OUTPUT": "stderr", Byebug: This library lets you debug an issue by pausing
"RBENV_DIR": "/home/jatin/Area_51/sinatra_example", the request and providing a full-blown REPL to investigate.
"MAIL": "/var/spool/mail/jatin", Sinatra-Cross-Origin: This library lets you handle Cross
"WINDOWPATH": "2", Domain Origin Resource Sharing (CORS), which is very
"TERM": "xterm-256color", useful if you are making a web SDK for others to use.
"SHELL": "/usr/bin/zsh There are many extensions available at http://www.
sinatrarb.com/extensions-wild.html that might help.
}
References
Sinatra can handle views and templates as well, and they
[1] http://www.sinatrarb.com
are pretty simple. So, its good if you want to make user- [2] https://sinatrarb.slack.com - Sinatra Slack Community
facing applications.

By: Jatin Dhankhar


Note: Most of the code used in the article is also available
at https://github.com/jatindhankhar/sinatra_example. The author loves modern C++, Ruby, JavaScript and Haskell.
He can be reached at jatin@jatindhankhar.in.

Continued from page 37...


cascaded intelligence, where you cannot predict the next
dangerous, leaving a network or application susceptible to step and also need to apply years of experience to reach a
attack, while giving an illusion that everything is alright. It conclusion. No tool can do this, at least, not as of today, and
has been observed that automated tools tend to exhibit false hence it must be performed manually. An ethical hackers
positives as well as false negatives. This brings us to the next job can be made less stressful by automating certain tasks
important question of which method is betterthe automated of vulnerability assessment; however, the proof-of-concept
VAPT or manual VAPT? part in penetration testing mostly relies on manual ways of
exploiting the loophole and gathering the required evidence.
Automated vs manual VAPT Given below are the benefits of manual penetration testing.
The shortest answer is that the manual VAPT is always better Mimics the behaviour of real life hackers
and, hence, is a more widely used approach. This is because Brings a great deal of accuracy to the results
the automated tools are based on simple logic, which checks No false positives
either for signatures or behaviour. To understand this, lets Provides evidence, enabling the replication of problems
go to the basic difference between a software program and Helps in fixing a products security design issues
the human mind. Listed below are the steps a typical ethical VAPT is a methodical approach to risk management.
hacker performs for a VAPT. CISO's or IT heads should, as a matter of strategy, incorporate
Enumerates a vulnerability VAPT in their budgets and risk governance processes. It
Performs an attack manually should be a periodically executed process, and the frequency
Analyses the results of the attack should depend upon the datas confidentiality and risk impact.
Performs similar or different attacks based While there are multiple tools to perform vulnerability
on previous findings assessment, penetration testing is a manual process, and
Assimilates the results to create a customised attack should be handled by professional and highly experienced
Exploits the vulnerability further to see if more ethical hackers. This will ensure genuine cyber security as
attacks are possible opposed to an illusion of being secure.
Repeats the above steps for all vulnerabilities
Each network or application is different, resulting in a By: Prashant Phatak
very wide range of vulnerability scenarios. From the above The author is the founder CEO of Valency Networks, based
steps, it becomes clear that there is a lot of complexity in India (www.valencynetworks.com). He is a subject matter
expert in IT security penetration testing, designing and audits.
involved in VAPT, wherein, the results of one test decide
He can be reached at prashant@valencynetworks.com.
the actions of the next one. This makes VAPT a process of

40 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Developers

Scala: The Powerhouse of


Apache Spark
Scala, which is an acronym for Scalable Language, is a multi-paradigm, statically-
typed, type-safe programming language focused on Web services. Widely used by
data scientists today, its popularity is set to soar in the future because of the boom
in the Big Data and data science domains.

T
he world is being flooded with data from a wide range for distributed/concurrent programming, it is popularly
of sources. The hottest trends in technology currently used for data streaming, batch processing, AWS Lambda
are Big Data and data science, both of which offer Expression and analysis in Apache Spark. It is one of the
ways to cope with this data deluge. Many platforms have most widely used languages by data scientists, and its
emerged in this space, but Apache Spark and Scala work in popularity will soar in the future due to the boom in the
synergy to address the various challenges this humongous Big Data and data science domains.
data throws up. They are being used on Facebook, Pinterest,
NetFlix, Conviva and TripAdvisor, among others, for Big What is Apache Spark?
Data and machine learning applications. Apache Spark is a cluster computing framework based on
Hadoops MapReduce framework. Spark has in-memory
So what is Scala? cluster computing, which helps speed up computation by
Scala stands for Scalable Language. It was developed as reducing the IO transfer time. It is widely used to deal with
an object-oriented and functional programming language. Big Data problems because of its distributed architectural
Everything in Scala is an object, even its primitive data support and parallel processing capabilities. It is preferred to
types. If you write a snippet of code in Scala, you will Hadoop due to its stream processing and interactive query
see that the style is similar to a scripting language. It is features. To provide a wide range of services, it has built-in
very powerful, yet compact, and requires only a fraction libraries like GraphX, SparkSQL and MLlib. Spark supports
of the lines of code compared to other commercially Python, Scala, Java and R as programming languages, of
used languages. Due to its characteristics and support which Scala is the most preferred.

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 41


Developers Lets Try

Reasons to use Scala for Spark 2. To install Scala, type:


Eighty eight per cent of Spark users code in Scala for the
following reasons: $ cd ~/Downloads
1) Apache Spark is written in Scala and is scalable in $ wget http://www.scala-lang.org/files/archive/scala-
JVM. Being proficient in Scala helps you dig into the 2.11.7.deb
source code of Spark, so that you can easily access and $ sudo dpkg -i scala-2.11.7.deb
implement the latters newest features. $ scala version
2) Spark is implemented in Scala, so it has the maximum
features available at the earliest release. The features Working with Spark RDD using Scala
are ported from Scala to support other languages Resilient Distributed Datasets (RDD) are the basic data types
like Python. of Spark. They can be created in two waysfrom an existing
3) Scalas interoperability with Java is its biggest advantage, source or an external source.
as experienced Java developers can easily grasp the Creating RDD from an existing source: First, switch to
object-oriented concepts quickly. You can also write Java the home directory and load the sparkcontext as sc.
code inside a Scala class.
4) Scala is a static typed language. It looks like a dynamic $ ./bin/spark-shell
typed language because it uses a sophisticated type
inference mechanism. This leads to better performance. Then, create an RDD from existing data stored previously
5) Scala renders the expressive power of a dynamic in the driver program. First, we will make an array and then use
programming language without compromising the parallelise method to create the Spark RDD from an iterable
on type safety. already present in the driver program, using the following code:
6) It is designed for parallelism and concurrency to cater
to Big Data applications. Scala has efficient built-in val data = Array(2,4,6,8)
concurrency support and libraries like Akka, which allow val distData = sc.parallelize(data)
you to build a scalable application.
7) Scala works well within the MapReduce framework To view the content of any RDD, use the collect method,
because of its functional nature. Many Scala data as shown below:
frameworks follow similar abstract data types that are
consistent with Scalas collection of APIs. Developers distData.collect()
just need to learn the basic standard collections,
which allow them to easily get acquainted with Creating RDD from an external source: An RDD can be
other libraries. created from external sources which have the Hadoop Input
Format such as a shared file system, HDFS, HBase, etc. First,
Installing Scala load the desired file using the following syntax:
Scala can be installed on Windows or Linux based systems.
It is mandatory for Java to be installed before Scala. The val lines = sc.textFile(text.txt);
following steps will install Scala 2.11.7 on Ubuntu 14.04
with Java 7. Type the following commands in a terminal. To display the lines, use the command given below:
1. To install Java, type:
lines.take(2)
$ sudo apt-add-repository ppa:webupd8team/java
$ sudo apt-get update Basic transformations and actions
$ sudo apt-get install oracle-java7-installer Transformations modify your RDD data from one form to
another. Actions will also give you another RDD, but this
Table 1: A comparison between four languages
Metrics Scala Java Python R
Type Compiled Compiled Interpreted Interpreted
JVM based Yes Yes No No
Verbosity Less More Less Less
Code length Less More Less Less
Productivity High Less High High
Scalability High High Less Less
OOPS support Yes Yes Yes Yes

42 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Developers

operation will trigger all the lined up transformations on compliant. The following code will explore some basic functions:
the base RDD and then execute the action operation on
the last RDD. val sc = new SparkContext(conf)
Map transformation: Map applies a function to each val sqlContext = new SQLContext(sc)
element of the RDD. The following code checks the length import sqlContext.implicits._
of each line. val sampleData: Seq[ScalaPerson] = ScalaData.sampleData()
val dataset = sqlContext.createDataset(sampleData)
val Length = lines.map(s => s.length)
Length.collect() The Scala vs Python debate
Scala and Python are both powerful and popular among data
Reduce action: Reduce aggregates the elements scientists, many of whom learn and work with both languages.
according to key value. It is applied to the output of the Scala is faster and moderately easy to use, while Python is slower
Map function. The following code calculates the sum total but very easy to use. But Python usually ranks second because of
of characters in the file. the following reasons:
1. Scala is usually 10 times faster than Python for processing.
val totalLength = Length.reduce((a, b) => a + b) Python code needs a lot of translation and converting, which
makes the program a bit slow. Hence, there is a performance
The DataFrame API overhead. Scala has an edge in performance when there are
DataFrame is a distributed data collection organised into fewer processor cores.
columns that are similar to a relational database system. 2. Scala is better for concurrency due to its ability to easily
DataFrame can be created from Hive tables, structured data integrate across several databases and services. It has
files, external databases or existing RDDs. The DataFrame asynchronous libraries and reactive cores. Python doesnt
API uses a schema to describe the data, allowing Spark provide heavyweight processes to fork for multi-threading or
to manage the schema and only pass data between nodes. parallel computing.
This is more efficient than using Java serialisation. It is 3. The Scala programming language has several existential
helpful when performing computations in a single process, types, macros and implicits. Its advantages are evident when
as Spark can serialise the data into off-heap storage in a using these powerful features in important frameworks and
binary format and then perform many transformations libraries. Scala is the best choice for the Spark streaming
directly on this, reducing the garbage-collection costs of feature because Python Spark streaming support is not
constructing individual objects for each row in the data advanced and mature like Scala.
set. Because Spark understands the schema, we dont need Scala has slightly fewer machine learning and natural
to use Java serialisation to encode the data. The following language processing libraries than Python. The library has
code will explore some functions related to DataFrames. only a few algorithms but they are sufficient for Big Data
First, create a sparkcontext object, as follows: applications. Scala lacks good visualisation and local data
transformations. Nevertheless, it is preferred since Python
val sqlcontext = new org.apache.spark.sql.SQLContext(sc) increases portability for more issues and bugs, as translation is
tough. That Scala is the winning combination of both object-
Then, read an external JSON object and store it oriented and functional programming paradigms might be
in DataFrame dfs. Next, show and print it, using the surprising to beginners and they could take some time to pick
following code: up the new syntax. Scala programming might be a difficult
language to master for Apache Spark, but the time spent on
val dfs = sqlContext.read.json(employee.json) learning it is worth the investment.
dfs.show()
dfs.printSchema() References
[1] spark.apache.org/
DataSet API [2] www.tutorialspoint.com/apache_spark/
DataSet API has encoders that translate between JVM [3] www.kdnuggets.com/2015/06/introduction-big-data-
representations (objects) and Sparks internal binary format. apache-spark.html
Spark has built-in encoders, which are powerful as they [4] www.tutorialspoint.com/scala/
generate byte code to mix with off-heap data, and provide
on-demand access to individual attributes without having By: Preet Gandhi
to de-serialise an entire object. Moreover, the DataSet API
The author is an avid Big Data and data science enthusiast. She
is designed to work well with Scala. When working with can be reached at gandhipreet1995@gmail.com
Java objects, it is important that they are fully JavaBean-

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 43


Developers Lets Try

An Introduction to

Remote Procedure Call (RPC) has been around for decades as a mechanism for inter-
process communication in applications. The client making a call talks to a stub that works
behind the scenes to handle the marshalling/unmarshalling of the request/response data.
To the client it appears that the service is residing locally.

T
he last decade has seen the rise of public APIs supported languages. Most modern programming languages
and standards like REST for building HTTP based like Java, Python, C#, Node.js and others are supported. You
services. Both XML and JSON are frequently used can either generate the server bindings via the tools provided
as the data format for these service methods request and or even dynamically provide the implementation.
response data. With the proliferation of these services and On the client side, you can generate the gRPC stub in a
the emerging trend towards micro-services, latency becomes client language of your choice, and use that stub directly in
an important consideration when creating high performance your client to invoke the service.
and efficient services.
To address this, Google had been working for a while Why use gRPC?
to come up with a specification that defines both service gRPC has several advantages that are worth considering in
interfaces and efficient communication protocols, along with your application. Some of them are:
bindings in multiple languages for both the client and server It is built on HTTP/2, which provides us with a high
sides. The company later made this available as open source speed communication protocol that can take advantage of
to the general public and the gRPC Project was born. The bi-directional streaming, multiplexing and more.
project helps to implement services in multiple languages The latest version of ProtocolBuffer, i.e., version 3,
with pluggable support for load balancing, health checking supports many more languages.
and authentication. The ProtocolBuffer data has a binary format and,
The gRPC model is shown in Figure 1. hence, provides a much smaller footprint than JSON/
The service, its methods and the messages are defined XML payloads that are currently the most popular.
via a separate specification known as ProtocolBuffers. This This can make a big difference when latency is an
specification is then implemented by the server in one of the issue in your API.

44 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Developers

package osfy_stats;

//Service. define the methods that the grpc server can expose
to the client.
service OSFYStatsService {
rpc toparticles (TopArticlesRequest) returns
(TopArticlesResponse);
rpc articleStats (ArticleStatsRequest) returns
(ArticleStatsResponse);
}

//Message Type definition for TopArticlesRequest


message TopArticlesRequest{
Figure 1: gRPC model int32 numResults = 1;
}
gRPC and CNCF
gRPC was released by Google more than a year back and //Message Type definition for TopArticlesResponse
since then, there has been a lot of momentum towards message TopArticlesResponse {
getting the industry to consider this as the glue for micro- repeated Article articles = 1;
services communication, especially when latency is a }
key factor. Recently, it got adopted as a top level project
in the Cloud Native Computing Foundation (CNCF), //Message Type definition for Article
which is a big move towards the wider adoption of message Article {
gRPC. It joined the likes of Kubernetes, Prometheus int32 id = 1;
and others that are considered to be the foundation of a string title = 2;
cloud native application. string url = 3;
}
Wire Protocol - ProtocolBuffers
ProtocolBuffers is both an interface definition language //Message Type definition for ArticleStatsRequest
and a message format. It is primarily used to define the message ArticleStatsRequest {
service interface, i.e., what the service methods are and the int32 id = 1;
messages that are exchanged. The message formats are also }
defined via their individual parts.
This protocol definition file can then be used to //Message Type definition for ArticleStatsResponse
generate both the server side and client side bindings, or message ArticleStatsResponse {
you can dynamically load the definition and provide the int32 id = 1;
implementations. ProtocolBuffers is currently available int32 numViews = 2;
in two versions: proto2 and proto3, but we will go with int32 numLikes = 3;
the latter, which is the latest since it has support for a int32 numComments = 4;
wide range of languages. }
The best way to understand ProtocolBuffers is via an
example that we will build over the course of this article. Let us go through the proto file in brief:
This will include the server and client implementations. At the top of the file, we specify the version of
We are going to build a service called OSFY Stats. ProtocolBuffers and that the service resides in a package
This service provides two methods, one for retrieving the named osfy_stats.
top articles from the OSFY website and another method to We then define the service named OSFYStatsService and
retrieve the stats on a particular article, like the number of specify the two methods that it exposes, i.e., toparticles
views, likes and so on. We are not going to provide a real and articleStats.
implementation later, but this exercise is more to get an The input and output message formats are specified,
idea of how to start building the specification and message and the message formats for each of the request and
formats as per the ProtocolBuffers standard. response messages are defined in the same file. Note that
The proto file (osfy_stats.proto) is shown below: the ProtocolBuffers specification supports various scalar
types (int32, float and string) and also other complex stuff
syntax = "proto3"; like repeatable, Nested and more. The unique numbers

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 45


Developers Lets Try

that you see, i.e., 1, 2, 3, etc, are used by the binary format }
while encoding and decoding the messages. },
The toparticles method takes in the number of top
articles that we want as input and returns an array of articleStats(call, callback) {
articles, where each article contains fields like the ID, let article_id = call.request.id;
title and a URL. //make some calls to actual API
The articleStats method takes the articles ID as input,
and returns a message containing stats like the number of let numViews = 1000;
views, likes and comments. let numLikes = 30;
let numComments = 5;
Implementing our server
Now that we have defined the service, we can implement callback(null, {
our server. We will be using Node.js for the task, and it is id:article_id,
assumed that you have a Node.js environment set up and numViews,
available on your machine. numLikes,
We will need a few node libraries to be installed numComments
and you can use npm install: });
}
$ npm install grpc });
$ npm install grpcli
//Specify the IP and and port to start the grpc Server, no
Now, let us look at the implementation on the server side. SSL in test environment
The file server.js is shown below: server.bind('0.0.0.0:50000', grpc.ServerCredentials.
createInsecure());
const grpc = require('grpc');
//Start the server
const proto = grpc.load('osfy_stats.proto'); server.start();
const server = new grpc.Server(); console.log('OSFY Stats GRPC Server is now running on port-
>', '0.0.0.0:50000');
let top_articles = [
{ id:20000 , title: 'T1', url: 'URL1' }, Let us go through the code in brief:
{ id:20001 , title: 'T2', url: 'URL2' }, We load the proto definition file and create a server instance.
{ id:20002 , title: 'T3', url: 'URL3' }, For the server instance, we simply bind the service proto.
{ id:20003 , title: 'T4', url: 'URL4' }, osfy_stats.OSFYStatsService.service and provide the
{ id:20004 , title: 'T5', url: 'URL5' } implementations for the two methods: articleStats and
]; toparticles.
We use mock implementations for the two methods and,
//define the callable methods that correspond to the methods in reality, you would have connected to your analytics API
defined in the protofile for this purpose.
server.addProtoService(proto.osfy_stats.OSFYStatsService. To start the server, all we need to do is the following,
service, { and it will display that the server is running, via the message
toparticles(call, callback) { shown below:

if (call.request.numResults < 1 || call.request. $ node server.js


numResults > 5) { OSFY Stats GRPC Server is now running on port-> 0.0.0.0:50000
callback(new Error('Invalid number of Results provided.
It should be in the range of [1-5]')); Testing the service
} else { To test the service, we can use the node module grpcli that
we installed. To launch grpcli and point it to the proto file and
var topresults = top_articles.slice(0, call.request. server that is running, use the command given below:
numResults);
grpcli -f osfy_stats.proto --ip=127.0.0.1 --port=50000 -i

callback(null, { articles:topresults }); This will initiate the connection, and we can then use the

46 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Developers

rpc list and call methods to test out the service. The sample client.articleStats({"id":2}, (error, response) => {
calls are shown below: if (!error) {
console.log("Article ID : " + response.id + " Views :
$ grpcli -f osfy_stats.proto --ip=127.0.0.1 --port=50000 -i " + response.numViews + " Likes : " + response.numLikes + "
Package: osfy_stats Comments : " + response.numComments );
Service: OSFYStatsService } else {
Host: 127.0.0.1 console.log("Error:", error.message);
Port: 50000 }
Secure: No });
[grpc+insecure://127.0.0.1:50000]# rpc list
toparticles(TopArticlesRequest) { You can execute the client and see that the two actions
return TopArticlesResponse; available by the service are invoked. The output is shown below:
}
articleStats(ArticleStatsRequest) { $ node client.js
return ArticleStatsResponse; Article ID : 2 Views : 1000 Likes : 30 Comments : 5
} Total Articles: 2
[grpc+insecure://127.0.0.1:50000]# rpc call articleStats 20000 T1 URL1
{"id":1} 20001 T2 URL2
Info: Calling articleStats on OSFYStatsService
Response: Other language bindings
{ We have seen how we can define the service interface via the
"id": 1, ProtocolBuffers format, and then used Node.js to develop both
"numViews": 1000, the server side and client side bindings. The advantage of gRPC
"numLikes": 30, is that your server side could be implemented in a specific
"numComments": 5 language, say Node.js, but the client bindings could be in another
} language, like Python, Java or other supported bindings.
[grpc+insecure://127.0.0.1:50000]# To see the list of languages supported, check out the
documentation page (http://www.grpc.io/docs/) and select a
Consuming the gRPC service language of your choice.
Now that we have tested our service, we can write our client Modern architectures suggest breaking up monolithic
code as shown below. The code is similar in the sense that we applications into multiple micro-services and to compose your
load the proto file first and then create a client to the server applications via those services. This results in an explosion of
that is running. Once the client is connected, we can directly inter-service calls and it is important that latency, which is one
invoke the service methods as shown below: of the key factors to consider in providing a high performance
system, is addressed. gRPC provides both an efficient wire
const grpc = require('grpc'); transfer protocol and multiple language bindings that make
this a possibility. With the recent adoption of gRPC as a top
const proto = grpc.load('osfy_stats.proto'); level project in the Cloud Native Computing Foundation, we
are likely to see an increase in developers exploring and using
const client = new proto.osfy_stats.OSFYStatsService('localho this across a wide range of projects.
st:50000', grpc.credentials.createInsecure());

References
client.toparticles({"numResults":2}, (error, response) => {
if (!error) { [1] gRPC.io home page: www.grpc.io
[2] gRPC Documentation: http://www.grpc.io/docs/
console.log("Total Articles: " + response.articles. [3] Protocol Buffers Documentation: https://developers.google.
length); com/protocol-buffers/docs/overview
for (article of response.articles) { [4] gRPC Community: http://www.grpc.io/community/
console.log(article.id + " " + article.title + " " + [5] Cloud Native Computing Foundation: https://www.cncf.io/
article.url);
} By: Romin Irani
} else { The author has been working in the software industry for
console.log("Error:", error.message); more than 20 years. His passion is to read, write and teach
about technology, in order to help developers succeed. He
}
blogs at www.rominirani.com.
});

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 47


Developers Lets Try

Qt Programming
for HTTP REST Clients
This article discusses Qt support for connectivity to IoT platforms like ThingSpeak
using HTTP REST APIs. It also focuses on handling JSON data in terms of encoding,
parsing, URL encoding, forming query strings, etc.

Q
t is a cross-platform development framework with a request payload or the GET method with a query
designed to provide eye candy GUI features and string, and retrieve data in JSON or XML formats using
to give rich API support for Web communication, the GET method. Recently, support for sending data using
graph plotting, data exchange, 3D visualisation, multimedia MQTT Publish has also been added. ThingSpeak has good
handling, location tracking, sensor interfacing, etc. Qt integration support for MATLAB from Mathworks, which
applications can be built for various desktop platforms like helps it to offer better analysis and visualisation of data.
Linux, Mac OS and Windows; for embedded platforms like It provides SDKs in various languages for connectivity
Raspberry Pi and QNX, and also for mobile platforms like or one can try to connect using any HTTP client of the
Android, iOS and Windows Mobile. preferred language.
This article explores Qt support for connectivity to IoT In ThingSpeak, data is stored in terms of channels, and
platforms like ThingSpeak using HTTP REST APIs, and each channel is associated with an ID, name, description
also focuses on handling JSON data in terms of encoding, and various applicable fields along with some tags, geo-
parsing, URL encoding, forming query strings, etc. The location, etc. For simple and better authentication, API
assumption is that readers have basic familiarity with Qt keys are provided for read/write operations and a channel
and RESTful operations using HTTP support. If you are key for meta operations. The API keys of a specific
new to the Qt environment, do refer to some of the previous channel can be embedded in a query string or post data
articles published in earlier editions of OSFY, as listed in the for authentication. Secure HTTP (https) is preferred to
References, before proceeding. prevent unauthorised access of API keys by eavesdroppers.
A channel can also be made public during the creation or
About HTTP REST and ThingSpeak by changing the settings later, in which case no read key is
ThingSpeak is an open source platform for building IoT required for viewing the data.
applications, which supports connectivity using HTTP One can log in to ThingSpeak using a Mathworks account,
REST APIs. One can send data using the POST method which is free of cost, and create any number of channels

50 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Developers

and send maximum feedsthe only limitation on updating feed.insert(field3,Qvariant(pval).toString());


channels is an interval of 15 seconds. Once the channel is QByteArray payload=QJsonDocument::fromVariant(feed).toJson();
created with a suitable description, applicable fields and meta
information, you can identify the read or write API keys under You may verify the prepared JSON data in QString format
Channel settings and the key for channel meta operations in as follows:
the Profile section.
Lets now look at how a REST client for connecting with qDebug() << Qvariant(payload).toString();
ThingSpeak can be built.
Or you can display it in a QLineEdit or QTextEdit widget
Qt HTTP connectivity for testing purposes.
In order to talk to any network server using the HTTP Step 2: Prepare the URL as follows:
protocol, Qt provides the QNetworkAccessManager class,
which has asynchronous methods like get, post, put and QUrl myurl;
deleteResource to perform various REST operations. These myurl.setScheme(http); //https also applicable
methods take the QNetworkRequest object as an argument, as myurl.setHost(api.thingspeak.com);
well as an additional argument for request payload in the form myurl.setPath(/update.json);
of QByteArray for POST, PUT operations. QNetworkRequest
mainly contains the URL in the form of a QUrl object, which We are skipping the user name and password as we are
encapsulates the protocol, host name, port, path, query string, using API keys for authentication. We are also skipping
etc. The QUrlQuery class can be used to form a QueryString setPort as the service is running on the default port 80. You
effectively. These methods return the response in the form can verify the prepared URL as follows:
of a QNetworkReply, which needs to be explicitly destroyed
using the deleteLater method in the slot connected to the qDebug() << myurl.toString();
finished signal of QNetworkAccessManager.
Lets consider a channel with three fields representing Step 3: Prepare the network request, as follows:
temperature, humidity and pressure. Let us assume that
the various API keys and channel numbers are initialised QNetworkRequest request;
as follows: request.setUrl(myurl);
request.setHeader(QNetworkRequest::ContentTypeHeader,
QString RDKey = XXXXXXXXXXXXXXXX; application/json);
QString WRKey = XXXXXXXXXXXXXXXX;
QString CHKey = XXXXXXXXXXXXXXXX; Step 4: Perform the POST operation using the following
Qstring CHNum = xxxxxx; code in the slot connected to the Publish PushButton click.

To send a feed, we need to perform the POST method QNetworkAccessManager *restclient; //in class
with the steps that follow, using the URL https://api. restclient = new QNetworkAccessManager(this); //constructor
thingspeak.com/update.json and the following JSON data QNetworkReply *reply = restclient->post(request,payload);
as request payload: qDebug() << reply->readAll();

{ restclient can be declared in the MainWindow or the


api_key:XXXXXXXX XXXXXXXX,
field1:25,
field2:72,
field3:900
}

Step 1: Lets prepare the data for POST in JSON format,


assuming that tval, hval and pval represent the temperature,
humidity and pressure values in integer form.

QVariantMap feed;
feed.insert(api_key,WRKey);
feed.insert(field1,QVariant(tval).toString());
feed.insert(field2,QVariant(hval).toString()); Figure 1: Sending a feed using POST

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 51


Developers Lets Try

Dialog class and the QNetworkAccessManager object can be url.setHost(api.thingspeak.com);


created in constructor, as one object is sufficient to perform url.setPath(/channels/+CHNum+/feeds.json);
all the operations. url.setQuery(api_key=+RDKey+&results=10);
The same update operation can be achieved using the request.setUrl(url);
GET method and data encoded in the URL as a query string: reply=nwManager->get(request);

QUrlQuery querystr; To process the responses holding all feeds in the JSON
querystr.addQueryItem(api_key,WRKey); format, connect the finished signal of restclient to a suitable
querystr.addQueryItem(field1,25); custom slot.
querystr.addQueryItem(field2,72);
querystr.addQueryItem(field3,900); QObject::connect(restclient, SIGNAL(finished(QNetworkReply*)),
myurl.setScheme(https); this, SLOT(replyFinished(QNetworkReply *)));
myurl.setHost(api.thingspeak.com);
myurl.setPath(/update); Parsing JSON data
myurl.setQuery(querystr); The returned JSON data has two primary fields with the
request.setUrl(myurl); names channel and feeds, and the value of feeds is an array
reply = restclient->get(myurl); of all feeds, where each array element consists of fields like
qDebug() << reply->readAll(); entry_id, field1, field2, field3, created_at, etc.
To traverse all array elements and retrieve the specific
fields in each, you can use the following code to parse the
JSON data in the replyFinished slot:

QJsonDocument jsdoc;
jsdoc = QJsonDocument::fromJson(reply->readAll());
QJsonObject jsobj = jsdoc.object();
QJsonArray jsarr = jsobj[feeds].toArray();
foreach (const QJsonValue &value, jsarr) {
QJsonObject jsob = value.toObject();
qDebug() << jsob[entry_id].toInt();
qDebug() << jsob[field1].toString();
qDebug() << jsob[field2].toString();
qDebug() << jsob[field3].toString();
Figure 2: Sending a feed using GET qDebug() << jsob[created_at].toString();
}
Alternatively, data encoded in the URL query string reply->deleteLater();
format can be used to perform the POST operation using the
same URL api.thingspeak.com/update.json: Rendering data in tabular form
To display the data in tabular form, create a TableWidget
//Prepare querystr similar to above steps through TableView with the name tableFeeds and add
request.setHeader(QNetworkRequest::ContentTypeHeader, the following code in the slot connected to the Retrieve
application/x-www-form-urlencoded); PushButton click.
QByteArray postdata = Qvariant(querystr).toByteArray();
restclient->post(myurl,postdata); ui->tableFeeds->clearContents();
ui->tableFeeds->setColumnCount(5);
Retrieving data from ThingSpeak ui->tableFeeds->setRowCount(jsarr.count());
To retrieve the feeds from ThingSpeak, we need to perform the foreach (const QJsonValue &value, jsarr) {
GET operation on http://api.thingspeak.com/channels/xxxxxx/ QJsonObject jsob = value.toObject();
feeds.json and api_key=XXX..XX as the query string. For this ui->tableFeeds->setItem(k,0,
purpose, use the following code in the slot connected to the new QTableWidgetItem(jsob[entry_id].
Retrieve PushButton click. You can append results=10 to the toString()));
query string to limit the number of results to the last 10 feeds. ui->tableFeeds->setItem(k,1,
new QTableWidgetItem(jsob[field1].toString()));
QUrl url; ui->tableFeeds->setItem(k,2,
url.setScheme(http); new QTableWidgetItem(jsob[field2].toString()));

52 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Developers

ui->tableFeeds->setItem(k,3, to other IoT platforms and database servers like InfluxDb,


new QTableWidgetItem(jsob[field3].toString())); which support HTTP REST based connectivity. You can find
ui->tableFeeds->setItem(k,4, the entire code for this example at github.com/rajeshsola/qt-
new QTableWidgetItem(jsob[created_at].toString())); examples/tree/master/thingspeak-demo.
k++;
}
References
[1] doc.qt.io
[2] in.mathworks.com/help/thingspeak/
[3] github.com/rajeshsola/qt-examples
Please refer to the following articles to get started with Qt:
[4] http://opensourceforu.com/2015/03/qt5-let%c2%92s-
learn-some-theory/
[5] http://opensourceforu.com/2015/03/qt5-console-
applications-and-networking/
[6] http://opensourceforu.com/2012/01/developing-
applications-qt-part-1/
[7] http://opensourceforu.com/2012/02/developing-
applications-qt-part-2/
[8] http://opensourceforu.com/2012/03/developing-apps-
qt-part-3/
[9] http://opensourceforu.com/2012/05/developing-apps-
qt-part-4/
Figure 3: Retrieving data and displaying it in tabular form

You can also plot the graph with the above feeds using By: Rajesh Sola
the third party library, QCustomPlot (http://www.qcustomplot. The author is a faculty member of C-DACs Advanced
com) or with the help of Qt Charts introduced in version 5.7.0. Computing Training School, and an evangelist in the
As an example, we have discussed connectivity to embedded systems and IoT domains. You can reach him at
rajeshsola@gmail.com.
ThingSpeak in this article. You can apply these concepts

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 53


Developers Lets Try

A Quick Look at
Programming with Shell Scripts
The power of scripting lies in the fact that you get to program with commands you
already know, from various computer languages. Scripting provides a means to
substitute really complicated and convoluted commands and if there is something
repetitive, then a script can probably remove the tedium in your work.

#!/bin/bash

I
magine that you are doing some important task on your different command line interfaces (CLI) or in a graphical
computer system and, suddenly, you get a black screen with manner (using the GUI). A shell takes input from us in the
something being automatically typed on it. I am sure many form of commands, processes it and then gives an output.
of us have experienced such system reboots that take place It can be accessed by a terminal, which runs it. Whenever
on their own due to some hardware or software issues. When we run the terminal, the shell actually issues a command
this happens, our pulse rate shoots up, and we hope and pray prompt, where we can type our own input, which is then
that the task that was being performed has been saved, or else, executed when we hit the Enter key. The output is thereafter
everything will have to be started afresh. displayed on the terminal. The shell basically wraps around
Have we ever given a thought to how all this happens on the delicate interior of an operating system, protecting it
its own? Well, its shell scripting that drives such processes from any accidental damage and, hence, the name. There are
automatically. A newbie in the computer programming arena different types of a shell, such as Korn shell (ksh), Bourne
generally gets anxious just seeing the black screen on the shell (sh), C shell (csh), Bourne Again shell (bash), a remote
computer, assuming the programming involved is quite difficult. shell (rsh), etc. A script written in any such environment is
In shell scripts, the term shell defines the interface referred to as a shell script.
between the user and the different services of an operating The different operations that can be performed by shell
system such as Linux, UNIX, Windows (to some extent) scripts include file manipulation, execution of programs, and
or Mac. Apart from the shell, the kernel is the other main printing text. A script that sets up the specific environment,
component of an operating system. Its the kernel that makes runs the program, does clean-ups if necessary, does logging,
the communication between the hardware and software etc, is basically called a wrapper, which refers to the
possible. The interface can be created by a shell through automated mode of running a specific operating system shell.

54 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Developers

code files, instead of manually running the four commands


which are required to build the final program from them,
one could create a C shell script, and keep it in the directory
along with the C source code files, which would ultimately
Kernel
Hardware Operating Terminal User
compile them automatically. The script would further allow
System
Shell
a user to save the file being edited, pause the editor, and then
just run the shell script to create the updated program, test
that, and return to the editor again.
Different shortcuts to perform specific functions: We
can use the different available shortcuts in shell scripting
Figure 1: A shell acts as an interface between the user and the OS to perform some specific action. These shortcuts are short
(Image credits: http://www.guru99.com/) commands written for specific utilities. They are like
inbuilt functions, which we use in different programming
In different operating systems, shell scripts are referred to languages. A shell script can also provide convenient
by different names such as batch files (OS/2, MSDos-Win95 variations of a system command, where different special
stream), command procedures (VMS), and shell scripts environment settings, post-processing or command options
(Windows NT stream and third-party derivatives). Mainframe apply automatically, but in such a way that they allow the
operating systems are associated with a different set of terms. new script to still act as a complete normal UNIX command.
Shell scripts help us to program different commands in For example, to create a version of the ls command to list
chains and have the system execute them as a scripted event different files, it can be given a shorter command name of
the same as batch files. They also allow us to perform far l. This shorter command will be normally saved in the bin
more useful functions, like command substitution. We can directory of a user as /home/username/bin/l and a default set
invoke a command, like date, and then use its output as part of different command options will be pre-supplied. The user
of a file-naming scheme. We can even automate backups, can then use l for most commonly used short listings.
and each copied file can have the value of the current date Generalisation: Simple batch jobs are usual for isolated
appended to the end of its name. Shell scripts are not just tasks, but at the same time, using shell loops, variables and tests
invocations of different commands either, but are programs in provides much more flexibility to users. Lets look at a bash file
their own right. Shell scripting also allows us to use different (shell script) to convert different JPEG images to PNG images,
programming functions such as if/ then/ else statements, in which the names of images are provided on the command
for loops, and so on directly within our operating systems linepossibly using wildcards. Instead of each of the names
interface. We dont have to learn another language because we being listed within the script, they can be created with this
are using what we already knowthe command line. file, typically saved in /home/username/bin/jpg2png. So we
can directly run this command on an entire directory of JPEG
Different features of shell scripts images with just /home/username/bin/jpg2png *.jpg.
Lets have a look at the different features of shell scripts. Flavour of programming: Many modern shell scripts
Running batch jobs: Shell scripts allow different sets also supply various features which are usually found only in
of commands that are entered manually at a command line more sophisticated programming languages, such as control-
interface to be executed automatically, without having flow constructs, comments, variables, subroutines, arrays
to wait for a user to separately trigger each stage of the and so on. With such features available, it is quite possible
sequence. For example, in a directory that has three C source to write reasonably sophisticated applications using shell
scripts. However, they are still limited by the fact that most
shell scripting languages have little or even no support for
program
data typing systems, threading, classes, complex math and
execution
other such common language features. They are also much
interpreted
programming
variable and
filename
slower than the compiled code or interpreted languages that
language
are written with speed as a performance goal. The standard
substitution

SHELL UNIX tools, Awk and Sed, provide extra capabilities for shell
programming. Perl can also be embedded in different shell
environment
control
I/O
redirection scripts as can other scripting languages such as Tcl, etc.
Verisimilitude: A key trait of different shell scripts
pipeline
hookup
is that the invocation of their interpreter is considered as
a core operating system feature. So, instead of a user's
Figure 2: The different functions of a shell Figure 3: Path shortcuts in shell scripting shell only being able to run different scripts in that shell's
(Image credits: googleimages.com) (Image credits: googleimages.com) language or a shell script only having directives of its

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 55


Developers Lets Try

interpreter handled correctly, if it is run from a shell stdout


Stdin
(both were limitations in the early Bourne shell's script
program
handling), shell scripts are set up and executed by args Stderr
the OS itself. Nowadays, a modern shell script is not
just on the same footing as the system commands, but
rather, many of the system commands are actually shell
I/O
scripts. This extends to the returning exit codes like
other system utilities in order to indicate success or
failure, and also allows them to be called components
X11
of the larger programs, regardless of how all those network
storage
larger tools are implemented. Like different standard
system commands, shell scripts omit any kind of file
name extension unless it is intended to be read into Figure 4: Output redirection and piping in shell scripting
a running shell using a special mechanism for this (Image credits: googleimages.com)
purpose (such as cshs source or shs .).
different. Various earlier versions of Windows NT are able
Shell scripting on various operating systems to successfully run contemporary versions of 4OS2 with
It is possible to leverage the various advantages of shell the help of the OS/2 sub-system.
scripting on different operating systems (other than UNIX 4. Scripting languages can be extended; for example,
and Windows) as well with the help of interoperability Windows NT and MS-DOS/Windows 95/98 type systems
software. Lets have a look at some of these options. allowed for batch/shell programs to call different tools
1. Interoperability software like Cygwin, Interix (which like KixTart, QBasic, Rexx; various Basic, Python and
is available in the Microsoft Windows Services for Perl implementations; and the Windows Script Host
UNIX), MKS Toolkit, UWIN (AT&T UNIX for and all its installed engines. On UNIX and other Posix-
Windows), Hamilton C shell, and others, allow UNIX compliant systems, Sed and Awk are used to extend the
shell programs to be run on different Windows NT string and the numeric processing ability of shell scripts.
machines and all their successors, with some loss of Tcl, Rexx, Perl and Python have graphics toolkits that
functionality on the MS-DOS-Windows 95 branch, as can be used to code different procedures and functions
well as earlier MKS Toolkit versions for OS/2. At least for shell scripts. This poses a speed bottleneck (Fortran,
three DCL implementations for Windows OS apart C, and Assembly language are much faster still) and
from XLNT, a multiple-use scripting language package adds functionality such as sockets and other connectivity
(which can be used with the command shell), CGI functions, which are not available in the shell language.
programming and Windows Script Host -- are available VBA and VBScript can be easily used to communicate
for these types of systems as well. with databases, spreadsheets, scriptable program of all
2. In addition to all these tools, some OS/2 and Posix types, development tools, telecommunications software,
functionality can also be used with the corresponding graphics tools and other software that can be accessed
environmental sub-systems of the Windows NT OS using the Component Object Model.
series up to Windows 2000 as well. A third 16-bit
sub-system, often called the MS-DOS sub-system, uses Writing your first shell script
Command.com which is provided with these OSs to Well, we are now at the most interesting part, which is,
run all the just-mentioned MS-DOS batch files. programming using the shell script. So we will actually follow
3. Different console alternatives such as 4DOS, 4NT, three simple steps in order to successfully write our first shell
4OS2, Peter Norton's NDOS, FreeDOS, and the script, which is the famous program to display Hello World.
GUI Take Command, which add the functionality to The pre-requisites are:
Windows NT-style Cmd.exe, OS/2's Cmd.exe, MS- You need to have Linux installed on your system.
DOS/Windows 95 batch files (run by Command.com), You need to have a text editor (select from Vim, kwrite,
and 4NT, respectively, are similar to the shells that they etc), as well, on your system.
actually enhance and are much more integrated with the Now, lets follow the three simple steps.
Windows script host. The Windows Script Host comes 1. Write the script
with three engines (VBScript, VBA and JScript ) that A shell script is basically a file that contains ASCII text. In
are pre-installed, and to which a number of third-party order to create a shell script, we use a text editor, which is
engines can be added with Perl, Rexx, Python, Tcl and nothing but a program, similar to a word processor, which
Ruby with pre-defined functions in 4NT. PC DOS is reads and writes different ASCII text files. There are many
also quite similar to MS-DOS, while DR DOS is quite text editors available for our Linux system, both for the GUI

56 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Lets Try Developers

environment and the command line environment. Here is a the program is located. That would really take a long time.
list of a few: You will have noticed that we don't usually have to specify
1. Vi or Vim the complete path name to the program we want to run; the
2. Emacs shell just seems to know that. The shell maintains a list of
3. Nano different directories where executable files are kept, and it just
4. Gedit searches for the directories in that list. If its not able to find
5. kwrite the program after searching each of the directories in the list,
Now, we can type in the first script using any of the it will throw up the error: Command not found.
above text editors, as follows: This list of directories is called the path. Let us look
at some of the commands related to this along with their
#!/bin/bash possible output.
# My first script The command for viewing the list of directories
echo "Hello World!" is as follows:

The above script has three lines. [me@linuxbox me]$ echo $PATH
The first line is a special clue given to the shell in order
to indicate what program is used to interpret this script. The output: A colon-separated list of directories which
In this case, its /bin/bash. Other scripting languages will be searched if a specific path is not given when a
such as Awk, Perl, Tcl, Tk, and Python can also use this command is attempted.
type of mechanism.
The second line is just a comment. Everything that The command for adding directories to the path, where
comes after a # symbol is all ignored by bash. As directory_name is the name of directory we want to add, is:
our scripts become larger and more complicated,
comments become important. They are basically used [me@linuxbox me]$ export PATH=$PATH:directory_name
by programmers to explain whats going on, so that
others can understand. The output: directory_name will be added to the path.
The last line is the echo command, which just prints The command for creating a bin directory, which is a sub-
whatever is given on the display. Once we have written directory of our home directory, is as follows:
the above script, we can save this file using any name.
Here, we save it as First_Shell_Script. [me@linuxbox me]$ mkdir bin
2. Give the shell permission to execute it
The next thing we need to do is to give the shell The output: The bin directory will be created.
permission to execute our script. This is done using the Shell scripting can be used in the following cases:
chmod command, as follows: 1. To create our own command or tool.
2. To monitor several tasks like disk usage, etc.
[me@linuxbox me]$ chmod 755 my_script 3. To take data backup and snapshots.
4. For automatic system booting.
The 755 will give us permission to read, write and to 5. For automatic installation of different application packages.
execute. Everybody else will just have read and execute 6. To automate different aspects of computer maintenance
permission. If we want our script to be private (so that only and user account creation.
we can read and execute), we use 700 instead. 7. To create startup scripts for different unattended applications.
8. To kill or start multiple applications together.
3. Put it at the location where the shell can find it
We now need to run our script by typing the
following command: References
[1] http://www.wikipedia.org/
[me@linuxbox me]$ ./First_Shell_Script [2] http://www.guru99.com/
[3] http://linuxcommand.org
Now, you should see Hello World! displayed. If we
dont, then we need to check what directory we saved our
By: Vivek Ratan
script in, so that we can go there and try again.
Before we go further, lets discuss paths a little bit. The author currently works as an automation test
engineer at Infosys, Pune. He can be reached at
When we type in the name of a command, our system
ratanvivek14@gmail.com for any suggestions or queries.
does not search the entire computer in order to find where

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 57


Developers Insight

Programming the Internet of Things


Using Contiki and Cooja
Contiki is an operating system with a focus on low power IoT devices. Cooja
is the Contiki network simulator. Cooja allows the large and small networks of
Contiki motes to be simulated. This article takes the reader through the process
of programming IoT with Contiki and Cooja.

W
e are all surrounded by a number of gadgets, mobile help them communicate with distant objects.
devices, smartphones, wireless nodes and many other As per reports from Forbes.com, the market for the
objects that are digitally connected in real-time. The Internet of Things is expected to reach around US$ 267
Internet of Things (IoT) enables real world objects to interact billion by 2020. Analysis from Gartner underlines that around
with each other. These objects can share information and 8.4 billion objects, with investments amounting to US$ 273
communicate in real-time to deliver better performance as well as billion, will be interconnected with each other in the current
security. IoT works by developing and integrating smart objects year (2017-18). This represents a 31 per cent increase over the
that can be controlled using remote network infrastructure. figures of 2016-17.
The term, the Internet of Things, was coined by Some of the key applications of IoT include:
Kevin Ashton in 1999. The implementation of IoT is Smart cities, retail points, smart grids, agriculture and
now widespread because of high performance wireless farming, homes and offices
technologies. Radio frequency identification (RFID) tags The Internet of Vehicles (IoV)
and sensors are the most important components of IoT. Connected cars
The RFID tags can be embedded in real world devices and Connected railways infrastructure
objects, which can be monitored remotely using software Wearable devices
based applications. RFID readers can be used to locate, read Software defined networking
and sense RFID implanted objects. Very small, micro-sized The industrial Internet
transmitting and receiving chips are integrated with RFID to Energy management

58 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Insight Developers

Research domains in IoT M2MLabs Mainspring


Due to the ever increasing deployment of IoT in the Node-RED
government and in the private sector, there is a need to ThingBox
analyse various factors that can affect its overall performance
and efficiency. Automation for home and offices
The following are some of the key research issues in IoT: Eclipse SmartHome
Security, privacy and trust architectures Home Gateway Initiative (HGI)
Big Data analysis and scalability Ninja Blocks
Device interoperability and compliance openHAB
Robustness and fault tolerance PrivateEyePi
Cognitive networking RaZberry
Energy aware approaches The Thing System
Virtualisation
Ontology models Middleware
IoTSyS
Free and open source tools for IoT programming Kaa
Featured below are some well known open source tools used OpenIoT
for IoT programming. OpenRemote
OpenIoT (http://www.openiot.eu/): This is a free and
open source platform to manage and program the sensors on Operating systems
the cloud and the Internet based environment. The concept of AllJoyn
Sensing-as-a-Service is being adopted in OpenIoT. Brillo
Zetta (http://www.zettajs.org/): This is a free and open Contiki
source platform that is based on Node.js. Zetta is used to FreeRTOS
create the IoT servers that can control and run the globally Raspbian
distributed systems, sensors and computers, including those RIOT
that are on the cloud. Spark
DSA (http://www.iot-dsa.org/): Distributed Services TinyOS
Architecture is a powerful, open source IoT library that is
available for free distribution. It enhances the performance of IoT integration tools and horizontal platforms
inter-object communication and makes it very effective. DSA Canopy
provides the toolkit for managing IoT based applications, Chimera IoT
services and objects. DeviceHive
Node-RED (http://nodered.org/): This provides the IoT Toolkit
programming interface and APIs for the Internet of Things. M2MLabs Mainspring
Using Node-RED, the flow based creation of remote IoT Mango
objects can be done easily with a Web browser based flow Nimbits
editor. In the flow editor of Node-RED, the JavaScript code Open Source Internet of Things (OSIoT)
can be executed and remote objects can be programmed easily OpenRemote
with powerful functionalities. Pico Labs
IoTivity (https://www.iotivity.org/): This is a prpl Foundation
powerful open source library which enables inter-object RabbitMQ
connectivity with enormous speed and performance. It SiteWhere
is written and programmed in C and C++. Most of the SiteWhere
performance aware protocols (like ANT+, Bluetooth low ThingSpeak
energy, Wi-Fi Direct, Zigbee and Z-Wave) can be easily webinos
integrated with IoTivity. Yaler
There are other open source implementations for the
Internet of Things as listed below. Protocols
Advanced Message Queuing Protocol (AMQP)
Development toolkits and libraries Constrained Application Protocol (CoAP)
Arduino Extensible Messaging and Presence Protocol (XMPP)
Eclipse IoT Project OASIS Message Queuing Telemetry Transport (MQTT)
Kinoma Very Simple Control Protocol (VSCP)

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 59


Developers Insight

to get the desired results. Contiki works on IPv4 as well as


IPv6 networking with the integration of lightweight protocols,
so that low power chips and radio frequency chips can be
connected without performance issues.
The URL for downloading Instant Contiki is http://
sourceforge.net/projects/contiki/files/Instant%20Contiki/.
Once the compressed Instant Contiki is downloaded, it
can be used on any host operating system. Instant Contiki
is available on sourceforge.net as a compressed file which
then has to be extracted. The uncompressed or extracted
Instant Contiki can be executed on VMware Player, which
is a virtualisation tool that can be downloaded free and is
Figure 1: Directory structure and files in Instant Contiki available at http://www.vmware.com/go/downloadplayer/.
In the extracted folder of Instant Contiki, there is the
executable file Instant_Contiki_Ubuntu_12.04_32-bit.vmx.
This file, on executing, will automatically open in
VMware Player, and we will be ready to work with Contiki
using virtualisation software in parallel with any host
operating system. The default password for the Contiki
operating system is user.
After loading the Contiki OS, the commands given
in Figure 3 are executed in the terminal so that the Cooja
simulator gets loaded for the implementation of IoT.

Creating a new network in the Cooja simulator


Figure 2: Instant Contiki login screen In the file menu of Cooja, select New Simulation as
shown in Figure 4.
In the dialogue box, the basic network parameters are

Figure 3: Loading the Cooja simulator in Contiki

Implementations for engineering


Open Garden
Open Source Robotics Foundation
OpenWSN
Figure 4: Creating new IoT simulation in Cooja
Using the Contiki OS with the Cooja
simulator to program the IoT
Contiki (http://www.contiki-os.org/) is a popular, free
and open source operating system for IoT programming
available under the BSD licence with the base code of
the C programming language. Contiki can be used for
communication between low powered RFID chips in wireless
networks with a high degree of performance and security.
The programming on Contiki is done using the Cooja
network simulator, in which the base libraries of RFID chips
and sensors are available in C. To program, control and
monitor the remote IoT devices, the back-end C programs
and related header files can be customised and recompiled Figure 5: Set-up of basic simulation properties in Cooja

60 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Insight Developers

Figure 6: Invoking wireless and RFID motes in the Cooja simulator Figure 9: Viewing wireless motes with positions in Cooja

Figure 10: Running simulation and behaviour analytics of motes


Figure 7: Importing C source code to recompile in Cooja
imported in the simulation area so that the transmission of
radio signals can be viewed and analysed.
In this simulation of the IoT network, the scenario
of a dynamic key exchange between the motes is
done. Here, the dynamic security key is generated and
authenticated for communication. In the IoT, for reasons
of security, it is necessary to devise and implement the
protocols and algorithms by which the overall privacy
and security in communication can be enforced to avoid
any intrusions. As the IoT can be used for military
applications, it becomes mandatory to work on highly
Figure 8: Compiling C source code for the desired behaviour of wireless motes in Cooja secured key exchange algorithms with the dynamic
cryptography of security keys.
set, which include the name of the simulation, radio medium, Once the simulation is complete, the network log files,
startup delay and random seed. which include the source and destination motes, the time,
Once the basic layout and working environment is ready, and the overall activities performed during simulation are
you need to import the RFID tags, sensor nodes or any analysed. In the Mote Output Window, the log data can be
other wireless devices that are to be connected and have to copied and further analysed using data mining and machine
communicate over the IoT. In wireless networking and IoT, learning tools for predictive analytics.
these are known as motes. There are many types of motes in
Cooja that can be programmed.
Physical motes, too, can be connected by using ports on By: Dr Gaurav Kumar
the system so that real-time interfacing can be done. Every
The author is the MD of Magma Research and Consultancy
mote, with the base properties and programming APIs, is
Pvt Ltd, Ambala. He is associated with various academic and
specified in the C source code at the back-end of Cooja. These research institutes, where he delivers lectures and conducts
C source code files can be customised and recompiled to get technical workshops on the latest technologies and tools.
the new or desired output from these motes. You can contact him at kumargaurav.in@gmail.com. Website:
www.gauravkumarindia.com.
After compiling C code, a number of virtual motes can be

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 61


Developers Insight

A Guide to Programming in
Perl, PHP and Python
Perl, PHP and Python are three very popular and easy-to-learn programming
languages, each with their own advantages and disadvantages. Newbies venturing
into the field of programming will find this guide interesting and instructive.

T
o be a good programmer, mastering one programming Perl code is very short and there is a whole set of one-
language is not enough. In fact, it is very important to line code available, which shows the power of Perl.
understand a customers requirements and choose the It should be used, depending upon the use case. It can
best available language for the task. Its easy to shift from one be used as a functional language, sometimes object-
programming language to another language if you know them oriented, procedural or imperative. How you want to use
very well. But there are so many programming languages in it depends on you. It handles almost every use case.
the world. Each has its own advantages and disadvantages. Perls CPAN provides a huge number of modules and
By leveraging all the advantages of different languages, a tested code, and most of them are completely free.
programmer can build a robust application. There are different Since Perl is a very old language, it has vast
factors which need to be considered, such as the functionality community support.
of the application, support for new features, the platform on Perl is portable and available for all platforms.
which the application will run, performance, security, code
size, community and support. Disadvantages
Today, lets examine the three Ps: Perl, PHP and Python. All Since Perls syntax is complex, sometimes new
these three languages are dynamic and powerful in their own programmers find it difficult to understand it, because
way and can be used in different scenarios, but they are most the same code can be written in many different ways. For
commonly used to build Web applications and for scripting. example, print 11 + 12 + 13 != print (11 + 12) + 13
It has poor documentation for object-oriented paradigms
Perl compared to Python.
Perl is a general-purpose, high-level, dynamic programming In Perl, there are many ways to do the same things.
language. Currently, Perl 5 is the most popular version of it, Sometimes, this creates a problem.
while the latest version is Perl 6. Perl is derived from different It is slow compared to other scripting languages.
languages like C, AWK, Sed and Shell Script.
Perl is most powerful in string manipulation and regular Popularity
expressions. It is very useful while parsing huge amounts of Though Perl has been around for a long time, its growth has
data, line by line or based on specific regex. It is also useful been slow compared to some other languages and, yet, it has
for Web development, systems administration, network survived. Huge community support and built-in modules
programming and game development. make it very popular.
The biggest advantage of Perl is that there are many ways
to do the same thing. But, sometimes, this advantage creates Popular frameworks
problems in terms of resulting in non-structural or bad code style. Catalyst, Dancer, Mojolicious, etc, are some
frameworks that use Perl.
Advantages
Perl is very good at handling regular expressions. Hence, Syntax
it is preferred when there is a lot of work on regex. Shown below is the basic syntax for Perl. The extension for

62 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Insight Developers

Perl files is .pl or .pm, which is based on a file or module: popular frameworks.

#!/usr/bin/perl Syntax
$abc = 10; PHP scripting code is written using the <?php start tag and
print Value of abc = $abc\n; ?> end tag. The file extension is .php, and usually contains
print program is over; PHP scripts and HTML code.

<?php // PHP code ?>


PHP
PHP is also a general-purpose language but is mainly used for Python
Web development. Its a server-side scripting language designed Python is a general-purpose and high-level programming
by Rasmus Lerdorf. It is very popular for small or medium level language designed by Guido van Rossum in the late 1980s.
website development compared to other languages. It is also Its very elegant and easy to learn. Nowadays, a beginners
used by some giant firms like Facebook, YouTube, and Yahoo! first priority is to learn Python. It supports multiple
Nowadays, there are a lot of frameworks built on PHP, which paradigms functional, imperative, procedural and OO
compete with Python and Perl. Though demand for Python is (object oriented). Python is an all-round language. Since
increasing, PHP is still very popular in both small and large its often a first choice, it can be found everywhere. It can
organisations. The current version of PHP is 7.1.2. be used in testing, automation, Web development, data
analytics, cloud computing, mobile development and game
Advantages development. Python uses indentation to identify the block,
Most people prefer PHP when it comes to creating and this eliminates the need for curly brackets and the colon.
dynamic Web pages, because its easier to set-up in Pythons philosophy is different, which is, There is only
local host and most of the hosting providers offer built- one way to do the things and its called the Pythonic way.
in PHP support. The current version of Python is 3.6.0.
Its easy to use. The syntax is mostly the same as the C
language. Anyone can easily adopt it. Advantages
There are lots of frameworks available for PHP and it has One of the best things about Python is that it is well
immense community support. documented.
PHP is stable. Since its used by many developers, code Python is used in 3D animation and game development,
maintenance is very quick. which differentiates it from other languages.
PHP has strong database support and provides native In school, students learn Python quicker than C or C++
session management. because it is easy.
PHP 7 is much faster than any other versions of PHP. Python uses white space indentation, while others use
curly braces. Comparatively, Python code is neater
Disadvantages and cleaner.
Some of the libraries written in PHP are procedural, so Code written in Python is very short compared to other
its difficult for programmers from an object-oriented languages, which demonstrates its power.
background. Python also supports JVM so code written in Python can
Since it is open source, security is the major challenge as easily work with some of the Java objects/APIs.
the code is available to all; hence, intruders can easily find If you are new to programming, learn Python because
weaknesses in the code. by learning this one language, you can easily jump
It becomes slow after a certain scale. Because of this, into any field of interest, whether its automation, Web
large scale organisations use their own customised development, game development or data analytics.
frameworks to increase performance. Python is everywhere.
PHP is not suitable for desktop applications. Besides, its
error handling capabilities are poor. Disadvantages
Indentation is the biggest issue in Python. The code will
Popularity not work and sometimes people get irritated because of it.
PHP is still very popular and is one of the top-10 languages used Python forces programmers to follow a particular
by Web developers to create dynamic websites. Web developers convention.
should definitely learn PHP to kickstart their careers. Its slower compared to older languages like C and C++.
It is also an interpreted language.
Popular frameworks It doesnt perform multi-processor/multi-core work
Laravel, Symfony, CodeIgniter, Phalcon, etc, are some of the efficiently.

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 63


Developers Insight

Popularity you can do wonders in all those segments. So I prefer Python.


Python has been bestowed the TIOBE Programming The most important thing is to learn the Pythonic way of
Language of the Year award in 2007 and 2010. The TIOBE writing a code. Here are a few examples.
index measures the growth and popularity of the language Example 1: The non-Pythonic way of writing a code:
over the period of one year.
def test(a, b):
Popular frameworks a[0] = 2
Django, TurboGears, Web2py, Bottle, CherryPy, Flask, b[0] = 7.5
Pyramid, etc, are some of the popular frameworks. abc = [0]
xyz = [0]
Syntax test(abc, xyz)
Python syntax is very neat and clean. The extension abc = abc[0]
of the file is .py. xyz = xyz[0]

#!/usr/bin/python The Pythonic way of writing the same code:

print "Hello! Welcome to the world of Python!" def test():


return 2, 7.5
So which is the best programming language alpha, beta = foo()
to learn and use?
There is no specific answer to this question because we can Example 2: The non-Pythonic way of writing code:
perform almost all tasks with any of the three languages.
It depends on what you want to do and how you can do it i = 0
efficiently. The answer to this question varies based on the while i < mylistleng:
applications or usage. do(mylist[i])
If Web development is the first priority, then PHP is the i += 1
first preference. For test automation and scripting, Python and
Perl are very popular. There are lots of frameworks available The Pythonic way of writing the same code:
in all three languages, and since community support is good,
you will never be stuck with a particular problem. for i in range(mylistleng):
PHP has lots of popular CMS frameworks available like do(mylist[i])
WordPress, Joomla and Drupal. Any newbie can deploy
websites easily using these frameworks. There are lots of Another Pythonic way of writing the same code:
plugins available for these frameworks and almost all the
major functionalities are covered. Similarly, Python has the for item in mylist:
Django framework, which is very popular and most Python do(item)
lovers use it for Web development.
My advice would be to learn all three languages and use Example 3: A short program for reversing a string is
them based on the situation. Beginners can start with Python shown below:
as it is very easy, and later jump into learning PHP and
Perl, in that order. The basic logic for all the programming 'Hello Python'[::-1]
languages is the same and the only difference is in terms of
the syntax. Usually, the person who knows one language can
easily migrate to another language very quickly. References
These are never ending discussions on all the forums [1] https://en.wikipedia.org/wiki/Perl
about which is the best programming language for career [2] https://wiki.python.org/moin/WebFrameworks
growth. My advice would be to learn one language very well. [3] https://www.python.org/
Pick the one you feel comfortable with and slowly venture [4] https://en.wikipedia.org/wiki/PHP
[5] http://php.net/manual/en/intro-whatis.php
into exploring the other two.
By: Maulik Parekh
My preference
I will go with Python as it is evolving very fast and is easy to The author has an M. Tech degree in cloud computing from VIT
University, Chennai. He can be reached at maulikparekh2@gmail.
learn. The use cases of Python cover a very broad range. It is
com. Website: https://www.linkedin.com/in/maulikparekh2.
used in almost every IT segment and, by learning this language,

64 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Insight Developers

Dart: An Easy, Scalable


and Multi-purpose
Programming Language
If you are looking for an application programming language that is easy to
learn, highly scalable and deployable everywhere, then do try Dart. This article
introduces readers to its exciting array of features.

D
art is a programming language developed at Google. Dart targets
The primary developers behind it are Lark Bak and The Dart code can be executed in four different
Kasper Lund. Dart was first released in October 2011, ways (see Figure 2):
and the latest stable release is version 1.22, which came out The code can be trans-compiled into JavaScript using
in February 2017. The consistent updates to Dart indicate its source-to-source compilation. This is done with the
active development. help of the dart2js compiler. As it can be converted to
Dart is cross-platform and supports all major operating JavaScript, all major browsers support it.
systems. It is open source and available with a BSD licence. It The Dart SDK includes a virtual machine called Dart VM.
is recognised as an ECMA standard. This mode is for standalone execution. The Dart code can
be executed in command line interface mode. The Dart
Objectives of Dart SDK includes a powerful package manager called pub.
According to the official documentation, Dart is a long- The Dart code can be executed in another mode through
term project with ambitious objectives. The core objectives, the Dartium browser. This is a customised Chromium
illustrated in Figure 1, are: Web browser that includes the Dart VM. As this browser
Dart has a strong support base with many libraries and has direct support for Dart code, there is no need to
tools, which enable very large applications. convert it into JavaScript.
One of the major objectives of Dart is to simplify Dart can also be executed in AOT mode. AOT stands for
programming tasks. It is designed to make common Ahead-Of-Time compilation. In this mode, the Dart code
programming tasks simpler. can be directly converted into native machine code.
Dart is very stable and it can be used to build production
quality real-time applications. It is an object-oriented DartPad
programming language with support for inheritance, If you prefer to start writing your first Dart program without
interfaces and optional typing features. any installation or configuration, then DartPad is the right

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 65


Developers Insight

Dart execution
modes

Trans-Compile in Stand-alone via Dartium Browser AOT Compilation


to JavaScript DartVM

Figure 2: Dart execution modes


Figure 1: Darts objectives

choice for you. It can be downloaded from https://dartpad.


dartlang,org. The DartPad interface is plain and simple.
Write your code and click Run to execute the code. The
output is also shown within the DartPad window itself, as
shown in Figure 3.
DartPad introduces users to the world of Dart
programming. The support for libraries in DartPad is
restricted to the basic level. To include various libraries, users
can have a local installation of the Dart SDK.

A simple Dart program


Shown below is a simple Dart program with a user Figure 3: DartPad execute your Dart programs
defined function:
types, as listed below:
// Define a function. Numbers
printOSFYIssueNumber(num aNumber) { Strings: These are sequences of UTF-16 code units.
print('Welcome to the OSFY issue Number $aNumber.'); // Strings can be provided with either single quotes or
Print to console. double quotes.
} Booleans: These are provided with the bool keyword.
Lists: These are used to specify arrays, for example,
// This is where the app starts executing. var list = [100,200,300]
main() { Maps: These are used to associate keys with values. For
var issuenumber = 12; // Declare and initialize a variable. example:
printOSFYIssueNumber(issuenumber); // Call a function.
} var OSFYThemes = {
// Keys Values
main() is the function that the application execution 'Jan' : 'Mobile Computing',
starts from. This sample program initialises a variable and 'Feb': 'Networking',
calls a user defined function printOSFYIssueNumber(). The 'Mar' : 'Programming Lang'
function takes one numeric argument. In the function, the };
type of the argument is num. In Dart, num denotes the
number type. There are two sub-types to num. These are Runes: In Dart, runes are UTF-32 code points of a
int and double. string. As stated earlier, Dart strings are UTF -16. For
As you might have observed, the function definition doesnt expressing the 32-bit Unicode values, a specific syntax is
require any specific keyword. It merely involves the use of the adopted. An example of how runesare used follows:
function name and the optional arguments. The object-oriented
attribute has been given emphasis in the design of the Dart main() {
programming language. The functions are objects in Dart. They var clapping = '\u{1f44f}';
belong to a type called Function. What this implies is that the print(clapping);
functions can also be assigned to other variables, and they can print(clapping.codeUnits);
be supplied as arguments to other functions. print(clapping.runes.toList());
The comments are prefixed with //. The print() function }
is used to output the value to the user.
The Dart programming language supports various data Symbols: The Symbol object in Dart is used to represent

66 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Insight Developers

an operator or identifier used in a Dart program. is provided at https://webdev.dartlang.org/guides/get-started.


Another interesting feature of Dart is Method
Cascading. To perform this, the operator used is ... It is the Dart mobile apps
double dot operator. Dart mobile apps are built using Flutter, which is a SDK for
An overview of the Dart programming constructs is building mobile apps. For iOS and Android, the apps can
provided at https://www.dartlang.org/guides/language/ be built with a single codebase. Apps built using Flutter are
language-tour. high-performance and high-fidelity. The major advantages of
As stated in the beginning of this article, Dart is a building mobile apps with Flutter are as follows:
general-purpose programming language. It is used to build iOS and Android apps can be built using the same
applications belonging to various types. The three major types codebase.
of apps that can be built with it are listed below: Prototyping is comparatively simpler.
Dart Web apps The apps are built with highly customised user
Dart Mobile apps experiences. The material design widgets for the Flutter
Dart Server (or command line) apps framework are handy. The custom designs can also be
implemented using OEM widget sets.
Dart Web apps Flutter includes the following components:
As per the official documentation (https://webdev.dartlang. A functional reactive framework
org/), Google uses Dart for building critical Web apps. It is A 2D rendering engine
utilised with AngularDart. Googles internal CRM is also built Ready-to-use widgets
using Dart. Apart from the search giant, many other reputed Development tools
companies also use Dart for their critical Web apps. In the application development model of Flutter,
In the case of Dart Web apps, the contents of the HTML everything is a widget. Flutter has a unified object
elements can be manipulated dynamically from Dart code. A model in which all components are widgets. In Flutter
simple countdown timer code follows. terminology, a widget can be used to define all of the
following: structural elements, style elements, layout, and
In HTML, type: even the business logic.

<h1 id="countdown"></h1> Fundamental Dart libraries


The three most fundamental Dart libraries are listed below:
In Dart, type: dart:core - All basic functionalities of Dart such as
import 'dart:html'; strings, collections, dates and URIs are processed
using this library.
main() async { dart:html - This library is the wrapper for DOM
var countdown = querySelector("#countdown"); manipulation which is much used with Web apps.
for (int i = 100; i >= 0; i--) { dart:io - This library is used with command line apps.
countdown.text = "Time: $i"; The libraries in Dart are imported with the help of
await window.animationFrame; import, as shown below:
}
} import 'dart:html';
import 'dart:math';
Place this code in DartPad and click Run. In the output
window (HTML), you will notice the countdown from 100 to 0. Apart from the above-mentioned core libraries, there are
The HTML element <h1> is accessed with the querySelector() various other libraries. Some of them are listed below:
function. Here, the id is supplied as input. Then the contents are dart:async - This is a library that supports asynchronous
dynamically modified by using the text attribute. programming.
The dart:html library is utilised in the above program. It dart:developer - This library is used for interacting with
is a wrapper around the DOM (Document Object Model) and developer tools such as the debugger and inspector.
Window API. Due to the availability of this wrapper library, dart:js - This library provides support for interoperating
the developer need not worry much about browser support. with JavaScript.
Important advantages of building Web apps with Dart are: dart:svg This is used to handle support vector graphics.
The Dart SDK is of production quality. It is stable dart:web_audio - This is used to perform audio
and maintained. programming in the browser.
With Angular, Dart becomes a powerful combination. dart:web_gl This is to perform 3D programming
Detailed information regarding building Web apps with Dart in the browser.

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 67


Developers Insight

dart:web_sql - This provides an API for storing the data, tools such as pub build (for building a Web app) and pub
which can be manipulated with SQL. serve (for serving a Web app) can also be used.
There are a few other important Dart tools such as:
Dart pub Dartanalyzer - This tool is used to evaluate and report
The package manager of Dart is called pub. The potential errors in your Dart code.
Dart applications specify the pubspec, which lists the Dartfmt - This tool is for formatting the Dart code.
dependencies for that application. For example: The official Dart style guide is followed while
formatting the code.
name: my_app To summarise, Dart is an interesting programming
dependencies: language with features to facilitate Web, mobile and
js: ^0.3.0 command line apps. Its major advantages are its stability
intl: ^0.12.4 and support base. The SDK is constantly updated and,
at the same time, is very stable. In the case of Web
After the specification of pubspec, navigate to that applications, the combination with AngularDart makes it
directory and execute pub get as shown below: a very powerful tool. The mobile application development
platform, Flutter, enables the building of apps for both
cd <path-to-app> Android and iOS from the same codebase. Overall, Dart is
pub get a programming language that is easy to learn, and it enables
the developer to build various types of apps.
The dependencies can be upgraded later with the
following command:
References
$ pub upgrade
[1] DartPad: https://dartpad.dartlang.org/
[2] Dart Language basics: https://www.dartlang.org/guides/
The Dart tools language/language-tour
In this article, the code written in Dart is executed using [3] Dart SDK: https://api.dartlang.org/stable/1.22.1/index.html
[4] Dart Package Manager Pub: https://www.dartlang.org/
DartPad. However, as stated earlier, for advanced tasks,
tools/pub/get-started
it would be better to have an IDE installed in the local
machine. The official documentation has recommended the
By: Dr K.S. Kuppusamy
WebStorm IDE.
In the case of Web app development, the Dartium browser The author is an assistant professor of computer science at
the Pondicherry Central University, with more than 11 years of
can be used. The Dartium browser download is available in teaching and research experience in academia and industry.
the link: https://webdev.dartlang.org/tools/dartium. He can be reached via mail at kskuppu@gmail.com.
Apart from the Dartium browser, the other command line

Read more stories on Components in


www.electronicsb2b.com
TOPCOMPONENTS STORIES
The latest in power co
nverters
ELECTRONICS

ent distributors
Indias leading compon
ry
onics components indust
Growth of Indian electr INDUSTRY IS AT A
components for LEDs
The latest launches of
ics
components for electron
The latest launches of

Log on to www.electronicsb2b.com and be in touch with the Electronics B2B Fraternity 24x7

68 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Insight Developers

Python: The User


Friendly Language
for Coding

This article will delight newbies who want to get a foothold in the
programming world. It introduces readers to the fascinating world of
Python, which is a very versatile programming language.

C
omputers, today, come with immense disk space, of hardware with the same user interface; it is scalable,
multi-core processors and high speed Internet supporting very large programs; and it has user interfaces
connectivity. And they use computer languages that for UNIX, Windows and Mac. It also has efficient high-
interact with the operating system and execute processes at level data structures and extensive standards-free libraries,
a high speed. One such language is Python, which is used as which make programming easy; hence, it is considered the
a high level programming language. It was first released in language for beginners.
1991 by Guido van Rossum, an ex-employee of Google. It In this article, we will learn how to install, set up and use
is quite easy to learn, as it uses English keywords frequently, Python. The cool thing about learning Python is that there are
unlike the heavy syntaxes of other languages. Moreover, no prerequisites. Even if you are a novice to programming
programmers can code the logic using fewer lines of code you can become a pro coder within a month. To start with,
than what is required in other programming languages like download and install Python from https://www.python.org/
C or Java. The unique design, notably, using white space downloads/release/python-2712/. For this article, we are using
indentation to delimit code blocks, makes Python more Python 2.7. The above link also contains Python for Windows
readable and clean. and Mac. On most Linux boxes, Python is pre-installed.
Python is an interpreted, interactive and object-oriented For Windows, download Python and run the .msi file. Upon
scripting language. The Python code is processed by the completion, add the environment variable named 'PYTHON'
processor at run time, i.e., it does not need to be compiled and its value as the directory where Python is (in this case,'C:\
as in Java, which is compiled to get the .class file. The term Python27'), as shown in Figure 1. We can verify whether
interactive implies that you can use the Python prompt to Python has been installed correctly by running the python -
write the code, which interacts with the interpreter, and version command in the command line. This will give you
by encapsulating the code within objects, it follows the the current version of Python running on your computer, as
OOPS principle. The other features that make Python cool shown in Figure 2. To create Python files, use any text editor
are that it is extendable, i.e., it can run on a wide range of your choice. For this article, we will be using the Sublime

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 69


Developers Insight

Class, def, if, else, elif, etc. Unlike Java or C, which use
braces to wrap lines of code, Python uses indentation
to denote the block of code that is tightly mapped. In
Python, statements usually end with a new line, but if the
statement gets carried to the new line, then one uses the
\ backslash to show the continuation of the line. A single
line comment is denoted by # and a multi-line comment
can be wrapped in triple quotes.
The data types used in Python are numbers, strings, lists,
tuples and the dictionary. The number data type stores the
numeric value and is immutable in nature, i.e., upon changing
Figure 1: Setting the environment variable the value, a new object is created and the older one is kept
for automatic garbage collection. For example, variable =
10. The single quote or double quotes are used to denote the
string. For example, varA = Hello World, varB = Python
is cool. Python does not support character types, but treats
the characters as strings of length one. Coming to the list, it
consists of comma-separated values which could be of any
Figure 2: Checking the correct installation of Python and its version type and it is represented as [,,,,]. All values are enclosed
between '[' and ']'. A list object is a mutable data type, which
text editor, which can be downloaded from https://www. means it can't be hashed, and modifying an existing list
sublimetext.com/3. will not result in a new list objectthe memory address
The clich of programming languages is Hello World; so will not be changed either. For example: def_list = [1,
lets get started by printing it in the console. Open the command 2,"1","100","Python","Anne"].
prompt, type Python and execute it. Now run the command: The next is a tuple, which has comma-separated
values that could be of any type, enclosed between '('
print (Hello world). and ')'. This, too, is an immutable data type and can be
used as the key in a dictionary. For example: def_tuple =
This will print Hello World in the console as shown (1,2,"1","100","Python","Anne"). The dictionary in Python
in Figure 3. Python, being a scripting language, can also be contains the key value pair in which the key is immutable,
executed by writing a group of individual statements, which and the value can be anything; the key value is separated by
make a single code block called a suite in a file, and can be a colon :. Dictionaries work on the hashing principle. For
saved with the .py extension. example: dictB = dict(). Let us now create a new file in the
Now lets learn about the building blocks of Python, like Sublime text editor with the following commands:
the identifiers, keywords, user input processes, comments, etc.
Identifiers are the names given to classes, variables, functions, # An Empty Dict
etc. These are case sensitive and start with the letters A-Z, dictA = dict() # same as dictA = {}
a-z or an underscore. There are some naming conventions in dictB = dict() # same as dictB = {}
Python, which are listed below: # Adding values to it
An identifier starting with an underscore means that its for i in [1,3,2,4,8,9,5,6,7]:
private, and a double underscore means it is strongly private. dictB[i] = i
The class name must start with upper case. Python # Adding values to a dict
has some reserved words called keywords which have
special meanings. Examples of keywords are and, finally, # Let us use a simple for loop to add values to a dict
for i in xrange(10):
dictA[i] = i + 10
print dictA,'\n\n',dictB,'\n\n'

'''
Define a simple list with multiple datatypes
'''
def_list = [1,2,"1","100","Python","Anne","A!@345<>_()",True,
False,{1:100,2:200,3:300},range(10)]
Figure 3: Getting started with printing Hello World

70 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Developers Insight

#Now create a variable


vara = def_list
#Modification of vara will result in modifying def_list
vara.append("Hero")
print "Address of vara and def_list %s and %s
"%(id(vara),id(def_list)),'\n\n'
print "vara = %s "%(vara),'\n\n'
print def_list = %s %(def_list),\n\n

# Define a simple tuple with multiple datatypes


def_tuple = 1,2,1,100,Python,Anne,A!@345<>_(),True, Figure 5: Outcome of executing the PythonPractice.py file
False,{1:100,2:200,3:300},range(10)
# Print and view the tuple There are a few rules for writing the function, which are:
print Printing the tuple - , def_tuple, \n\n a) It begins with the def keyword, followed by the name
print Printing the tuples address - , id(def_tuple),\ and parentheses, which can be used to pass the input
n\n# The address is subject to change parameters.
b) A code block within every function starts with a colon
Once this is done, save the file with the .py extension. In this (:) and is indented. A simple example of a function is
case, it is saved as PythonPractice.py. In the command prompt, shown below:
browse to the location where the file is saved and execute the
command Python PythonPractice.py (shown in Figure 4); this #A Function to print the sum of numbers
displays the result on the console (as shown in Figure 5). def funcA(a,b,c):
Python is famous for its functional programming. A #Add a,b,c and return the result
function is a block of organised, reusable code that is used to sum_numbers = a + b + c
perform a task. It provides better modularity because of the return sum_numbers
ability to be reused.
This can be called by executing print funcA(100,200,300),
which prints the result 600 in the console.
There are many other useful features of Python like
modules, inheritance, multi-processors, exceptions, file input
and output, all of which make Python a high level and easy
programming language. Python also has classes and objects,
multi-threading, database access, networking, emails and
many more features, which can be learned while exploring
the advanced features.

By: Ashish Kumar Sinha


The author is a software engineer based in Bengaluru. A software
enthusiast at heart, he is passionate about using open source
technology and sharing it with the world. He can be reached at
ashi.sinha.87@gmail.com. Twitter handle: @sinha_tweet.
Figure 4: A Python file to test the dictionary, list and tuples

Your favourite Magazine on Open


Source is now on the Web, too.

OpenSourceForU.com
Follow us on Twitter@LinuxForYou

72 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Overview Developers

An Introduction to HTML5
HTML5, the fifth and current version of the HTML standard, is a markup
language used to structure and present content on the World Wide Web.
This article will help readers get acquainted with it.

H
TML5 has evolved through the cooperation between like Silverlight and Flash.
the W3C and the Web Hypertext Application
Technology Working Group. It is a higher version of New tags and elements
HTML, and its many new elements make your pages more Semantic elements: Figure 1 displays a few useful
semantic and dynamic. It was developed to provide a greater semantic elements.
Web experience for everyone. HTML5 offers great features Form elements: The form elements present in HTML5
that make the Web more dynamic and interactive. are shown in Figure 2.
The new features of HTML5 are: Graphic elements: The graphic elements in HTML5 can
New sets of tags such as <header> and <section> be seen in Figure 3.
<canvas> element for 2D drawing Media elements: The new media elements in HTML5 are
Local storage listed in Figure 4.
New form controls like calendar, date and time
New media functionality Advanced features of HTML5
Geo-location
HTML5 is not an official standard as yet; hence, not all Geo-location
browsers support it or some of its features. One of the most It is an HTML5 API that is used to get the geographical
important reasons behind developing HTML5 was to prevent location of a websites user, who has to first permit the site
users from having to download and install multiple plugins to fetch his or her location. This usually happens via a button

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 73


Developers Overview

Job postings can automatically include commute times


How it works: Geo-location works by scanning common
sources of location information, which include the following:
Global Positioning System (GPS), which is the most
accurate
Network signalsIP address, RFID, Wi-Fi and Bluetooth
MAC addresses
GSM/CDMA cell IDs
User inputs
The API offers a very handy function to detect geo-
location support in browsers:

if (navigator.geolocation) {
// do stuff
}
Figure 1: Semantic elements
The getCurrentPosition API is the main method for using
geo-location. It retrieves the current geographic location
of the users device. The location is described as a set of
geographic coordinates along with the heading and speed. The
location information is returned as a position object.
The syntax is:

Figure 2: Form elements getCurrentPosition(showLocation, ErrorHandler, options);

showLocation: This defines the callback method that


retrieves location information.
ErrorHandler(Optional): This defines the callback method
that is invoked when an error occurs in processing the
Figure 3: Graphic elements asynchronous call.
options (Optional): This defines a set of options for
retrieving the location information.
Figure 5 incorporates the set of properties returned by a
position object.
We can present location information to the user in two
waysgeodetic and civil:
1. The geodetic way of describing a position refers directly
to the latitude and longitude.
2. The civic representation of location data is readable and
Figure 4: Media elements easily understood by humans.

and/or browser popup. All the latest versions of Chrome,


Firefox, IE, Safari and Opera can use the geo-location
feature of HTML5.
Some uses of geo-location are:
Public transportation websites
Taxi and other transportation websites
To calculate shipping costs on an e-commerce site
Travel agency websites
Real estate websites
Movie theatre websites can find movies playing nearby
Online gaming
For sites to feature local headlines and weather on
their front page Figure 5: Position object properties

74 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Overview Developers

As shown in Table 1, each attribute/parameter has both Results in less load for servers
a geodetic representation and a civic representation. The cache manifest file is a simple text file that lists the
resources the browser should cache for offline access. The
Table 1 manifest attribute can be included on the documents HTML
Attribute Geodetic Civic tag, as follows:
Position 59.3, 18.6 Stockholm
Elevation 8 metres Third floor <html manifest=test.appcache>
Heading 142 degrees To the city ...
Speed 12 km/h Running </html>
Orientation 55 degrees North-West
It should be on all the pages that you want to cache.
Web storage
In HTML, to store user data on a local machine, we were The application pages that are cached will remain unless:
using JavaScript cookies. To avoid that, HTML5 has 1. The user clears them out.
introduced Web storage, with which websites themselves 2. The manifest has been modified.
store user data on a local machine. 3. The cache is updated.
The advantages of Web storage, as compared to
cookies, are: Video
More secure Until HTML5 was launched, there was no uniform standard
Faster for showing video on Web pages. Most of the videos were
Stores a larger amount of data shown through different plugins like Flash. But HTML5
The stored data is not sent with every server request. specifies a standard way to show the video on a Web page by
It is only included when asked for. This is a big using a video element.
advantage of HTML5 Web storage over cookies. Currently, it supports three video formats for the video
There are two types of Web storage objects: element, as shown in Table 2.
1) Local this stores data with no expiration date.
2) Session this stores data for one session only. Table 2
How it works: The localStorage and sessionStorage Format IE Firefox Opera Chrome Safari
objects create a key = value pair. Ogg No 3.5+ 10.5+ 5.0+ No
An example is: key=Name, value=Palak MPEG4 No No No 5.0+ 3.0+
These are stored as strings but can be converted, if
WebM No No 10.6+ 6.0+ No
required, by using JavaScript functions like parseInt() and
parseFloat().
Given below is the syntax for using Web The example given below shows the use of this video
storage objects: element:

Storing a Value: <! DOCTYPE HTML>


localStorage.setItem(key1, value1); <html>
localStorage[key1] = value1; <body>
Getting a Value:
alert(localStorage.getItem(key1)); <video src= vdeo.ogg width=320 height=240
alert(localStorage[key1]); controls=controls>
Remove a Value:
removeItem(key1); This browser does not support the video element.
Remove All Values:
localStorage.clear(); </video>

Application Cache (AppCache) </body>


Using HTML5 Apache, we can make a Web application </html>
work offline without an Internet connection. All browsers,
besides IE, can use AppCache (at this point in time). This example uses an Ogg file, and will work in
The advantages of Application Cache are: Firefox, Opera and Chrome. To make the video work in
Enables browsing Web pages offline Safari and future versions of Chrome, we must add an
Pages load faster MPEG4 and WebM file.

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 75


Developers Overview

The video element allows multiple source elements. <source src=song.mp3 type=audio/mpeg />
Source elements can link to different video files. The browser
will use the first recognised format, as follows: This browser does not support the audio element.

<video width=320 height=240 controls=controls> </audio>


<source src=vdeo.ogg type=video/ogg />
<source src= vdeo.mp4 type=video/mp4 /> Canvas
<source src= vdeo.webm type=video/webm /> To create graphics on a Web page, HTML5 uses the Canvas
This browser does not support the video element. API. We can draw anything with it and it uses JavaScript.
</video> This can improve the performance of our website by avoiding
the need to download images off the network. With Canvas,
Audio we can draw shapes and lines, arcs and text, gradients and
With audio, the case is similar to video. Until HTML5 was patterns. In addition, Canvas gives us the power to manipulate
launched, there wasnt any uniform standard for playing pixels in the images and even in video. You can add the
audio on Web pages. Most of the audio was also played Canvas element to an HTML page as shown below:
through different plugins like Flash. But HTML5 specifies a
standard way to play audio on a Web page by using an audio <canvas id=myCanvas width=200 height=100></canvas>
element. The audio element is used to play sound files and to
stream audio. The Canvas element doesnt have capabilities to draw
Currently, HTML5 supports three audio formats for the elements. We can achieve this by using JavaScript. All
audio element, as shown in Table 3. drawings should be inside JavaScript.

Table 3 <script type=text/javascript>


Format IE 8 Firefox Opera Chrome Safari var c=document.getElementById(myCanvas);
3.5 10.5 3.0 3.0 var cxt=c.getContext(2d);
Ogg No Yes Yes Yes No cxt.fillStyle=blue;
Vorbis cxt.storkeStyle = red;
MP3 No No No Yes Yes cxt.fillRect(10,10,100,100);
Wav No Yes Yes No Yes cxt.storkeRect(10,10,100,100);
</script>
The use of the audio element is demonstrated below:
The output of the above script is seen in Figure 6.
<! DOCTYPE HTML>
<html>
<body>

<audio src= song.ogg controls=controls>

This browser does not support the audio element.

</video>

</body>
</html>

This example uses an Ogg file and will work in Firefox,


Opera and Chrome. To make the audio work in Safari and
future versions of Chrome, we must add an MP3 and Wav file. Figure 6: Output of Canvas
The audio element allows multiple source elements,
which can link to different audio files. The browser will use You can draw many objects like arcs, circles, linear/
the first recognised format, as follows: vertical gradients, etc.

<audio controls=controls> HTML5 tools


<source src=song.ogg type=audio/ogg /> To operate effectively, all skilled or amateur Web developers/

76 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Overview Developers

designers should use HTML5 tools, which are a great help Adobe Edge Animate: This is a useful tool for HTML5
when one needs to set up workflows/websites or perform developers who have to deal with interactive HTML
repetitive tasks. They improve the usability of Web animations. It is used in digital publishing, the Web and in
designs. Featured below are some essential tools which the advertising fields. This tool allows users to create flawless
help in creating amazing websites. animations, which run across multiple devices.
HTML5 Maker: This is used to interact with content in Video.js: This is a HTML5 video player based on JavaScript.
websites with the help of HTML, JavaScript and CSS. It is If you want to add videos to your website, you should use this
very easy to use. It also allows us to develop slide shows, tool. It makes videos look good and a part of the website.
sliders, HTML5 animation and more. The W3 Validator: The W3 Validator tests the validity of
Liveweave: This is used to test the code. It cuts down the markup of websites in HTML, XHTML, SMIL, MathML,
on the time spent on saving the code and loading it on etc. To test the markup validity of any website, you have to
screen. Pasting the code in the editor gives instant results. choose the document type as HTML5 and enter your Web
It is very easy to use and also provides the auto-complete pages URL. By doing this, your code will get checked, and
feature for some of the code, which makes development all errors and warnings will be mentioned.
and testing faster and easier. HTML5 Reset: This tool allows developers to rewrite the
Font dragr: This previews the custom Web fonts in code of their old websites in HTML5.
a browser. It loads the font instantly, so you get to know You can use these tools to provide a great Web experience
whether it looks good or not. It also offers a drag-and-drop for visitors to your website.
interface, allowing you to drop your typefaces, Web open
fonts and vector graphics to test all of them immediately.
HTML5 Please: This allows us to find anything References
related to HTML5. If you want to know how to use any [1] https://www.w3schools.com/html/html5_intro.asp
feature, you can search for it on HTML Please. It provides [2] http://www.html-5-tutorial.com/
lists of useful resources about supporting browsers and [3] https://www.tutorialspoint.com/html5/
devices, syntax, general recommendations of how to use [4] https://www.udemy.com/learn-html5-programming-
from-scratch/learn/v4/overview
the element, etc.
Modernizr: This is an open source tool which is used
to provide the best experience possible, given the visitors By: Palak Shah
browser. With this tool, you can detect whether the The author is a senior software engineer. She loves to explore
visitors browser supports HTML5 features, and load the new technologies, learn innovative concepts, and is also fond
of philosophy. She can be reached at palak311@gmail.com.
scripts accordingly.

oSFY Magazine Attractions During 2017-18


Month theMe
March 2017 Open Source Firewall, Network security and Monitoring

April 2017 Databases management and Optimisation

May 2017 Open Source Programming (Languages and tools)

June 2017 Open Source and IoT

July 2017 Mobile App Development and Optimisation

August 2017 Docker and Containers

September 2017 Web and desktop app Development

October 2017 Artificial Intelligence, Deep learning and Machine Learning

November 2017 Open Source on Windows

December 2017 BigData, Hadoop, PaaS, SaaS, Iaas and Cloud

January 2018 Data Security, Storage and Backup

February 2018 Best in the world of Open Source (Tools and Services)

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 77


Developers Overview

Top IDEs for Raspberry Pi


The Raspberry Pi, a tiny single-board computer, has revolutionised the way in which
computer science is being taught in schools. It has also turned out to be a boon
for software developers. Currently, it has gained popularity much beyond its target
market and is being used in robotics projects.

R
aspberry Pi, a small development board Raspberry Pi 3 Model B was launched, which is currently
minicomputer that runs the Linux operating the main product available. In 2017, the Foundation released
system, was developed in the United Kingdom the updated model of Raspberry Pi Zero named Raspberry Pi
by the Raspberry Pi Foundation to promote the teaching Zero W (W = wireless).
of basic computer science in schools in the UK and in In the near future, a model that has improved technical
developing countries. Raspberry Pi has USB sockets, specifications will arrive, offering a robust platform for
which support various peripheral plug-and-play devices embedded systems enthusiasts, researchers, hobbyists and
like the keyboard, the mouse, the printer, etc. It contains engineers to use it in multi-functional ways to develop real-
ports like HDMI (High Definition Multimedia Interface) time applications.
to provide users with video output. Its credit-card-like size
makes it extremely portable and affordable. It requires just Raspberry Pi as an efficient programming device
a 5V micro-USB power supply, similar to the one used After getting the Pi powered up and the LXDE WM up
to charge a mobile phone. and running, the user gets a full-fledged Linux box running
Over the years, the Raspberry Pi Foundation has released a Debian based operating system, i.e., Raspbian. The
a few different versions of the Pi board. The first version was Raspbian operating system comes with tons of free and open
Raspberry Pi 1 Model B, which was followed by a simple and source utilities for users, covering programming, gaming,
cheap Model A. In 2014, the Foundation released a significant applications and even education.
and improved version of the board Raspberry Pi 1 Model The official programming language of Raspberry Pi is
B+. In 2015, the Foundation revolutionised the design of the Python, which comes preloaded with the Raspbian operating
board by releasing a small form factor edition costing US$ system. The combination of Raspberry Pi and IDLE3,
5 (about ` 323) called Raspberry Pi Zero. In February 2016, a Python integrated development environment, enables

78 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Overview Developers

New Class...

Parser

Game
Compile

Command

Room

Parser1: room1:
Parser Room
Figure 1: Raspberry Pi
Creating object.. Done.

programmers to develop all sorts of Python based programs. Figure 2: The BlueJ GUI interface
In addition to Python, various other languages are
supported by Raspberry Pi. A number of IDEs (integrated BlueJ provides an efficient way for learning object-
development environments) that are free and open source oriented programming concepts and the GUI provides a class
are also available. These allow programmers, developers structure for applications like UML diagram. Every OOPS
and application engineers to develop programs and based concept, like class, objects and function calling, can be
applications on Pi. represented via interaction based design.

Top IDEs for Raspberry Pi Features


As a programmer and developer, the first thing you require Simple and interactive interface: The user interface is
is an IDE, which is regarded as a comprehensive software simple and easy to learn as compared to other professional
suite that integrates the basic tools that developers and interfaces like NetBeans or Eclipse. Developers can focus
programmers require to write, compile and test their software. mainly on programming rather than the environment.
An IDE contains a code editor, a compiler or interpreter and Portable: BlueJ supports multiple platforms like
a debugger, which the developer can access via a graphical Windows, Linux and Mac OS X, and can even run
user interface (GUI). One of the main aims of an IDE is to without any installation.
reduce the configuration necessary to piece together multiple New innovations: BlueJ IDE is filled with innovations in
development utilities, and provide the same set of capabilities terms of the object bench, code pad and scope colouring,
as a cohesive unit. which makes development fun even for newbies.
An IDEs user interface is similar to that of a word Strong technical support: BlueJ has a hard-core functioning
processor, for which tools in the toolbar support colour- team that responds to queries and offers solutions to all
coding, formatting of source code, error diagnostics, sorts of developer problems within 24 hours.
reporting and intelligent code completion. IDEs are designed Latest version: 4.0.1
to integrate with third-party version control libraries like Official website: https://www.bluej.org/
GitHub or Apache Subversion. Some IDEs are dedicated to
a particular programming language, allowing a feature set Geany IDE
that matches the programming language, while some support Geany IDE is regarded as a very lightweight GUI based text
multiple languages. editor that uses Scintilla and GTK+ with IDE environment
Raspberry Pi has a wide range of IDEs that provide support. The unique thing about Geany is that it is designed to
programmers with good interfaces to develop source code, be independent of a special desktop environment and requires
applications and system programs. only a few dependencies on other packages. It only requires
Lets explore the top IDEs for Raspberry Pi. GTK2 runtime libraries for execution. Geany IDE supports
tons of programming languages like C, C++, C#, Java,
BlueJ HTML, PHP, Python, Perl, Ruby, Erlang and even LaTeX.
BlueJ is an IDE that is dedicated to the Java Programming
Language and was mainly developed for educational Features
purposes. It also supports short software development Auto-completion of code and simple code navigation.
projects. Michael Kolling and John Rosenburg at Monash Efficient syntax highlighting and code folding.
University, Australia, started BlueJ development in 2000 as a Supports embedded terminal emulator, and is highly
powerful successor to the Blue system, and BlueJ became free extensible and feature-rich since lots of plugins are
and open source in March 2009. available for free download.

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 79


Developers Overview

Simple project management and supports multiple file AlgoIDE


types, which include C, Java, PHP, HTML, Python, Perl, AlgoIDE is a combination of a scripting language and an
and many more. IDE environment, designed to function together to take
Highly customised interface for adding or removing programming to the next paradigm. It incorporates a powerful
options, bars and windows. debugger, real-time scope explorer and executes the code,
Latest version: 1.30.1 step by step. It is basically designed for all age groups to
Official website: http://www.geany.org design programs and do extensive research on algorithms.
It supports various types of languages like C, C++, Python,
Java, Smalltalk, Objective C, ActionScript, and many more.

Features
Automatic indentation and completion of source code.
Effective syntax highlighting and error management.
Contains a debugger, scope explorer and dynamic help
system.
Supports GUI and traditional Logo programming
language Turtle for the development of source code.
Latest version: 2016-12-08 (when it was last updated)
Official website: http://www.algoid.net/

Figure 3: The Geany IDE GUI interface

Adafruit WebIDE
Adafruit WebIDE provides a Web based interface for
Raspberry Pi users to perform programming functions, and
allows developers to compile the source code of various
languages like Python, Ruby, JavaScript and many others.
Adafruit IDE allows developers to put the code in a GIT
repository, which can be accessed anywhere via GitHub.

Features Figure 5: The AlgoIDE GUI interface


Can be accessed via Web browser on ports 8080 or 80.
Supports the easy compilation and running of source code. Ninja IDE
Bundled with a debugger and visualiser for proper Ninja IDE (Not Just Another IDE), which was designed
tracking, the navigation of code and to test source code. by Diego Sarmentero, Horacio Duranm Gabriel Acosta,
Official website: https://learn.adafruit.com/webide/overview Pedro Mourelle and Jose Rostango, is written purely in
Python and supports multiple platforms like Linux, Mac
OS X and Windows, for execution. It is regarded as a
cross-platform IDE software, especially designed to build
Python based applications.
Ninja IDE is very lightweight and performs various
functions like file handling, code locating, going to lines, tabs,
automatic indentation of code and editor zoom. Apart from
Python, several other languages are supported by this IDE.

Features
An efficient code editor: Ninja-IDE is regarded as
the most efficient code editor as it performs various
functions like code completion and code indentation, and
Figure 4: The Adafruit WebIDE GUI interface functions as an assistant.

80 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Overview Developers

Errors and PEP8 finder: It highlights static and PEP8 IDE through Lazarus package files.
errors in the file. Makes use of Free Pascal, which is highly enhanced
Code locator: With this feature, quick and direct access with new features and is even used in Android app
to a file can be made. The user can just make use of the development.
CTRL+K shortcut to type anything, and the IDE will Highly extensible, open source and supports various
locate the specific text. frameworks to compile additional languages.
Its unique project management features and tons of Latest version: 1.6.4
plugins make Ninja-IDE highly extensible. Official website: http://www.lazarus-ide.org
Latest version: 2.3
Official website: http://ninja-ide.org

Figure 7: The Lazarus IDE GUI interface

Codeblock IDE
Codeblock IDE was written in C++ using wxWidgets as a
GUI toolkit and was released in 2005. It is a free, open source
and cross-platform IDE supporting multiple compilers like
Figure 6: The Ninja IDE GUI interface GCC, Clang and Visual C++.
Codeblock IDE is highly intelligent and performs various
Lazarus IDE functions like Syntax highlighting, code folding, code
Lazarus IDE was developed by Cliff Baeseman, Shane completion and indentation, and has a number of external
Miller and Michael A. Hess in February 1999. It is regarded plugins for varied customisations. It can run on Windows,
as a cross-platform GUI based IDE for rapid application Mac OS X and Linux operating systems.
development, and it uses the Free Pascal Compiler. It Features
inherits three primary featurescompilation speed, Supports multiple compilers like GCC, Visual C++,
execution speed and cross-compilation. Applications can be Borland C++, Watcom, Intel C++ and many more.
cross-compiled from Windows to other operating systems Basically designed for C++, but today supports
like Linux, Mac OS X, etc. many languages.
This IDE consists of the Lazarus component library, Intelligent debugger, which allows users to debug
which provides varied facilities to developers in the form of programs via access to the local function symbol and
a single and unified interface with different platform-specific argument display, user defined watches, call stack,
implementations. It supports the principle of Write once and custom memory dump, thread switching and GNU
compile anywhere. debugger interface.
Supports varied features for migrating code from
Features Dev-C++, Visual C++ and others.
Powerful and fast enough to handle any sort of source Makes use of custom-built systems and stores information
code, and supports performance testing. in XML extension files.
Easy to use GUI, which supports drag-and-drop Latest version: 16.01
components. Additional components can be added to the Official website: www.codeblocks.org

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 81


Overview Developers

Using State Machines


to Build Better Software
Often, an application runs in an environment of asynchronous, unordered and
unpredictable events and the software needs to be robust enough to work
seamlessly under these conditions. In this article, targeted at software designers
and developers, we explore the benefits of using state machines to make robust
software and the open source options available for this purpose.

SMC

A
lmost every software becomes complex as it evolves In this article, we look at the benefits of using state
over a period of time, and can therefore suffer from machines for modelling software along with some
frequent non-functional problems. These problems examples, and see what the open source world has
are linked to its maintainability, code manageability, to offer in this space.
extensibility, modifiability, determinism, etc. However, a
good plan and design carved out at the initial stages could Benefits of state machines
help developers enjoy the smoothness of the development Some of the benefits of adopting state machines are listed below.
process, as the software matures over a period of time. A complex problem can be broken down into smaller and
The use of state machines is one of the oldest and manageable pieces called states, with each state being
best known techniques for modelling the behaviour of delegated a narrowly defined task. Modelling the system
a system. And its adoption dates way back to the study with a state machine ensures a self-documenting and
of physical matter. As a reference, water (H20) can exist compact representation of the software that automatically
in three different states solid, liquid and gaseous satisfies non-functional demands like manageability,
and in each state it exhibits a specific behaviour; also, extensibility, modifiability and determinism. It might
there are defined events and actions that lead to water, seem like a lot of work in the beginning but as the system
steam or ice transitioning through its different states. grows, this technique helps to dramatically reduce the
Software designers have been using this example to overall complexity. Enabling a state machine for code that
model and partition systems into well-defined states, is already developed and has evolved quite a bit can be
with specific actions and events that define how these painful. So, the one-time investment in state machines for
systems move through these states. any software module right at the beginning of the software

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 83


Developers Overview

development life cycle (SDLC) is always good. then define your states actions and various transitions using
Once a state machine is in place, the developer can the auto generated code and StatefulJ APIs. You can refer
focus on tuning the behaviour of the system to meet to http://www.statefulj.org/framework/#installation for the
functionality requirements and enhance business value, installation and usage steps.
rather than spending time on enforcing the rules of its
behaviour and other crucial non-functional attributes like SMC
code maintainability, flexibility, etc. State machine compiler (SMC) provides users with a
When a system has its responsibilities well delegated framework for writing a well-defined format to define states,
at different states, it also ensures predictability and transitions and actions. The framework is available for
determinism in the system, thereby making it developer- multiple programming languages like C, C++, Java, Python,
friendly when troubleshooting. Scala, Objective-C, JavaScript, Ruby and VB.NET. The
State machines with well-defined states and events can code that SMC generates out of the user-defined state model
keep in control the growth of conditional logic as well follows the state design pattern, with a few variations. The
as ad-hoc code branching out with scattered Boolean application then uses these generated APIs to instantiate and
flags in the software, and thereby control the overall run the state machine. You can refer to the SMC manual
cyclomatic complexity. (http://smc.sourceforge.net/SmcManual.htm) for rules
Digressing a bit into the history of software and to define the state model, transitions and other elements.
technology, good designs and implementations backed by Incorrect usage could lead to compile or runtime errors.
state machines have always proved excellent in various
verticals. These include commonly used elements in our The spring state machine
daily life like a DBMS transaction; TCP, BGP and many This is an open source framework released under the Apache
other networking protocols; system processes and threads, 2.0 licence for developers to use state machines in spring
gaming software development, etc. All these software applications. It uses the builder design pattern for configuration
structures have a state machine in their DNA. Even everyday and instantiation of states. Spring state machines provide some
occurrences like traffic lights, vending machines and other useful features like storing the state machine configurations
digital electronic systems could all be quickly modelled using in a persistent storage, UML Eclipse Papyrus modelling,
Mealy and Moore styled finite state machines. Zookeeper based distributed state machine, etc.
With all this said, let us now explore some options that the
open source world has to offer developers and designers. You
could enable a state machine for your code, even if its proprietary, References
with the open source state machine frameworks given below, and
[1] http://www.statefulj.org/framework/
reap the benefits of the privileges we discussed earlier.
[2] http://smc.sourceforge.net/
[3] http://projects.spring.io/spring-statemachine/
The StateFulJ framework [4] https://ocw.mit.edu/courses/electrical-engineering-
StateFulJ is an open source, lightweight, Java based finite and-computer-science/6-01sc-introduction-to-
electrical-engineering-and-computer-science-i-
state machine (FSM) framework that could help you embed
spring-2011/unit-1-software-engineering/state-
a state machine into your application. It is a useful aid machines/MIT6_01SCS11_chap04.pdf
when your application has to deal with many synchronous
and asynchronous events and requests, while handling
By: Shravan I.V.
concurrency in a reliable way. The user has to define the
state machine model (states, events and transitions) using The author currently works as a software developer at Cisco
Systems India. He is interested in open source technologies,
Java annotations, and the framework auto generates the and can be reached at iv.shravan@gmail.com.
necessary FSM infrastructure for the application. You can

Your favourite Magazine on


Open Source is now on the Web, too.

OpenSourceForU.com
Follow us on Twitter@LinuxForYou

84 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Overview Developers

Qt: The Cross-Platform


Development Toolkit
Check out Qt, a cross-platform development framework, which can be used to
develop application software that runs on various software and hardware platforms.

Q
t, which is pronounced as cute, is a cross-platform also provides Qt Quick, which allows the use of scripting
development framework which was originally created languages like JavaScript. Non-GUI features include SQL
by Haavard Nord and Eirik Chambe. It was first database access, XML parsing and JSON parsing.
released on May 20, 1995. The latest version, Qt 5.8, was
released on January 23, 2017. Qt comes in four editions Downloading and installing Qt
Community, Indie Mobile, Professional and Enterprise. The Download the copy of the Qt SDK or if you are using a Linux
Community version is under the open source licence, while system, then use a copy of Qt and a compiler. Remember that
the other three are commercially sold by the company, Qt. if you are starting off, you might want to consider the open
Qt is not a programming language at all but a cross-platform source LGPL version.
development framework for the desktop, embedded systems Qt can be installed in two ways:
and mobiles. It is basically written in C++. The t in it stands 1. Through the Qt installers, whereby you download and
for toolkit which describes it much better. It is, in fact, a set install it.
of tools. Remember that it is written as Qt and not as QT. 2. Through the Qt source.
The first letter stands for Apples QuickTime and has very little
to do with programming. Thus the framework itself and the Creating a new project
applications/libraries using it can be compiled by any standards- The following steps will help you create a project.
compliant C++ compiler like GCC, ICC, MSVC and Clang. Start up Qt Creator (refer to Figure 1). Go to the File
New File or Project menu entry.
Its purpose and capabilities Choose Qt GUI Application and choose a name for it (see
Qt is used for developing multi-platform applications and Figure 2). Enter a project name, say qt-tutorial-01 (Figure 3).
graphical user interfaces (GUIs). However, programs without Select one or more versions of Qt to target. A desktop
a GUI can also be developed, such as command line tools and build is fine for this tutorial (Figure 4).
consoles for servers. An example of a non-GUI program using Select the base class to be QWidget and for everything else,
Qt is the Cutelyst Web framework. GUI programs created leave it as the default settings (Figure 5). Check the project
with Qt can have a native-looking interface, in which case, Qt creation options on Summary and click Finish (Figure 6).
is classified as a widget toolkit. This will create a simple project consisting of four files.
It uses standard C++ with extensions, including signals main.cpp
and slots that simplify the handling of events, and this helps widget.h
in the development of both GUI and server applications. Qt widget.cpp
supports compilers like GCC and the Visual Studio suite. It widget.ui

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 85


Developers Overview

Figure 4: Select path

Figure 1: Qt Creator

Figure 5: Select Baseclass

Figure 2: New project

Figure 6: Summary

Widgets can be used for painting, printing and rendering.


Integration between Qt and WebKit makes it possible for
developers to use a fully-featured Web browser engine.
The Qt framework is simple and user-friendly. Once
you understand how this simple app works, you can start
adding some more bells and whistles like signal/slot
Figure 3: Qt GUI connections.

Facts and features


There were one million downloads of Qt 5.3 in just over a
Reference
month after its launch.
https://wiki.qt.io
There are 250+ commits by over 60 contributors per week.
Companies that use Qt include AMD, Autodesk, Siemens,
Panasonic, etc. By: Neetesh Mehrotra
Alongside the support for traditional desktop user The author works as a systems engineer in TCS, and his areas
interfaces, Qt includes support for declarative UI of interest are Java development and automation testing. He
can be reached at mehrotra.neetesh@gmail.com.
development with Qt Quick.

86 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


How To Developers

Creating the Sliding Number Game


in App Inventor 2

If youve been faithfully


following this series,
then get ready to create
a fun game. This is the
popular sliding number
puzzle which contains
numbered tiles within
a square frame, with
one blank space for
a tile. The idea is to
move a tile to the blank
space, and rearrange
the tiles in sequence in
the shortest possible
time and with the least
number of moves.

W
e started Android app that are available in the palette, and probably have already got the idea
development with App moving between designer and block from descriptions in earlier articles in
Inventor, picking up some editor is so much fun. this series. We will make an Android
pretty basic ideas to get used to the In this tutorial, I will give you the application that will present a square
concepts, and we have moved towards rather challenging task of building board, which is covered with numbers
more challenging and engaging yet another interesting and powerful on tiles (in a series starting from 1
application ideas. game with the resources available in but in jumbled order) with one empty
I have been getting regular App Inventor 2. I will be making a space. The objective is to arrange the
feedback, suggestions and debugging 15-number sliding puzzle which is also numbers in sequence. To make it more
questions. By now, most readers known by other names such as Gem interesting, you can count the time
have gained enough experience and Puzzle, Boss Puzzle, Game of Fifteen, and the number of moves it takes you
hands-on practice with all the features Mystic Square, etc. It also comes to solve the puzzle so that you can
of the tool. If you are a first-time in various sizes and variations. The challenge your friends as well.
reader of this series, you too can very objective is to arrange the numbers in
well learn from this point onwards sequence, leaving only the corner block GUI requirement
without having any prior programming empty to allow the number blocks to be For every application, we have a
experience or any specialised moved around. If the size of the puzzle graphical user interface or GUI, which
knowledge. Apps developed with is 33 tiles, it is called the 8-puzzle helps the user to interact with the on-
App Inventor can be uploaded to or 9-puzzle, and if it is made up of screen components. The block editor
the Google Play Store and I will 44 tiles, it is called the 15-puzzle or section defines how each component
be delighted to see the good work 16-puzzlenamed, respectively, for the responds to user actions.
done by readers. number of tiles or the number of spaces.
If we talk about App Inventor GUI requirements for Screen1
specifically, then we can proudly say Theme of the application 1. Label: This is a static text
that we have mastered the components The theme is pretty simple and you component that is used to display

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 87


Developers How To

some headings or markings on to If we need to store some variables


the screen. and values that we want to persist
2. Button: This will let you trigger even after the application is closed,
the event and is a very essential we use TinyDB.
component. The components that we need for
3. Horizontal arrangement: This this application are given in Table 1. We
comprises special components will drag them on to the designer from
that keep all child components the left hand side palette.
aligned within themselves. 1. Drag and drop the components
4. Table arrangement: This mentioned in Table 1 to the viewer.
comprises special components 2. Visible components will be seen by
that keep all child components, you while the non-visible components
within itself, well arranged in will be located beneath the viewer
rows and columns as specified in under the tag Non-visible.
the properties. 3. For the applications name, set
5. Clock: This is the timer the Screen1 title property to
component that provides the time SlidingPuzzle.
control of the events happening. 4. All images need to be put within the
Using this, we can set certain vertical arrangement so as to keep
events to happen after a particular them aligned in a square view.
interval. 5. If you have dragged and placed
6. Notifier: This is used to display Figure 1: Designer screen everything, the layout will look
some instructions or give controls something like whats shown
over your existing components. in Figure 1.
You will see its functionality in 6. Make the necessary property
more detail as we implement it in changes like we did in changing
our game. the text property for the label and
7. Canvas: This is the component button components.
for drawing and animation. You 7. Renaming the components helps to
can place various animation identify them in the block editor.
objects on the canvas to control 8. Your graphical user interface is
them via user actions. You will ready. The application will look
be able to see more details on exactly like whats shown in Figure
this aspect as we work on the 2, after installation in the device.
application. 9. The hierarchy of the components
8. Image: The image component dragged to the designer is shown
is used when you need to show in Figure 3.
some pictures or special effects If you are confused by the designer
on screen. and the components viewer, let me
9. TinyDB: This is the database discuss it a bit more. Here is the
component for your application. hierarchy that we have placed for
Figure 2: How the application looks our application.
Table 1
Component name Purpose Location Figure 1: Designer screen
1 Label To display a label Palette-->User Interface-->Label
2 Button To trigger events Palette-->User Interface-->Button
3 Horizontal arrangement To arrange the child components Palette-->Layout-->Horizontal Arrangement
4 Table arrangement To arrange the child components Palette-->Layout-->Table Arrangement
5 Clock To have time control of events Palette-->Sensors-->Clock
6 Notifier To display on-screen information Palette-->User Interface-->Notifier
7 Canvas To enable drawing Palette--> Drawing and Animation--> Canvas
8 Image To display images Palette-->User Interface-->Image
9 TinyDB To store data Palette-->Storage-->TinyDB

88 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


How To Developers

each time to randomly change the this block should move to this
Components
numbers displayed on the board. empty position, and a blank should
Screen1 Now, lets head towards the block be created in the place from which it
TblScores editor to define the behaviour. Lets has moved. This is just a swapping
discuss the actual functionality that we of positions.
LblScoreHdr
are expecting from our application. 3. Each move will increase the
HorizontalArrangement1
1. The board will be loaded with move count.
LblTimer the numbers 1 to 15, in sequence. 4. Our clock timer will be running in
Label1 On pressing the Shuffle the tiles the background and will count the
LblMoves button, numbers will be randomly seconds. Make sure to check the
Tray distributed on the square board. Timer always fires checkbox in the
BtnShuffle
2. If there is an empty block adjacent clock properties.
to any block that is touched, then 5. Once the blocks are arranged in
Notifier1
sequence, we need to display a
Game message on the screen, and the
ScoresDB move count and the time taken
should be recorded to be presented
on the leader board.
So lets move on and add these
behaviours using the block editor. I
hope you remember how to switch
from designer to block editor. There is a
button right above the Properties pane
to switch between them.
Rename Delete
Block editor blocks
I have already prepared the blocks for
Figure 3: A view of the components you. All you need to do is drag the
Figure 4: Block editor image 1 relevant blocks from the left side palette
1. At the top, we have the title for and drop them on the viewer. Arrange
our application. Its always a good the blocks the same way as shown in
practice to name your application the image. I will explain what each does
and show it on the screen as well. and how it is called.
We have set the title property As soon as Screen1 is loaded,
of Screen1 as the name of the certain variables to control events later
application, so the top grey bar on will be declared. In Figure 4, all the
will be the application title or you necessary variables are declared with
can make it within the screen by Figure 5: Block editor image 2 their initial state.
providing a label. Before we present anything to the
2. Below that, we have a score card user, we need to reset everything by
which is hidden in the beginning keeping all the blocks at their default
and will be loaded as the leader position and setting the lists. How the
board at the end of the game. Screen1.Initialize block takes care of
3. In the middle, we have labels of the that is displayed in Figure 5.
time and the moves. We will display Figure 6: Block editor image 3 The Shuffle button will re-arrange
the time taken and the steps count to the blocks and start the game. Figure 6
solve the puzzle. shows the blocks for events when you
4. Beneath that, we have our actual click on the Shuffle button.
play area. We have placed 16 image The tile_shuffle procedure is a
components on the canvas. Assign a recursive call to shuffle the blocks; we
number to the 15 numbers and keep have put that line of blocks within a
one block empty. procedure name so that we can call it
5. At the end, the Shuffle the tiles any number of times.
button will begin a new session Figure 7: Block editor image 4 The counter will be triggered as

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 89


Developers How To

soon as your play board is ready to use. un-trusted source. Allow this
It will increase by one second as we from the settings and after the
have set the interval property to 1000 successful installation, you will
milliseconds in the designer for the see the icon of your application
clock component. in the menu of your mobile. Here,
Now, when a tile is touched, how Figure 8: Block Editor image 5 you will see the default icon,
it should move is depicted in Figure 9. which can be changed and we will
I have posted for two blocks. It will be tell you how to do so as we move
the same for the others as well, keeping ahead in this course.
a separate event handler for all; so I hope your application is working
please create accordingly. exactly as per the requirements
you have given. Now, depending
Application code upon your usage requirements and
It was not possible to snap each and customisation, you can change various
every block of the logic, so I am things like the image, sound and
providing the complete code as a bar behaviour, too.
code. Scan the code (see QRCode 1)
to obtain the .aia file, which you can Debugging the application
upload to your projects in App Inventor We have just created the prototype
2 and view the complete code. Figure 9: Block editor image 6 of the application with very basic
functionality, but what else might
Packaging and testing the user be interested in? Now come
To test the app, you need to get it various use cases which require
on your phone. First, you have to attention in order not to annoy the
download the application to your user. Your app should be able to
computer and then move it to your address the following use cases:
phone via Bluetooth or USB cable. Ill 1. Can we think of a way to share our
tell you how to download it. moves and puzzle-solving time
1. On the top row, click on the Build with our friends?
button. It will show you the option 2. Can we display two boards
to download the apk to your simultaneously for two users and
computer. make it a dual player game?
2. The progress of the download can be 3. What will other versions be like
seen, and after its been successfully if we think of expanding the size
QRCode 1: Project source code file (.aia)
done, the application will be placed of the square?
If you want to see how the in the Download folder of your These are some of the scenarios
application looks after installation, scan directory or the preferred location that might occur and users will be
the code given in QRCode 2 to get the you have set for it. pretty happy seeing these features
application apk. 3. Now you need to get this apk implemented.
file to your mobile phone either Think about all these scenarios
via Bluetooth or USB cable. and how you could integrate their
Once you have placed the apk solutions into the application. Do ask
file to your SD card, you need to me if you fail to address any of the
install it. Follow the on-screen above cases.
instructions to install it. You You have successfully built
might get some notification or another useful Android app for
warning saying,Install from yourself. Happy inventing!

By: Meghraj Singh Beniwal


The author is a B. Tech in electronics and communication, a freelance writer and
an Android app developer. He is currently working as an automation engineer
at Infosys, Pune. He can be contacted at meghrajsingh01@rediffmail.com or
meghrajwithandroid@gmail.com
QRCode 2: Application install File (.apk)

90 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


How To Developers

Searching Text Strings from


Files Using Python
Searching text strings from files in a given folder is easily accomplished by using Python
in Windows. While Linux has the grep command, Windows does not have an equivalent.
The only alternative, then, is to make a command that will search the string. This article
introduces see.py, which helps in accomplishing this task.

H
ave you ever thought of searching a string in the files self.path1= path1
of a given folder? If you are a Linux lover, you must self.string1 = string2
be thinking about the grep command. But in Windows, self.i=i
there is no grep command. By using Python programming, if self.i:
you can make your own command which will search the string2 = string2.lower()
string pattern from the given files. The program also offers self.string2= re.compile(string2)
you the power of regular expressions to search the pattern.
In this article, I am going to show you an amazing utility, The following method gives the files name in which the
which will help you to find the string from a number of files. given string is found:
The program, see.py, will search for the string pattern
provided by the user, from the files presented in the directory, def txt_search(self):
also given by the user. This is equivalent to the grep command file_number = 0
in the Linux OS. Here, we will use Python 2.7. files = [f for f in os.listdir(self.path1) if os.path.
The program expects the string pattern and directory from isfile(self.path1+/+f)]
the user. Let us examine the code and discuss it. for file in files:
file_t = open(self.path1+/+file)
Import the mandatory modules file_text= file_t.read()
import os if self.i:
import re file_text=file_text.lower()
import sys file_t.close()
import argparse if re.search(self.string2, file_text):
print The text +self.string1+ found in ,
In the following code I have declared a class Text_search file
class Text_search :
file_number=file_number+1
def __init__(self, string2, path1,i=None): print total files are ,file_number

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 91


Developers How To

The following method returns the files name as well as print total files are ,file_number
the line numbers in which the given string is matched.
This is the main function of the program which handles
def txt_search_m(self): all the options. The program offers you six options. The
files = [f for f in os.listdir(self.path1) if os.path. m option gives the number of the file and the line. mi
isfile(self.path1+"/"+f)] is case-insensitive. You can use the h option to get help
file_number = 0 for all options.
for file in files:
file_t = open(self.path1+"/"+file) def main():
line_number=1 parser = argparse.ArgumentParser(version=1.0)
flag_file = 0 parser.add_argument(-m, nargs = 2, help = To get
for line1 in file_t: files as well as line number of files )
if self.i: parser.add_argument(-s, nargs = 2, help = To get the
line1 = line1.lower() files contain string )
if re.search(self.string2, line1): parser.add_argument(-r, nargs = 2, help = To search
flag_file= 1 in recusrive order )
print "The text "+self.string1+" found in parser.add_argument(-mi, nargs = 2, help = -m option
", file, " at line number ",line_number with case insensitive )
line_number=line_number+1 parser.add_argument(-si, nargs = 2, help = -s option
if flag_file == 1: with case insensitive )
file_number=file_number+1 parser.add_argument(-ri, nargs = 2, help = -r option
flag_file=0 with case insensitive )
file_t.close()
print "total files are ",file_number args = parser.parse_args()

The following method also returns the files name as well If you select option m, then it will call the txt_
as the line numbers in which the given string is matched. search_m() method of class Text_search().
This method works in recursive mode.
try:
def txt_search_r(self): if args.m:
file_number = 0 dir = args.m[1]
for root, dir, files in os.walk(self.path1, topdown = obj1 = Text_search(args.m[0],dir)
True): obj1.txt_search_m()

files = [f for f in files if os.path. If you select option s, then it will call the method
isfile(root+/+f)] txt_search().
for file in files:
file= root+/+file elif args.s:
file_t = open(file) if args.s[1]:
line_number=1 dir = args.s[1]
flag_file = 0 obj1 = Text_search(args.s[0],dir)
for line1 in file_t: obj1.txt_search()
if self.i:
line1=line1.lower() If you select the r option, then it will call the method
txt_search_r().
if re.search(self.string2, line1):
flag_file= 1 elif args.r:
print The text +self.string1+ found if args.r[1]:
in , file, at line number ,line_number dir = args.r[1]
line_number=line_number+1 obj1 = Text_search(args.r[0],dir)
if flag_file == 1: obj1.txt_search_r()
file_number=file_number+1
flag_file=0 If you select the mi option, then it will call the txt_
file_t.close() search_m() method in case-insensitive mode.

92 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


How To Developers

elif args.mi: main()


dir = args.mi[1]
obj1 = Text_search(args.mi[0],dir,i=1) Lets make exe files using pyinstaller modules as
obj1.txt_search_m() shown in Figure 1.
After conversion, it will make a directory called see\dist. Get
If you select option s, then it will call the method txt_ the see.exe files from the directory see\dist and put them in the
search() in case-insensitive mode. Windows folder. In this way, see.exe is added to the system path.
see.exe works like a DOS command.
elif args.si: Let us use the program see.
if args.si[1]: Use the option s as in Figure 2. You can see that only file
dir = args.si[1] names are returned.
obj1 = Text_search(args.si[0],dir,i=1) Use the option m as shown in Figure 3. You can see that
obj1.txt_search() file names and lines are returned.
Use the option r as shown in Figure 4. In this option, m
If you select the r option, then it will call the txt_ works in recursive mode.
search_r() method in case-insensitive mode.

elif args.ri:
if args.ri[1]:
dir = args.ri[1]
obj1 = Text_search(args.ri[0],dir,i=1)
obj1.txt_search_r()

print \nThanks for using L4wisdom.com


print Email id mohitraj.cs@gmail.com
print URL: http://l4wisdom.com/see_go.php Figure 3: Option m, which is case-sensitive

except Exception as e:
print e
print Please use proper format to search a file use
following instructions
print see file-name
print Use <see -h > For help

Figure 4: Option r, which is case-sensitive

Figure 1: Python program to make exe file


Figure 5: Option si, which is case-insensitive

Figure 6: Option mi, which is case-insensitive


Figure 2: Option s, which is case-sensitive
Continued on page 98...
www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 93
OpenGurus How To

Hack the Bootsector


and Write Your Own!
This article is a tutorial on writing your own bootsector. It is a good exercise in
understanding how the bootsector works and trying your hand at writing something that
boots. Who knows? You might be able to write your own OS some day!

M
any young programmers dream of writing the code your own OS is that it's a great learning experience.
for their own operating system. But when they You are at the lowest level of software (just above the
realise they have to write everything from scratch, firmware), and in contact with bare metal. Any hardware
including the code for the device and file system drivers, component is ready to obey your orders. And all that
they give up the dream. matters is your capability to give the correct orders (which
Of course, one can just write the core components and is what is called drivers). Despite being time-consuming,
port all the existing stuff to the new system. But even getting bootsector experiments can give you the confidence that
a kernel ready one that supports only very basic features doing an entire Java or PHP course can't.
would be a long process. Moreover, porting the existing
components will not give you that developed-by-me feeling. Note: The code snippets and explanations given in this
So here is a solution: start off by writing something that article target the Intel x86 architecture. This means you can
just boots, rather than an entire OS, or even a kernel. Later, try them on Intel 8086 to Core i7, any x86 compatible CPU
the same steps can be followed to develop an advanced from AMD or other vendor, or on an emulator like QEMU.
bootloader, and eventually a kernel, which essentially lays the Also, modern technologies including GPT, EFI and GNU
foundation for your own OS. Multiboot have been avoided in favour of the traditional
Before starting, lets first address the following question: BIOS-based booting technology. It seems to be the best
why develop a new operating system? starting point, and is still supported by all modern machines.
This article doesnt assume that everybody is going to
develop a brand new operating system. We have many OSs The boot process and the bootsector
already, and our time and resources could be donated to such The steps involved in the boot process primarily depend on
existing community projects. the hardware components, firmware, BIOS, disks and the
However, one reason why you could consider writing operating system itself.

94 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


OpenGurus How To

Generally speaking, when a system is turned on, the Getting it assembled using NASM
CPU starts and executes the startup code from the ROM Although there are many assemblers available (including
chip. After the Power-On-Self-Test (POST), the BIOS GNU Assembler), I prefer NASM, the Netwide Assembler,
locates the boot disk, loads its bootsector (the first sector for its simplicity. Let's use the following command to
or 512 bytes) code into the RAM (location 0x7c00), and assemble this code (before that, make sure you have the
transfers the controls to it. package nasm installed on your computer):
The program that has got the controls now is called the
first bootstrap loader (or the first stage bootloader). This is nasm -o hello.bin -f hello.asm
the program that we are going to write and test in this article.
With a size constraint of 512 bytes, its only purpose I am assuming the command shell is in the same directory
would be to load the next stages in the bootloading process. as the source code. If not, use the command cd to navigate.
But this limited space is sufficient for our experiments. hello.asm is the input file, and the option -o specifies
the output file, which is hello.bin (an extension has no
The Hello World program significance, actually).
The Assembly code for a simple Hello World program that The option -f says that the format of the output file should
works on the x86 architecture follows. There is no space be flat (plain or raw) binary. Usually, assemblers and linkers
for a detailed explanation. However, the core idea is to take choose high-level executable formats like ELF and PE, which
each letter from a string literal (msg, here), and display it cannot be executed by the CPU without help from an OS. But
using the BIOS function in order to print a character. we need something that can be directly executed by the CPU.
Now just enter the following code using a text editor This is why we assemble our program as flat binary.
and save it as hello.asm.
Testing it with QEMU
; Set DS (data segment base) as 0x7c0 We can use emulators and virtual machine monitors to test
mov ax, 0x7c0 our bootable code without restarting the actual machine and
mov ds, ax getting out of the current OS. Lets choose QEMU as the
emulator to be used in this article, for its portability. Most
mov cx, MSGLEN GNU/Linux distros provide the package qemu, and you can
mov si, msg install it directly.
mov ah, 0xe ; BIOS 10h function code for tty output Now, simply run the following command (again, if the
putchar: Shell is in a different directory, use cd to navigate first). This
mov al, [si] ; Character to be displayed command instructs QEMU to start a virtual machine with
int 0x10 ; BIOS interrupt for video service the disk image hello.bin considered to be the boot disk.
inc si
loop putchar qemu-system-i386 hello.bin

jmp $ ; Jump here (i.e, loop forever) Now it works!


If youve got KVM installed, you can use the following
msg: db 'Hello, world!' command also:

; Let MSGLEN = Length of msg kvm hello.bin


MSGLEN: EQU ($ - msg)

; We need the boot signature as the last two bytes.


; That's why the remaining space is padded off.
padding: times (510 - ($ - $$)) db 0

BOOT_SIGN: db 0x55, 0xaa

One might ask: why Assembly language? There is no


escaping from Assembly, at least, not in the early stages of
developing an OS. Assembly is highly hardware-dependent
and less productive, but it gives greater control. Also, we
have a limited space of 446 bytes for our bootsector code,
which is too short for a high-level program. Figure 1: QEMU runs the Hello World bootable program

96 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


How To OpenGurus

skip at the start of the output; and skip is the number of blocks
to skip at the start of the input. conv=notrunc ensures that the
output file is not truncated (i.e., all other sectors in the USB
Flash drive are preserved).
Now lets test it on the real BIOS. Connect the USB drive
and restart the computer. If USB booting is enabled and given
high preference, the system should directly load your boot
code. If it doesnt, restart again and enter the BIOS settings.
Ensure the following, save the settings and restart again:
USB booting is enabled and given preference over other
drives like HDD.
Legacy booting is enabled and is preferred over UEFI.
Now you should see your Hello World program running.
Figure 2: Bless hex editor displays the contents of a USB Flash drive When you've finished enjoying your own bootable program,
just press the power button on the tower to shut down, or use
Getting it set on an actual disk Ctrl + Alt + Del to restart.
Lets get our code written onto the bootsector of a USB Flash
drive. First, find the drive name of the USB Flash drive. If Using a hex editor
you have just a single SATA hard disk installed, the next drive A hex editor is a program that lets you view/edit the
you connect (here, the USB Flash drive) would be called /dev/ contents of any computer file as a plain stream of bytes,
sdb. To verify this, launch the Disk Utility or try the command and it is usually represented in hexadecimal values. While
lsblk after connecting the drive. developing bootable programs, we can use a hex editor to
review the internal byte patterns in a disk image or pseudo-
Caution: files like /dev/sdb. In our case, for example, you can use a
Incorrect identification of drive names can cause hex editor to ensure that we haven't exceeded the limit of
unexpected data loss. Also, take a backup of important files 446 bytes for our boot code.
before you start experimenting with a disk. The popular command hexdump might be already
available on your GNU/Linux system. However, I recommend
We are not performing a simple copy-paste. So it is better installing the package <i>bless</i>, which provides the easy
to unmount the drive (in case it got mounted automatically) and full-featured Bless hex editor.
by using the following command: After installation, launch Bless from the menu or by using
the command bless. If you are not the root user, you might not
sudo umount /dev/sdb be able to open system files like /dev/sdb (which represents
the hard disk). You'll need the assistance of commands like su,
Now, we can use the following command to copy the sudo or gksudo. For example:
bootsector. But wait! Dont even think about executing it until
you complete the next paragraph. sudo bless /dev/sdb
gksudo bless /dev/sdb
sudo dd if=hello.bin of=/dev/sdb

This command will copy the data in the file hello.bin Caution:
to the Flash drive, directly (i.e., not as a file). To make it Never open actual disks (especially your primary hard
useful again, youll have to format it. Alternatively, the disk) if you are not sure what you are doing. Editing files
following commands copy the necessary parts only, leaving like /dev/sda can even break the booting, OS and the
all other bytes intact. partition table. However, trying disk images (e.g., .img and
.iso files) is safe if you have their backup copies.
sudo dd bs=446 count=1 conv=notrunc if=hello.in of=/dev/sdb
sudo dd bs=1 count=2 seek=510 skip=510 conv=notrunc if=hello. Another example: A simple typewriter
bin of=/dev/sdb When we run hello.bin (our first example), the keyboard does
not respond. Given below is the code for a simple typewriter,
The first line copies the boot code and the second line which displays whatever you type.
copies the boot signature bytes (0x55, 0xaa). bs means the
block size is to be considered while copying; count is the mov ax, 0x7c0
number of blocks to copy; seek is the number of blocks to mov ds, ax

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 97


OpenGurus How To

The way ahead


All examples discussed in this article are based on the Intel
x86 Real Mode, which has a limited memory of 1MB, and
no protection walls between applications. Modern systems
make use of the Protected Mode, which is a must to write a
general-purpose OS. However, for backward compatibility
and simplicity, modern CPUs still start in the Real Mode.
Figure 3: QEMU runs the typewriter program That means the examples we discussed are still useful,
avoiding the need for a complete reboot.
read_and_display: You can find many websites that can help you in all
mov ah, 0; BIOS 10h function code for keyboard read these processes, among which is the remarkable wiki.
int 0x16; BIOS interrupt for keyboard service osdev.org. However, as the term bootstrap loading
; Waits for a keypress. suggests, you are pulling yourself up with your own
; Now we have the ASCII code of the pressed key in AL. bootstraps, which means that original experimentation
and a lot of patience are required.
mov ah, 0xe; BIOS 10h function code for tty output
; Anything in AL will be displayed.
int 0x10 ; BIOS interrupt for video service By: Nandakumar Edamana
The author is a free software user, developer, hacker and
jmp read_and_display activist who has developed a few software packages including
Sammaty Election Software. He writes for mainstream media
padding: times (510 - ($ - $$)) db 0 and composes music as a passion. Website: nandakumar.
co.in. You can contact him at nandakumar96@gmail.com.
BOOT_SIGN: db 0x55, 0xaa

Continued from page 93...

Figure 9: Regular expressions

Figure 7: Option ri, which is case-insensitive

Figure 10: The power of regular expressions


Figure 8: Help option

Use the option si as shown in Figure 5. You can see See Figure 10, which shows the power of regular
that only file names are returned, and text searching is expressions.
impervious to upper and lower case.
Use the option mi as shown in Figure 6. Use the By: Mohit
option ri as shown in Figure 7.
The author is a certified ethical hacker and EC Council
In order to get help, use the option h as shown certified security analyst. He has a masters degree in
in Figure 8. computer science from Thapar University, and is the author
The program offers you the power of regular of Python Penetration Testing Essentials. You can contact
expressions. Figure 9 shows the file 1.txt, which contains him at mohitraj.cs@gmail.com and https://in.linkedin.com/
in/mohit-raj-990a852a.
text. Let us use the regular expression, + operator.

98 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


Case Study For U & Me

Vodafone Deploys Open Source


to Reduce Vendor Lock-in
Vodafone India is the second largest player in the Indian telecom sector after
Bharti Airtel, with a base of over 200 million subscribers. The telco giant uses
digital GSM technologies on 900MHz and 1800MHz frequencies to offer traditional
2G and 3G services alongside an advanced 4G LTE network.

A
part from offering mobile device users in the country Developers at Vodafone India also take support from
with seamless connectivity, Vodafone India is a large product sites. Additionally, the telco has some partner-
consumer of open source software. The subsidiary of managed solutions that are taken care of by third parties.
the UK-based Vodafone Group Plc has a talent pool of over
100 people involved in major open source developments. Moving away from proprietary technologies
Moreover, it considers open source as the key factor when it Vodafone India had initially relied on proprietary
comes to deciding the architecture for all its partners. technologies. But with the massive advances in the open
Vodafone India ensures that all partner contracts have source world, the operator has decided to make the shift to
open source as the key architecture deciding point, says Vikas community solutions.
Grover, former chief information officer, Vodafone India. Growth, cost reduction and architecture improvement
Vodafone's developer team uses traditional open initiatives compel us to keep transforming our IT state
source solutions such as Java, Drools, Eclipse Mars and year-over-year. This allows us to review our technology
Apache Hadoop as well as the new versions of R, Python, stack, avoid vendor lock-in and analyse cost implications,
Cassandra and Struts, among various others. resulting in wider implementation and induction of open
To enhance existing offerings and to discover new source technologies, Gupta told Open Source For You.
developments, the team accesses well-known repositories.
We sometimes take help from the contributors available Customer Point of Sale (CPOS)
on GitHub and Stack Overflow, says Rahul Gupta, VP for One of the technologies to have recently received open source
solution and planning of IT, Vodafone India. treatment by Vodafone engineers is a customer onboarding

www.OpenSourceForU.com | OPEN SOURCE FOR YOU | MaY 2017 | 99


For U & Me Case Study

Major open source solutions used at Vodafone India in order to shift the solution to open source software. The
CPOS (Customer Point of Sale) A customer on- major bottleneck in the transformation process was to enable
boarding application used for all types of new clients. real-time communication between the app server and JPS
It uses Apache Tomcat, BIRT, Java, JAXWS, Open server, which was based on the Java state machine. The
JPA, Spring and Struts. engineers were also required to optimise Enterprise Java
UPSS A system to support prepaid offers for over Beans (EJB) and Web service calls.
200 million customers. It uses Axis, Hibernate, Java, We designed XML-based flow and translated BPEL
Spring and Struts. rules to Java XML to begin the transformation. Our
A campaign management system An application to
engineers also used a caching mechanism to optimise
generate campaigns based on customer segmenta-
Appin server calls to JPS. After that, all transactions were
tion and value management. It uses Hadoop, Hive,
Pig and Red Hat Enterprise Linux. thoroughly tested with bucket movement, and Mini Sanity
(for bulk testing of post-paid connections) was simulated
system. Internally called Customer Point of Sale or CPOS, to ensure proper performance, says Gupta.
the technology has been moved from proprietary Websphere
Process Server (WPS) to a Drools-based custom workflow Open source campaign management
solution. The CPOS solution by Vodafone India helps in In addition to the customer onboarding system, Vodafone
acquiring new customers and offers efficient inventory India has an open source-powered Campaign Management
management. Our CPOS is effectively handling the smallest System that helps the telecom giant create unique offers and
of performance dips and availability issues that impact the promotions for customers, based on data-led segmentation
market directly, often leading to irrecoverable scenarios like a and real-time triggers including recharges.
customer moving away to other avenues, explains Abhilekh The offers made through the Campaign Management
Bhardwaj, head of IT delivery excellence, Vodafone India. System are available to customers at certain interventions. The
Apart from easing customer acquisition, Bhardwaj states system lists promotional activities when a customer contacts
that the open source code used in CPOS enables engineers to the operator for service needs. Also, the system circulates
scale the application and increase its resilience. pre-defined real-time triggers. These offers not only help
Vodafone India is also leveraging the features of CPOS Vodafone India to grow revenues but also let customers enjoy
for various eKYC (know your customer) services that offer a better and more personalised experience, asserts Bhardwaj.
Aadhaar-based instant activation. Open source adoption
within our CPOS has doubled the performance of activating Proprietary vs open source solutions
new prepaid, postpaid and enterprise customers, and has The IT engineers at Vodafone India make certain value-
delivered higher stability, Gupta comments. Today, the based evaluations to pick the right mix between proprietary
CPOS solution is accessed by all Vodafone-authorised technologies and open source software. There are parameters
distributors and retailers across the country. And it results including the technological edge, support, the roadmap and
in over 10 million activations per month. costs that help us decide between commercial and open
source options, says Gupta.
WPS Replacement Having said that, the team focuses more on open source.
The IT experts at Vodafone India accomplished the As a principle, we are committed to moving towards using
transformation project dubbed as WPS Replacement in open source, thereby reducing vendor lock-in to the extent
2014, wherein a WPS (Wi-Fi Protected Setup) backed bucket possible, says Bhardwaj.
movement was replaced with a custom Java state machine.
Gupta points out that more than 10 critical transactions Need for local competencies among Indian
impacting over 40 bucket movements had to be redesigned systems integrators
While open source is liberating the telco from the licensing
Key challenges involved in the WPS needed for proprietary solutions, the systems integrators
Replacement project in India also need to create their own competencies and
Complex workflows, which were as per TRAI regula- contribute to the community. This would help to reduce the
tions, had to be migrated from BPEL to Java Engine monopoly of a few support providers in the country.
More than 10 critical transactions impacting over 40 Open source adoption is no more a choice to be made
bucket movements had to be redesigned in the future. It is happening now and here, Bhardwaj
Java-based state machine (JPS) was hosted on a new emphasises.
server to ensure handling of high capacity activations
Real-time communication between app server and
JPS server By: Jagmeet Singh
Optimisation of EJB and Web service calls The author is an assistant editor at OSFY.

100 | MaY 2017 | OPEN SOURCE FOR YOU | www.OpenSourceForU.com


OpenGurus How To

Beaglebone Black:
Flashing eMMC Through an SD Card
The Beaglebone Black is a low-power open source single-board computer. eMMC is
short for embedded multi media controller which refers to a package integrating
Flash memory and a memory controller in the same silicon die. In this article, we
flash the eMMC on to the Beaglebone Black using an SD card.

the trick. The best option is not to use the MMC1_CLK and
MMC1_CMD signals at all and tie them LOW.

Note: If the board is powered off without using


the onboard power button, then there is a chance of
data corruption in the eMMC. The data in the eMMC
can be restored by re-flashing the board. It is always
recommended to use the latest version of the software.

Steps to flash the board


To flash the board, you need an
SD card with a capacity of 4GB or

T
more. Using an SD card smaller
he Beaglebone Black Rev C features a Sitara than 4GB will not boot the board.
AM3358BZ100, 1GHz processor and 512MB DDR3L Before starting, do remember to take
RAM. Its significant features are lower costs, and an a backup of all the contents of the
increase in both performance and memory size. In this low SD card that you are going to use, as
power device, EEPROM has been reduced from 32KB to flashing will erase them completely.
4KB, so that the cost falls. The board features a 4GB NAND Now, ensure to download the latest
(eMMC), and has an HDMI and a USB interface. In addition, images for the Beaglebone Black
it has a GPIO3_21 with a 24.576MHz clock. It also carries from the official Beagleboard
a microSD card. On-board Flash memory of 2GB acts as the website (Figure 2).
hard drive for the board to host a Linux operating system and Figure 1: Beaglebone Black The image can also be directly
other software development tools. downloaded from the system by using the following command:
With a user-friendly, browser-based Bonescript
programming environment called Cloud9, a learner can $ wget -c http://debian.beagleboard.org/images/BBB-eMMC-
easily program the Beaglebone Black (BBB) board to rapidly
prototype electronic systems that interface with real-world
applications. As user knowledge develops, the board provides
more complicated interfaces including C/C++ functions to
access digital and analogue pins aboard the ARM Cortex A8
microprocessor. The full power and capability of the BBB
board can be programmed in the underlying onboard Linux
operating system, such as Angstrom or Ubuntu.

Onboard eMMC
The onboard eMMC uses MMC1 signals. It is also
connected to the expansion header. The eMMC device on
the Beaglebone Black will need to be disabled by activating
the reset line to this device. To do this, you have to write to
eMMC first and instruct it to enable the reset. At this point
in time, it is not totally clear whether the reset line will do Figure 2: Latest image source

102 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


How To OpenGurus

flasher-debian-7.5-2014-05-14-2gb.img.xz The above command is shown in Figure 3.


In this case, I have created a mount point bbb_flashing and
After the image is downloaded, unzip it by using the have mounted the SD card. You can go to Devices to confirm
following command: whether the SD card has mounted properly or not.
I am going to use the dd command to copy the image file
$ xz -d BBB*.xz to the SD card. Figure 4 shows the image files being copied to
the SD card, in my case.
In the above command, BBB* denotes the full name of the
downloaded image. $sudo dd if=/<path/to/image/file> of=/dev/<SD Cardname>
After unzipping the downloaded image, mount the SD
card and copy the image on to it. After the image has been successfully copied on to the SD
The command used to mount the SD card is given below: card, unmount the SD card and insert it into the board, which
is in the switched off state.
$ sudo mount /dev/<Device name> E.g. sdb. The command used for unmounting the SD
card is as follows:

$sudo umount /dev/(Device name) Eg: sdb1

We have to provide an external power supply by holding


switch2 on the board. The SD card present in the board
functions and tries to flash the board, as shown in Figure 5.
As soon as the LEDs present on the board begin to flash,
Figure 3: Command showing mounting of the SD card you can release switch2.
It may take around 45 minutes to one hour to flash the
board. When the LEDs present on the board stop blinking
and are ON, the board has been flashed completely. In
the screenshot (Figure 6), we can see the LEDs glowing
constantly after the completion of the flashing process.
As soon as the flashing is over, disconnect the power and
try restarting the board by pressing the S2 button.
Finally, press S3 to power up the board and you will have
Figure 4: Copying the image to the SD card the latest image installed on it.
Beaglebone Black is used in robotics, motor drivers,
Twitter printers, data backups, SDR base stations, USB data
acquisition and more. It offers great customisation, speed
and MATLAB compatibility. It runs Simulink models as
standalone applications and the off-course JTAG debugger.
The incredible number of pins on the Beaglebone Black and
the many bus options allow users to easily interface it with
pretty much any device out there.
Figure 5: After the SD card is inserted, the board starts to flash

References
[1] https://en.wikipedia.org/wiki/BeagleBoard
[2] http://derekmolloy.ie/
[3] http://tinypic.com/1r55gh7o

By: S. Pardhu Pavan


The author currently works at AdeptChips Pvt Ltd,
Bengaluru, as an embedded systems engineer in the
areas of communications and Internet enabled systems.
He is an open source enthusiast, and has experience in C
programming and device driver development.
Figure 6: LED status after flashing

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 103


TIPS
& TRICKS
Record audio from your microphone via After fetching the file, you need to set an executable
the command line permission on the script for it to execute properly.
First, download the 'sox' tool suite which is extremely
versatile for audio file manipulation. Use the following sudo chmod a+rx /usr/local/bin/youtube-dl
command on Debian systems:
To download a video file, simply run the following
# apt-get install sox libsox-fmt-all command, where VIDEO_URL is the URL of the
'libsox-fmt-all' package enables playback of mp3 files. video that you want to download.

The 'sox' suite includes two tools called 'rec' and 'play'. youtube-dl <VIDEO_URL>
To record audio, insert a microphone into your audio
jack and type the following command: You can also download in multiple formats. Run
the commands below to discover all that can be done
# rec -c 1 test_file.mp3 using this tool:

The recording session begins and whatever you speak youtube-dl -h


through the microphone is recorded. Once you are done
recording, press Ctrl+C. or:
To play the recorded file, type the following:
man youtube-dl
#play test_file.mp3
Mounica Revuru, ojaswithamonica@gmail.com
'sox' can also handle audio files of formats like
wav, ogg, etc. Tips for day-to-day use
Given below are a few handy tips for those
Divya Lakshmanan, who use Linux daily.
divya.lakshmanan27@gmail.com Resume typing a command after a few others
Sometimes, after typing a long and complex command
Download videos using the YouTube on a Linux terminal, we realise that we have to type
downloader in Linux some other commands, and even examine their results,
First, install youtube-dl by following the steps given below. before we hit Enter. Instead of discarding what we have
If you are running an Ubuntu based Linux distribution, typed, or opening another terminal/GUI text editor to
you can install it using the following: store it, we can just go to the end of our typed line by
using Ctrl E, and press Ctrl U to clear the line. Then, we
sudo apt-get install youtube-dl can execute the intermediate command and just press
Ctrl Y. Voila! The deferred command reappears for us
For any other Linux distro, you can quickly install to modify or execute with the use of Enter. Think of it
youtube-dl on your system through the command line as a kind of cut-and-paste for the contents of the line
interface with the following command: preceding the cursor.
Docker emergency shutdown
sudo wget https://yt-dl.org/downloads/latest/youtube-dl -O/usr/ As of release 1.12.1, Docker does not have a single
local/bin/youtube-dl command to stop all running containers. But here

104 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com


is a hack to do that: welcome message to your terminal. This message will be
displayed at the start, whenever you open your terminal.
docker stop $(docker ps -q) Here are the steps to follow:
1. You need to install figlet. So open the terminal and type
You may have to use sudo before docker both times the following command:
in the command. This can save you from individually
stopping dozens of containers before a system shutdown. sudo apt-get install figlet
Swing between smart quotes and straight quotes in
LibreOffice Then press Enter.
Those who have been hunting around for a way to 2. Open .bashrc in the Vim editor and press to get into
quickly use both smart and straight quotes on any PC running Insert mode.
LibreOffice or OpenOffice, heres the way to go about it.
Turn on Smart quotes (if turned off) using Tools vi .bashrc
AutoCorrect Options Localized Options.
Hit Ctrl+z (or Undo) to turn back curly quotes to 3. Enter the following command in .bashrc:
straight quotes following each individual insertion.
I tested this on LibreOffice, and expect equal success figlet -c your_message
with OpenOffice.
Press the Esc button; then press colon x and Enter.
A. Datta, webmaster@aucklandwhich.org 4. Now, when you open your terminal, you can see your
welcome message.
Adding the time stamp to the History Here is another tip that I want to share.
command Remove Amazon results from Dash in Ubuntu
The History command does not output the time stamp with Ubuntu added Amazon search results into the Unity Dash
the log of the most recently executed commands. a few releases ago. While many people complained that
To do so, run the following command in the terminal: their privacy was at risk since every search was being sent
to Amazons servers, I personally just found the Amazon
# HISTTIMEFORMAT=%d/%m/%y %T results unnecessary.
# history To remove the Amazon search results from the Dash,
run the following command:
If you want to permanently append this change, add the
following line to the ~/.bashrc file: sudo apt-get autoremove unity-lens-shopping

# export HISTTIMEFORMAT=%d/%m/%y %T and restart. This will get rid of the Dash lens that is
responsible for those results.
Then, from the terminal, run the following: Alternatively, you can also go into the System Settings
> Security & Privacy, and disable Online Search Results.
# source ~/.bashrc Do note that this toggle will affect not just the Amazon
search results, but also any other Dash lenses that require
Heres an explanation of the commands and switches: the Internet to function.
history GNU History library Harish Tiwari,
HISTIMEFORMAT Environmental variable harishtiwary46@gmail.com
%d Day
%m Month
%y Year
%T Time stamp
source In short, send the contents of the file to the shell
.bashrc Is a shell script that BASH runs whenever it Share Your Linux Recipes!
is started interactively The joy of using Linux is in finding ways to get around
problemstake them head on, defeat them! We invite you
to share your tips and tricks with us for publication in OSFY
Rajeeb Senapati, rajeeb.koomar@gmail.com so that they can reach a wider audience. Your tips could be
related to administration, programming, troubleshooting or
Add a welcome message to your terminal general tweaking. Submit them at www.opensourceforu.
com. The sender of each published tip will get a T-shirt.
This tip will show you how you can easily add a

www.OpenSourceForU.com | OPEN SOURCE FOR yOU | May 2017 | 105


OSFY DVD

DVD Of The MOnTh


Heres the latest version of Ubuntu for your desktop.
Ubuntu 17.04 Desktop
Ubuntu is used on the smallest of devices to the largest
cloud server. All the essential applications, like an office
Reco
mm
suite, browsers, email and media apps come pre-installed,
end
ed
Sys
te m
and thousands of games and applications are available in
Re

.
qu
ire
me
nts
the Ubuntu Software Centre. With its 17.04 release, Ubuntu
nt
switches from swap partitions to using swap files, by default.
e
em

:P
lac

4,
1G
ep

Live
er

BR
Lubuntu 17.04
fre

AM
a

,
or

DV
17.04
in f

D-R
efy.

Lubuntu is an official Ubuntu flavour based on the


OM
rt@

Driv
ppo

Lightweight X11 Desktop Environment (LXDE). Lubuntu


e
at su
to us

specifically targets older machines with lower resources, but


t work properly, write

also runs very well on newer hardware. The bundled DVD


May 2017 comes with the ISO image of the 32-bit edition.
KDE Neon
es no
DVD do

This is the latest and supposedly greatest of the KDE


this

communitys software packaged on a rock-solid base. Most


ase
In c

users will want to use the packages built from released


software, which will be available soon. KDE Neon will
provide users with more up-to-date packages of Qt and
cutting-edge KDE software.

Rocksor 3.9.0
You can build and manage your own Linux and BTRFS
CD Team
e-mail: cdteam@efy.in

powered advanced NAS and cloud storage with ease


Rocksor 3.9.0 provides a solid platform and empowers users
to deploy effective storage solutions.

What is a live DVD?


A live CD/DVD or live disk contains a bootable
operating system, the core program of any computer,
which is designed to run all your programs and manage
all your hardware and software.
Live CDs/DVDs have the ability to run a complete,
modern OS on a computer even without secondary
storage, such as a hard disk drive. The CD/DVD directly
runs the OS and other applications from the DVD drive
itself. Thus, a live disk allows you to try the OS before
you install it, without erasing or installing anything on
your current system. Such disks are used to demonstrate
features or try out a release. They are also used for
testing hardware functionality, before actual installation.
To run a live DVD, you need to boot your computer
using the disk in the ROM drive. To know how to set
a boot device in BIOS, please refer to the hardware
documentation for your computer/laptop.

106 | May 2017 | OPEN SOURCE FOR yOU | www.OpenSourceForU.com

You might also like