All posts by Steven A

Check if system (RHEL/CENTOS )is UEFI or BIOS

Please run the following script to find out if your system is UEFI or BIOS

 

#!/bin/bash
[ -d /sys/firmware/efi ] && fw=”UEFI” || fw=”BIOS”
echo -e “$fw”
if [ “$fw” == “UEFI” ] ; then
mygrub=’/boot/efi/EFI/redhat/grub.cfg’
echo -e “\n\tUEFI detected, this is a ($fw) system., and the boot config is located at ($mygrub)”
else
mygrub=’/boot/grub2/grub.cfg’
echo -e “\n\t($fw) system detected your boot config is located at ($mygrub)\n”
fi

Yum Update hung or ssh disconnected during yum update

Yum gives error: “There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them”

 

Environment:

Red hat / CentOS 5-6-7

 

Issue

  • While updating the system using yum it throws an error: “There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them”.
  • yum update interrupted and yum-complete-transaction wants to remove 253 pkgs
  • Running yum-complete-transaction renders the system inoperable after removing system critical packages

 

 

Resolution

  • While updating the system using yum if it finds incomplete or aborted yum transactions on a system it displays the message “There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.”

If due to some reason the previous transaction was incomplete or aborted then on the next yum install or update command, it would give this message. The “yum-complete-transaction” command would help to complete the previous incomplete or aborted transactions.

On execution of “yum-complete-transaction” it gives the list of packages which will be installed and removed to complete the previous transaction. It asks for confirmation if you would like to continue. On entering ‘Y’ it will complete the transaction. Before continuing (i.e hitting ‘Y’) *it is important to verify the list of packages that will be installed or removed by “yum-complete-transaction” .

Note: At the time of writing, there is a bug with “yum-complete-transaction” where, depending on the list of packages to install or remove from the previous transaction, it might offer to remove almost all the packages on the system. It is important to review the Transaction Summary and package list before hitting ‘Y’ to continue. If you are experiencing this issue, please run the following:

 

# package-cleanup --dupes
# yum-complete-transaction --cleanup-only
# yum update yum yum-utils
# yum-complete-transaction  (Note: At this point, it should not offer to remove so many packages. Please do check to make sure though.)
# yum clean all
# yum update

Example:
   # yum-complete-transaction
    Loaded plugins: rhnplugin
    There are 1 outstanding transactions to complete. Finishing the most recent one
    The remaining transaction had 3 elements left to run
    There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
    --> Running transaction check
    ---> Package dmidecode.i386 1:2.9-1.el5 set to be erased
    --> Processing Dependency: dmidecode >= 2.7 for package: hal
    ---> Package dnsmasq.i386 0:2.45-1.el5_2.1 set to be erased
    [..snip..]

    --> Finished Dependency Resolution

    ==================================================================================================================
     Package                               Arch               Version                     Repository             Size
    ==================================================================================================================
    Removing:
     dmidecode                             i386               1:2.9-1.el5                 installed             148 k
     dnsmasq                               i386               2.45-1.el5_2.1              installed             343 k
    Removing for dependencies:
     NetworkManager                        i386               1:0.7.0-9.el5               installed             3.3 M
     NetworkManager-glib                   i386               1:0.7.0-9.el5               installed             154 k

    Transaction Summary
    ==================================================================================================================
    Install      0 Package(s)        
    Update       0 Package(s)        
    Remove      4 Package(s)        

    Is this ok [y/N]:
If you do not want to complete the previous transaction, then use the "--cleanup-only" option. This would clean up only transaction journal files and exit.

Example :

  # yum-complete-transaction --cleanup-only
    Loaded plugins: rhnplugin
    Cleaning up unfinished transaction journals
    Cleaning up 2009-10-06.15:46.06



How to use yum to install RPMs required, for offline use?

Here is an example using “ffmpeg” as the package to download. I have tested the process on both Red Hat and CentOS 6.?

Install all the required package for the download process.

# yum install yum-plugin-downloadonly yum-utils createrepo
# mkdir /var/tmp/ffmpeg
# mkdir /var/tmp/ffmpeg-installroot

Note: The installroot is for the metada that will allow the full download of all dependencies.
# yum install --downloadonly --installroot=/var/tmp/ffmpeg-installroot --releasever=6 --downloaddir=/var/tmp/ffmpeg ffmpeg
Now, Generate the metadata needed to turn our new pile of RPMs into a YUM repo.

# createrepo --database /var/tmp/ffmpeg
# rm -rf /var/tmp/ffmpeg-installroot Configure the repo:
# vi /etc/yum.repos.d/offline-ffmpeg.repo
[offline-ffmpeg]
name=CentOS-$releasever - ffmpeg
baseurl=file:///var/tmp/ffmpeg
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

To check the missing dependencies:
# repoclosure --repoid=offline-ffmpeg

Then Offline: 

# yum --disablerepo=\* --enablerepo=offline-ffmpeg install ffmpeg

Good luck!!
 

What is Cloud Computing and Why Should You Care?

What Is Cloud Computing?

Cloud computing is a computing model that lets you access software, server, and storage resources over the Internet, in a self-service manner. Instead of having to buy, install, maintain and manage these resources on your own computer or device, you access and use them through a Web browser. Sometimes you might need to download a small piece of client code (i.e., software you install on your PC), but we’d still categorize that as cloud computing, because, for the most part, the real horsepower is supplied from the cloud.

At this point, many of you may be asking, I still don’t get why they call this “cloud” computing — why not Internet computing? The answer is that techies have long used cloud icons to represent the data centers, technologies, infrastructure and services that comprise the Internet — and the metaphor has stuck.

You can perform just about any computing task in the cloud. It’s likely that you already use several cloud solutions. For example, software-as-a-service (SaaS) or on-demand business applications, such as salesforce.com, Intuit QuickBooks Online or Citrix GoToMeeting are cloud applications; you access them from your Web browser, but the software, processing power and storage reside in the cloud.

Free Web services — such as Google Gmail or Microsoft Hotmail, or FaceBook and Twitter, for that matter — are also examples of cloud computing. Likewise, if you use online backup solutions, you’re storing your files in the cloud. And many managed services providers supply services such as network and security monitoring over the Internet. Another example is Amazon.com, which sells access to CPU cycles and storage as a service of its cloud infrastructure.

How Does Cloud Computing Work?

Cloud computing provides a simple way to access servers, storage, databases and a broad set of application services over the Internet. A Cloud services platform such as Amazon Web Services owns and maintains the network-connected hardware required for these application services, while you provision and use what you need via a web application.

Six Advantages and Benefits of Cloud Computing

Trade capital expense for variable expense

Instead of having to invest heavily in data centers and servers before you know how you’re going to use them, you can only pay when you consume computing resources, and only pay for how much you consume.

 

Benefit from massive economies of scale

By using cloud computing, you can achieve a lower variable cost than you can get on your own. Because usage from hundreds of thousands of customers is aggregated in the cloud, providers such as Amazon Web Services can achieve higher economies of scale which translates into lower pay as you go prices.

 

Stop guessing capacity

Eliminate guessing on your infrastructure capacity needs. When you make a capacity decision prior to deploying an application, you often either end up sitting on expensive idle resources or dealing with limited capacity. With cloud computing, these problems go away. You can access as much or as little as you need, and scale up and down as required with only a few minutes notice.

Increase speed and agility

In a cloud computing environment, new IT resources are only ever a click away, which means you reduce the time it takes to make those resources available to your developers from weeks to just minutes. This results in a dramatic increase in agility for the organization since the cost and time it takes to experiment and develop is significantly lower.

Stop spending money on running and maintaining data centers

Focus on projects that differentiate your business, not the infrastructure. Cloud computing lets you focus on your own customers, rather than on the heavy lifting of racking, stacking and powering servers.

Go global in minutes

Easily deploy your application in multiple regions around the world with just a few clicks. This means you can provide lower latency and a better experience for your customers simply and at minimal cost.

 

What to Consider

Behind the scenes, cloud computing vendors have to do a lot of work to manage all of the infrastructure, technology, and people that make this possible. To provide services easily, flexibly and profitably to thousands or even millions of users, they invest heavily in hardware, virtualization technologies, networking infrastructure and automation capabilities (any one of which would need its own article to fully explain).

There are thousands of cloud computing vendors and solutions out there. But they are not all are created equal — and neither are your needs in any given solution area. Think about how critical a particular function is to your business? What would happen if you couldn’t access data or use the application for a period of time? For instance, a small business needs higher service levels for an accounting solution than a freelancer requires for expense tracking. Before moving beyond a trial service, consider your needs for reliability, security, performance and support — and then at how well a vendor can meet them.

Cloud computing providers should provide details about how they protect data and ensure regulatory compliance, and they should explain their policies to provide you with your data if you decide to terminate the service or if they go out of business. If you pay for a service, you should also get a service level agreement(SLA) from the cloud vendor. The SLA documents service requirements supply ongoing metrics to ensure these requirements are met, and provides remuneration should the vendor fail to deliver on the agreed metrics.

 

Linux Interview! what to know

Common administrative commands in Red Hat Enterprise Linux 5, 6, and 7

System basics

Task RHEL5 RHEL6 RHEL7
View subscription information /etc/sysconfig/rhn/systemid /etc/sysconfig/rhn/systemid
subscription-manager identity
subscription-manager identity
Configure subscription rhn_register
subscription-manager 1
rhn_register
rhnreg_ks
subscription-manager
subscription-manager2
rhn_register 3
View RHEL version information /etc/redhat-release
View system profile sosreport
dmidecode
hwbrowser
sosreport
dmidecode
lstopo
lscpu

Basic configuration

Task RHEL5 RHEL6 RHEL7
Graphical configuration tools system-config-* gnome-control-center
Text-based configuration tools system-config-*-tui
Configure printer system-config-printer
Configure network system-config-network nmcli
nmtui
nm-connection-editor
Configure system language system-config-language localectl
Configure time and date system-config-date
date
timedatectl
date
Synchronize time and date ntpdate
/etc/ntp.conf
timedatectl
/etc/chrony.conf
ntpdate
Configure keyboard system-config-keyboard localectl
Configure SSH /etc/ssh/ssh_config
/etc/ssh/sshd_config
~/.ssh/config ssh-keygen

Jobs and services

Task RHEL5 RHEL6 RHEL7
List all services chkconfig –list
ls /etc/init.d/
systemctl -at service
ls /etc/systemd/system/*.service
ls /usr/lib/systemd/system/*.service
List running services service –status-all systemctl -t service –state=active
Start/stop service service name start
service name stop
systemctl start name.service
systemctl stop name.service
Enable/disable service chkconfig name on
chkconfig name off
systemctl enable name.service
systemctl disable name.service
View service status service name status systemctl status name.service
Check if service is enabled chkconfig name –list systemctl is-enabled name
Create new service file or modify configuration chkconfig –add systemctl daemon-reload
/etc/systemd/system/*.service
View run level/target runlevel
who -r
systemctl get-default
who -r
Change run level/target /etc/inittab
init run_level
systemctl isolate name.target
systemctl set-default
Configure logging /etc/syslog.conf /etc/rsyslog.conf /etc/rsyslog.conf
/etc/rsyslog.d/*.conf
/var/log/journal
systemd-journald.service
View logs /var/log /var/log
journalctl
Configure system audit add audit=1 to kernel cmdline
auditctl
/etc/audit/auditd.conf
/etc/audit/audit.rules
authconfig
/etc/pam.d/system-auth
pam_tty_audit kernel module
View audit output aureport /var/log/faillog
Schedule/batch tasks cron
at
batch
Find file by name locate
Find file by characteristic find
Create archive tar
cpio
zip

Kernel, boot, and hardware

Task RHEL5 RHEL6 RHEL7
Single user/rescue mode append 1 or s or init=/bin/bash to kernel cmdline append rd.break or init=/bin/bash to kernel cmdline
Shut down system shutdown
Power off system poweroff poweroff
systemctl poweroff
Halt system halt halt
systemctl halt
Reboot system reboot reboot
systemctl reboot
Configure default run level/target /etc/inittab systemctl set-default
Configure GRUB bootloader /boot/grub/grub.conf /etc/default/grub
grub2-mkconfig
grub-set-default
Configure kernel module modprobe
View hardware configured hwbrowser lshw (in EPEL)
Configure hardware device udev
View kernel parameters sysctl -a
cat /proc/cmdline
Load kernel module modprobe
Remove kernel module modprobe -r
View kernel version rpm -q kernel
uname -r

Software management

Task RHEL5 RHEL6 RHEL7
Install software yum install
yum groupinstall
yum install
yum group install
View software info yum info
yum groupinfo
yum info
yum group info
Update software yum update
Upgrade software yum upgrade
Configure software repository subscription-manager repos
/etc/yum.repos.d/*.repo
Find package owning file rpm -qf filename
yum provides filename-glob
View software version rpm -q packagename
View installed software rpm -qa
yum list installed

User management

Task RHEL5 RHEL6 RHEL7
Graphical user management system-config-users
Create user account useradd
Delete user account userdel
View/change user account details usermod
/etc/passwd
vipw
id
Create user group groupadd
Delete user group groupdel
Change group details groupmod
/etc/group
Change user password passwd
Change user permissions usermod
visudo
Change group permissions groupmod
visudo
Change password policy chage
View user sessions w

File systems, volumes, and disks

Task RHEL5 RHEL6 RHEL7
Default file system ext3 ext4 xfs
Create/modify disk partitions fdisk
parted
fdisk
gdisk
parted
ssm create
Format disk partition mkfs.filesystem_type (ext4, xfs)
mkswap
mkfs.filesystem_type (ext4, xfs)
mkswap
ssm create
Defragment disk space copy data to new file system
fsck (look for ‘non-contiguous inodes’)
copy data to new file system
fsck (look for ‘non-contiguous inodes’)
xfs_fsr
Mount storage mount
/etc/fstab
mount
/etc/fstab
ssm mount
Mount and activate swap /etc/fstab
swapon -a
Configure static mounts /etc/fstab
View free disk space df
View logical volume info lvdisplay
lvs
vgdisplay
vgs
pvdisplay
pvs
Create physical volume pvcreate pvcreate
ssm create (if backend is lvm)
Create volume group vgcreate vgcreate
ssm create (if backend is lvm)
Create logical volume lvcreate lvcreate
ssm create (if backend is lvm)
Enlarge volumes formatted with default file system vgextend
lvextend
resize2fs
vgextend
lvextend
xfs_growfs
ssm resize
Shrink volumes formatted with default file system resize2fs
lvreduce
vgreduce
XFS cannot currently be shrunk; copy desired data to a smaller file system.
Check/repair file system fsck fsck
ssm check
View NFS share showmount -e
mount
Configure NFS share /etc/exports
service nfs reload
/etc/exports
systemctl reload nfs.service
Configure on-demand auto-mounts /etc/auto.master.d/*.autofs
/etc/auto.*
Change file permissions chmod
chown
chgrp
umask (future file creation)
Change file attributes chattr
Change access control list setfacl

Networking

Task RHEL5 RHEL6 RHEL7
Configure name resolution /etc/hosts
/etc/resolv.conf
/etc/hosts
/etc/resolv.conf
nmcli con mod
Configure hostname /etc/sysconfig/network hostnamectl
/etc/hostname
nmtui
View network interface info ip addr
ifconfig
brctl
ip addr
nmcli dev show
teamdctl
brctl
bridge
Configure network interface /etc/sysconfig/network-scripts/ifcfg-* /etc/sysconfig/network-scripts/ifcfg-*
nmcli con [add|mod|edit]
nmtui
nm-connection-editor
View routes ip route
Configure routes ip route add
system-config-network
/etc/sysconfig/route-iface
ip route add
nmcli
nmtui
nm-connection-editor
/etc/sysconfig/route-iface
Configure firewall iptables and ip6tables
/etc/sysconfig/ip*tables
iptables and ip6tables
/etc/sysconfig/ip*tables
system-config-firewall
firewall-cmd
firewall-config
View ports/sockets ss
lsof
netstat
ss
lsof

Security and identity

Task RHEL5 RHEL6 RHEL7
Configure system security /etc/selinux/config
chcon
restorecon
semanage
setsebool
system-config-selinux
Report on system security sealert
LDAP, SSSD, Kerberos authconfig
authconfig-tui
authconfig-gtk
Network users getent

Resource management

Task RHEL5 RHEL6 RHEL7
Trace system calls strace
Trace library calls ltrace
Change process priority nice
renice
Change process run location taskset
Kill a process kill
pkill
killall
View system usage top
ps
sar
iostat
netstat
vmstat
mpstat
numastat
top
ps
sar
iostat
netstat
ss
vmstat
mpstat
numastat
tuna
top
ps
sar
iostat
ss
vmstat
mpstat
numastat
tuna
View disk usage df df
iostat

 

Simple questions

What is LD_LIBRARY_PATH?

  • LD_LIBRARY_PATH is an environment variable. It is used for debugging a new library or a non-standard library. It is also used to identify what directories need to be searched. Path to search for directories needs to give.
  • The variable can be set using setenv—LD_LIBRARY_PATH–$PATH.
  • It is used to search for the shared objects / dynamic libraries by the operating system for extendable functionality at runtime.

 

How to check Memory stats and CPU stats as a Linux admin?

Using ‘free’ & ‘vmstat’ command, we can display the physical and virtual memory statistics, respectively. With the help of ‘sar’ command, we can see the CPU utilization & other stats.

 

What are the different modes of Network bonding in Linux?

Below is a list of modes used in Network Bonding :
  • balance-rr or 0 – round-robin mode for fault tolerance and load balancing.
  • active-backup or 1 – Sets active-backup mode for fault tolerance.
  • balance-xor or 2 – Sets an XOR (exclusive-or) mode for fault tolerance and load balancing.
  • broadcast or 3 – Sets a broadcast mode for fault tolerance. All transmissions are sent on all slave interfaces.
  • 802.3ad or 4 – Sets an IEEE 802.3ad dynamic link aggregation mode. Creates aggregation groups that share the same speed & duplex settings.
  • balance-tlb or 5 – Sets a Transmit Load Balancing (TLB) mode for fault tolerance & load balancing.
  • balance-alb or 6 – Sets an Active Load Balancing (ALB) mode for fault tolerance & load balancing.

How to check and verify the status of the bond interface?

Using the command ‘cat /proc/net/bonding/bond0,’ we can check what mode is enabled and what LAN cards are used in this bond. In this example, we have one one bond interface. However, we can have multiple bond interfaces like bond1, bond2 and so on.

 

What is Puppet Server?

In computing, Puppet is an open-source software configuration management tool. It runs on many Unix-like systems as well as on Microsoft Windows, and includes its own declarative language to describe system configuration. 

 

What is the name and path of the main system log?

By default, the main system log is ‘/var/log/messages’. This file contains all the messages and the script written by the user. By default, all scripts are saved in this file. This is the standard system log file, which contains messages from all system software, non-kernel boot issues, and messages that go to ‘dmesg’. dmesg is a system file that is written upon system boot.

 

What is YUM?

yum is the primary tool for getting, installing, deleting, querying, and managing Red Hat Enterprise Linux RPM software packages from official Red Hat software repositories, as well as other third-party repositories. yum is used in Red Hat Enterprise Linux versions 5 and later. Versions of Red Hat Enterprise Linux 4 and earlier used up2date.

 

What is the difference between ext2 and ext3 file systems?

  • The ext3 file system is an enhanced version of the ext2 file system.
  • The most important difference between Ext2 and Ext3 is that Ext3 supports journaling.
  • After an unexpected power failure or system crash (also called an unclean system shutdown), each mounted ext2 file system on the machine must be checked for consistency by the e2fsck program. This is a time-consuming process and during this time, any data on the volumes is unreachable.
  • The journaling provided by the ext3 file system means that this sort of file system check is no longer necessary after an unclean system shutdown. The only time a consistency check occurs using ext3 is in certain rare hardware failure cases, such as hard drive failures. The time to recover an ext3 file system after an unclean system shutdown does not depend on the size of the file system or the number of files. Rather, it depends on the size of the journal used to maintain consistency. The default journal size takes almost a second to recover, depending on the speed of the hardware.

 

Explain /proc filesystem?

/proc is a virtual file system that provides detailed information about Linux kernel, hardware and running processes. Files under /proc directory named as Virtual files.
Since /proc contains virtual files, it is called virtual file system. These virtual files have unique qualities. Most of them are listed as zero bytes in size.
Virtual files such as /proc/interrupts, /proc/meminfo, /proc/mounts, and /proc/partitions provide an up-to-the-moment glimpse of the system’s hardware. Others: /proc/filesystems file and the /proc/sys/ directory provide system configuration information and interfaces.

 

 

Beginner Linux Users: Don’t Be Scared of the Terminal

The Terminal Is Optional

Whether you want to install software, configure your network, or tweak other system settings, you can do it from the terminal – but you can also do it from the graphical interface. Most settings you would want to change are easily accessible in the standard graphical control panels.

If you have never tried using Linux, you may have an expectation that you will have to learn terminal commands to get around, but this has become less and less true with each passing year. Give Ubuntu a try and you may be surprised at how little you’ll need to use the terminal. Many users shouldn’t need to touch the terminal at all.

(It is possible that, if your hardware isn’t well-supported, you may have to use terminal commands. With properly supported hardware, you should not have to mess around with the terminal to make things work.)

 

Open Source AI Tools

In open source, no matter how original your own idea seems, it is always wise to see if someone else has already executed the concept. For organizations and individuals interested in leveraging the growing power of artificial intelligence (AI), many of the best tools are not only free and open source but, in many cases, have already been hardened and tested.

At leading companies and non-profit organizations, AI is a huge priority, and many of these companies and organizations are open sourcing valuable tools. Here is a sampling of free, open-source AI tools available to anyone.

Acumos. Acumos AI is a platform and open source framework that makes it easy to build, share, and deploy AI apps. It standardizes the infrastructure stack and components required to run an out-of-the-box general AI environment. This frees data scientists and model trainers to focus on their core competencies rather than endlessly customizing, modeling, and training an AI implementation.

Acumos is part of the LF Deep Learning Foundation, an organization within The Linux Foundation that supports open source innovation in artificial intelligence, machine learning, and deep learning. The goal is to make these critical new technologies available to developers and data scientists, including those who may have limited experience with deep learning and AI. The LF Deep Learning Foundation just recently approved a project lifecycle and contribution process and is now accepting proposals for the contribution of projects.

Facebook’s Framework. Facebook has open-sourced its central machine learning system designed for artificial intelligence tasks on a large scale, and a series of other AI technologies. The tools are part of a proven platform in use at the company. Facebook has also open sourced a framework for deep learning and AI called Caffe2.

Speaking of Caffe. Yahoo also released its key AI software under an open source license. TheCaffeOnSpark tool is based on deep learning, a branch of artificial intelligence particularly useful in helping machines recognize human speech or the contents of a photo or video. Similarly, IBM’s machine learning program known as SystemML is freely available to share and modify through the Apache Software Foundation.

Google’s Tools. Google spent years developing its TensorFlow software framework to support its AI software and other predictive and analytics programs. TensorFlow is the engine behind several Google tools you may already use, including Google Photos and the speech recognition found in the Google app.

Two AIY kits open sourced by Google let individuals easily get hands-on with artificial intelligence. Focused on computer vision and voice assistants, the two kits come as small self-assembly cardboard boxes with all the components needed for use. The kits are currently available at Target in the United States and are based on the open-source Raspberry Pi platform — more evidence of how much is happening at the intersection of open source and AI.

H2O.ai. I previously covered H2O.ai, which has carved out a niche in the machine learning and artificial intelligence arena because its primary tools are free and open source.  You can get the main H2O platform and Sparkling Water, which works with Apache Spark, simply by downloading them. These tools operate under the Apache 2.0 license, one of the most flexible open source licenses available, and you can even run them on clusters powered by Amazon Web Services (AWS) and others for just a few hundred dollars.

Microsoft Onboard“Our goal is to democratize AI to empower every person and every organization to achieve more,” Microsoft CEO Satya Nadella has said. With that in mind, Microsoft is continuing to iterate its Microsoft Cognitive Toolkit. It’s an open source software framework that competes with tools such as TensorFlow and Caffe. Cognitive Toolkit works with both Windows and Linux on 64-bit platforms.

“Cognitive Toolkit enables enterprise-ready, production-grade AI by allowing users to create, train, and evaluate their own neural networks that can then scale efficiently across multiple GPUs and multiple machines on massive data sets,” reports the Cognitive Toolkit Team.

 

The way Entrepreneur Elon Musk Is Changing the World

The super-fast “Hyperloop” travel concept is just the latest in a series of big, bold dreams by billionaire entrepreneur Elon Musk.

Musk unveiled his proposed Hyperloop transportation system Monday (Aug. 12), claiming that it could blast passenger-packed pods through long tubes at about 760 mph (1,220 km/h) using energy derived from the sun.

The Hyperloop is potentially revolutionary, making it a typical Musk idea. Here’s a look at six ways the South African-born billionaire is changing the world — or is hoping to in the future.

 

Pioneering e-commerce

Elon co-founded the online financial services company X.com in 1999. In 2000, X.com merged with Confinity, which had developed an online payment system called PayPal. Though the combined firm at first retained the X.com moniker, it changed its name to PayPal in early 2001.

PayPal, which has helped make Internet payments and money transfers routine, grew quickly and dramatically. It was acquired by eBay in October 2002.

Private spaceflight

Musk founded the private spaceflight firm SpaceX in 2002 and currently serves as its CEO and chief designer.

SpaceX has already made history, becoming the first private company to deliver a spacecraft to the International Space Station. SpaceX’s unmanned Dragon capsule first visited the orbiting lab on a demonstration mission in May 2012 and has completed two bona fide cargo runs since. The company holds a $1.6 billion contract with NASA to make 12 such flights with Dragon and its Falcon 9 rocket.

SpaceX is also developing a crewed version of Dragon, and Musk hopes to score another NASA deal to fly astronauts to the space station. The firm is also working on a prototype reusable rocket called Grasshopper, in the hopes of making spaceflight far cheaper and more efficient.

Musk has said repeatedly that he founded SpaceX primarily to help humanity become a multiplanet species.

 

Making electric cars cool

Musk has a long-held interest in electric-vehicle technology, and in 2003, he co-founded Tesla Motors, which manufactures electric cars and the battery packs that power them.

Tesla is helping many people view electric cars in a new light. For example, the company’s Model S sedan was named 2013 Car of the Year by both Motor Trend and Automobile Magazine. One version of the Model S can go from 0 to 60 mph (96 km/h) in 4.0 seconds, according to Motor Trend.

The company is expanding rapidly. In May, officials announced that Tesla had already paid off the entire loan it received from the U.S. Department of Energy in 2010, nine years ahead of schedule. The firm also notched profits in the first and second quarters of 2013.

Renewable energy

Musk’s interest in electric cars stems in part from his concern about the effects of climate change, so it makes sense that he’s involved with a big renewable-energy venture.

Musk serves as chairman of SolarCity, which designs and installs clean-energy systems for households, businesses, universities and other organizations. The firm, which was founded in 2006, has thousands of customers across 14 states, according to its website.

 

The Hyperloop

Musk explained Monday, would use electric motors to accelerate 6.5-foot-wide (2 meters) pods to nearly supersonic speeds. These pods would zoom through long tubes, which would be mounted on pylons to minimize construction costs, reduce earthquake risk and ease right-of-way issues.

Musk sees the system as a cheaper, faster alternative to California’s proposed $70 billion high-speed rail system, estimating that a Hyperloop line could be built from Los Angeles to San Francisco for $6 billion or so. (A trip between the two cities would take just 30 minutes, Musk said.)

The entrepreneur hopes other innovators will improve upon the Hyperloop design and run with it, since he’s busy developing Tesla and SpaceX. But Musk said he’s interested in building a demonstration model to help get the Hyperloop off the ground.

“I’d like to see something like this happen,” Musk told reporters during a conference call Monday. “I don’t really care much one way or the other if I have any economic outcome here. But it would be cool to see a new form of transport happen.”

 

20 Practical Ruby Loop Command Examples – For, Each, While, Until

Some operations in computer programming are best served with a loop.

A loop is the repetitive execution of a piece of code for a given amount of repetitions or until a certain condition is met. We will cover while loops, do/while loops, and for loops.

In Ruby programming language, on a very high-level, the following are 8 different types of commands (functions) that you can use to loop through stuffs.

  1. Loop
  2. Until
  3. While
  4. Do – While
  5. For
  6. Each
  7. Upto
  8. Times

In this tutorial, we’ll discuss the following 20 examples that will cover all of the Ruby loop related commands.

  1. Quick Summary – For the Impatient
  2. Loop Command – Just Keeps Looping
  3. Loop Command – Break out of It
  4. Loop Command – Just Skip one Particular Loop using Next
  5. Until Command – Keep looping until it is true
  6. While Command – While it is true, keep looping
  7. Do-While Loop – While at the end of the block
  8. For Command – Loop through a Number Range
  9. For using Array – Loop through an Array of Elements
  10. For using Array Length
  11. For using Array Size
  12. For inside a For – Nested For Loops
  13. Each Command – Popular Loop Method in Ruby
  14. Each Command – Loop through Multiple Strings in an Array
  15. Each_Index Command – Loop through Only Array Indexes
  16. Each_with_Index Command – Loop through an Array using Index and Value
  17. Each inside a Each – Nested Each Command
  18. Each Command – Loop through Static Number Ranges
  19. Times Command – Loop through X number of Times
  20. Upto Command – Loop through Upto X number Starting from Y

1. Quick Summary – For the Impatient

For the impatient, quick snippets of major loop commands are shown below. For more details on these commands, read through the full tutorial.

Loop command:

loop do
 puts "do something"
end

Until command:

until count > 5
  puts "do something"
end

While command:

while count <= 5
  puts "do something"
end

For command – loop 5 times

for i in 1..5 do
  puts "#{i}"
end

For command – loop through an array:

for i in myarray do
  puts "#{i}"
end

Each command – loop 5 times

(1..5).each do |i|
  puts "#{i}"
end

Each command – loop through an array

myarray.each do |element|
  puts "#{element}"
end

Each command – loop through an array with both index and elements

myarray.each_with_index do |element,i|
  puts "#{i}. #{element}"
end

Times command – loop 5 times

5.times do |i|
  puts "#{i}"
end

Upto command – loop from 2 through 5

2.upto(5) do |i|
  puts "#{i}"
end

2. Loop Command – Just Keeps Looping

The first is the loop command itself. All it does is that it keeps going on an infinite loop.

As you see below, the following basic loop command example, will repeatedly keep printing the stuff between the “do” and “end” block until you press Ctrl-C

# cat loop1.rb
loop do
  puts "The Geek Stuf"
  puts "Press Ctrl-C to Exit!"
end

Execute the above program to test it. Make sure you press Ctrl-C to exit out of the loop

# ruby loop1.rb
The Geek Stuf
^CPress Ctrl-C to Exit!
loop1.rb:2: Interrupt
    from loop1.rb:1:in `loop'
    from loop1.rb:1

Also, keep in mind that for pretty much any loop commands in Ruby, instead of “do” and “end” you can also specify the body of the loop within curly brackets { } as shown below.

The following example is exactly same as above, but using braces .

# cat loop2.rb
loop {
  puts "The Geek Stuf"
  puts "Press Ctrl-C to Exit!"
}

Warning: Don’t give { on a separate line! If you do, you’ll get an error message. The following is not correct as the { is on the next line to loop. It should be on the same line as loop command.

# cat loop2.rb
loop
{
  puts "The Geek Stuf"
  puts "Press Ctrl-C to Exit!"
}

The above example will throw the following error message.

# ruby loop2.rb
loop2.rb:3: syntax error, unexpected tSTRING_BEG, expecting kDO or '{' or '('
  puts "The Geek Stuf"
        ^
loop2.rb:5: syntax error, unexpected '}', expecting $end

3. Loop Command – Break out of It

The previous loop command example is pretty much useless as it just keeps looping through.

So, to break out of a loop command, use the break command as shown below.

When you do a “break”, it will just stop the execution of the loop and come out.

# cat loop3.rb
loop do
  puts "The Geek Stuff"
  break
end

The above example will loop through just one time.

# ruby loop3.rb
The Geek Stuff

Looping through just one time, is pretty much useless also. So, in the following loop command example, it will loop through total of 5 times before breaking out of the loop.

As you can imagine, to keep track of the number of times to loop, we are using a variable called count and increment it by 1 every time. When the value of the count is equal to 6, we’ll break out of the loop.

# cat loop4.rb
count = 1
loop do
  puts "#{count}" " The Geek Stuff"
  count = count + 1
  if count == 6
    break
  end
end

The following is the output of the above example, which loops through exactly 5 times.

# ruby loop4.rb
1 The Geek Stuff
2 The Geek Stuff
3 The Geek Stuff
4 The Geek Stuff
5 The Geek Stuff

4. Loop Command – Just Skip one Particular Loop using Next

Just like break, inside a loop command, you can also use next.

Next will just skip the rest of the commands in the loop-block for the current execution, but will continue the loop from the top again.

So, in the following example, using if command, we are checking if the value of count is 3. When it is 3, we are executing “next” command, which will skip the remainder of the loop-block and continue the loop from the top again.

This means that the following example will skip only the 3rd execution of the loop.

# cat loop5.rb
count = 1
loop do
  if count == 3
    count = count + 1
    next
  end
  puts "#{count}" " The Geek Stuff"
  count = count + 1
  if count == 6
    break
  end
end

The following output indicates that the above example has skipped the 3rd execution of the loop.

# ruby loop5.rb
1 The Geek Stuff
2 The Geek Stuff
4 The Geek Stuff
5 The Geek Stuff

5. Until Command – Keep looping until it is true

Until is another type of ruby command to loop through stuff.

In until command, the body will get executed until the condition is true. i.e Keep looping as long the condition is false. When the condition becomes true, it will stop the loop.

In the following example, as long as the value of the variable count is not greater than 5, it will keep looping. When the condition becomes true (i.e when count is greater than 5), it will stop looping.

# cat until1.rb
count = 1
until count > 5
  puts "#{count}" " The Geek Stuff"
  count = count + 1
end

As you see from the output below, the above example has executed the loop 5 times using until command.

# ruby until1.rb
1 The Geek Stuff
2 The Geek Stuff
3 The Geek Stuff
4 The Geek Stuff
5 The Geek Stuff

6. While Command – While it is true, keep looping

The second type of command to loop through stuff is while command.

In while command, the body will get executed as long the condition specified in the while command is true.

So, the idea here is that while the condition is true, it will keep looping forever. So, it is your responsibility to make sure the condition becomes false at some point in time.

In the following example, the while will keep looping the body until the count is less than or equal to 5. We are increasing the count inside the loop-body.

So, the following example will loop through 5 times.

# cat while1.rb
count = 1
while count <= 5
  puts "#{count}" " The Geek Stuff"
  count = count + 1
end

As you see from the output below, the above example has executed the loop 5 times using while command.

# ruby while1.rb
1 The Geek Stuff
2 The Geek Stuff
3 The Geek Stuff
4 The Geek Stuff
5 The Geek Stuff

7. Do-While Loop – While at the end of the block

In the previous example, we had the while command at the beginning of the loop.

Typically in most programming languages, when you put the while command at the end of the loop, it is called do-while loop.

Ruby also supports the format of do-while as shown in the following example.

One thing to keep in mind here is that, a do-while loop will always execute the body of the loop at-least once.

This is because we are not checking for any condition at the beginning of the loop. So, the first time the loop is always executed.

At the end of the 1st loop, the condition is checked. As long as the condition is true, it will keep looping.

So, the following example will execute the loop 1st time, and then as long as the condition is true, it will keep looping.

# cat do-while1.rb
count = 1
begin
  puts "#{count}" " The Geek Stuff"
  count = count + 1
end while count <= 5

As you see from the output below, the above example has executed the loop 5 times using do-while command.

# ruby do-while1.rb
1 The Geek Stuff
2 The Geek Stuff
3 The Geek Stuff
4 The Geek Stuff
5 The Geek Stuff

8. For Command – Loop through a Number Range

Almost all programming languages have a for command to loop through stuff. Ruby is no exception.

The following example shows how to loop through a range of numeric values using a simple for loop.

The range is specified in the format of start-value and end-value separated by two periods (without any space in between them)

In the following example, the start-value of the range is 1. The end-value of the range is 5. count is the name of the variable that hold the current value of the loop.

# cat for1.rb
for count in 1..5 do
  puts "#{count}" " The Geek Stuff"
end

The following output indicates that the above example executed the loop 5 times using for command

# ruby for1.rb
1 The Geek Stuff
2 The Geek Stuff
3 The Geek Stuff
4 The Geek Stuff
5 The Geek Stuff

9. For using Array – Loop through an Array of Elements

Apart from giving a number range in the for command, you can also specify an array of elements to loop through.

In the following example, we have an array called “myarray”. In the for command, we’ve just specified this array name to loop through.

This will just loop through all the elements in the array one by one using the for command.

# cat for2.rb
myarray = [ 101, 201, 301, 401, 501 ]
for i in myarray do
  puts "#{i}"
end

As you see from the following output, it looped through all the elements in the array and printed them accordingly.

# ruby for2.rb
101
201
301
401
501

You can also loop through an array with string values as shown below.

# cat for2.1.rb
myarray = [ "The", "Geek", "Stuff" ]
for i in myarray do
  puts "#{i}"
end

As you see from the following output, the above example just looped through myarray which contains three string elements and printed them out.

# ruby for2.1.rb
The
Geek
Stuff

10. For using Array Length

In a for loop command, you can also specify the array-length in the range as the end-value to loop through an array as shown below.

# cat for3.rb
myarray = [ "The", "Geek", "Stuff" ]
maxsize = myarray.length
for i in 1..maxsize
  puts "#{i}" " The Geek Stuff"
end

In the above example, myarray contains total of three elements. So, marray.length will return 3. We are using this value in the for command range as 1..maxsize

So, we are not really looping through the array. We are kind of looping through the array indexes indirectly. There is a better method to loop through an array using indexes, which is explained in one of the following examples.

As you see from the following output, the loop is executed, exactly 3 times, which is the length of the array.

# ruby for3.rb
1 The Geek Stuff
2 The Geek Stuff
3 The Geek Stuff

11. For using Array Size

The following example is very similar to the previous example. But, we are using array size instead of length.

# cat for4.rb
myarray = [ "The", "Geek", "Stuff" ]
for i in 0...myarray.size
  puts "#{i}" " The Geek Stuff"
end

Keep in mind that:
Array length will return how many elements are in the array. We got 3 in previous example. So, if you want to loop through from 1, 2, 3 — use array length.
Array size will return total number of elements in the array minus 1. So, we got 2 in this example. So, if you want to loop through from 0, 1, 2 — use array size.

As you see from the following output, the array size returned 2. So, we are looping through from 0 through 2 in our for loop range.

# ruby for4.rb
0 The Geek Stuff
1 The Geek Stuff
2 The Geek Stuff

12. For inside a For – Nested For Loops

You can also have for loop inside a for loop. This is called nested for loops as shown in the following example.

The outer for loop will loop through the “names” array. The inner for loop will loop through the “things” array.

So, for each person in the names array, it will loop through every item in the things array.

# cat for5.rb
names = [ "John", "Jason", "Lisa" ]
things = [ "Chocolate", "Sugar" ]
counter = 1
for name in names
  puts "#{counter}. #{name} likes: "
  counter = counter + 1
  for item in things
    puts "  #{item}"
  end
end

As you see from the following output, for each person, it has looped through all the things using a nested for loop format.

# ruby for5.rb
1. John likes:
  Chocolate
  Sugar
2. Jason likes:
  Chocolate
  Sugar
3. Lisa likes:
  Chocolate
  Sugar

13. Each Command – Popular Loop Method in Ruby

In Ruby, the recommended method to loop through stuff is using each command as shown below.

The syntax of each command is bit different than the traditional for loop, while loop, etc.

The following example explains how to loop through an array of numbers using each command in ruby.

# cat iterator1.rb
counter = [ 1, 2, 3, 4, 5 ]
counter.each do |i|
  puts "#{i} The Geek Stuff"
end

In the above:

  • counter is the name of the array that contains array of numbers.
  • counter.each – Here we are adding .each to the array variable name. This will loop through the counter array.
  • do … end – This is the loop body (just like other loop command examples)
  • |i| – This is specific to each command. This indicates that the variable i will hold the current value of the array during the looping. You can use this variable to manipulate the individual array element in side the array.

As you see from the following output, we’ve looped through the array variable using the each command and printed the output.

# ruby iterator1.rb
1 The Geek Stuff
2 The Geek Stuff
3 The Geek Stuff
4 The Geek Stuff
5 The Geek Stuff

14. Each Command – Loop through Multiple Strings in an Array

This is similar to the previous each example, but instead of looping through an array of numbers, here we are looping through an array of strings.

# cat iterator2.rb
title = [ "The", "Geek", "Stuff" ]
counter = 1
title.each do |i|
  puts "#{counter}. #{i}"
  counter = counter + 1
end

As you see from the following output, the each command has looped through out title array and printed all the individual elements one by one.

# ruby iterator2.rb
1. The
2. Geek
3. Stuff

15. Each_Index Command – Loop through Only Array Indexes

If you just want to loop through the indexes of the array and not the array elements themselves, then use the each_index command as shown below.

# cat iterator4.rb
title = [ "The", "Geek", "Stuff" ]
title.each_index do |i|
  puts "#{i}"
end

In the above:

  • title is the array that contains three string elements.
  • title.each_index – This indicates that we like to loop through the indexes of our title array (not the array elements, just the index of the elements)
  • do … end – This is the loop body (just like other loop command examples)
  • |i| – This indicates that the variable i will hold the current value of whatever we are looping through. Since we are looping through the indexes, this will hold the current value of the index that we are looping through.

As you see from the following output, this has printed the indexes of the array elements. Since we have three elements in the array, this example has printed 0, 1 and 2.

# ruby iterator4.rb
0
1
2

Please keep in mind that array index always starts from 0 (not from 1)

16. Each_with_Index Command – Loop through an Array using Index and Value

While it is great that each command loops through elements, and each_index loops through indexes.

What if you want to loop through both indexes and elements.

That is exactly why we have each_with_index command as shown in the following example.

In this example, the each_with_index will loop through each individual item, and store both the element value and index value during the loop-body execution in two different variables.

# cat iterator3.rb
title = [ "The", "Geek", "Stuff" ]
title.each_with_index do |element,i|
  puts "#{i}. #{element}"
end

In the above:

  • title is the array that contains three string elements.
  • title.each_with_index – This indicates that we like to loop through both the array values and indexes
  • do … end – This is the loop body (just like other loop command examples)
  • |element,i| – Here we are specifying two variables. The 1st variable (element) will hold the value of the individual array element. The 2nd variable i will hold the value of the indexes of that particular element.
  • puts “#{i}. #{element}” – In the loop body, we are using both individual element and it’s corresponding index value.

As you see from the following output, this example prints both the index and the individual array element value.

# ruby iterator3.rb
0. The
1. Geek
2. Stuff

17. Each inside a Each – Nested Each Command

You can also have each inside an each. This is called Nested each, which is similar to the nested for loop example that we saw earlier.

The outer for loop will loop through the “names” array. The inner for loop will loop through the “things” array.

So, for each person in the names array, it will loop through every item in the things array.

# cat iterator5.rb
names = [ "John", "Jason", "Lisa" ]
things = [ "Chocolate", "Sugar" ]
counter = 1
names.each do |name|
  puts "#{counter}. #{name} likes: "
  counter = counter + 1
  things.each do |item|
    puts "  #{item}"
  end
end

As you see from the following output, for each person, it has looped through all the things using a nested each loop format.

# ruby iterator5.rb
1. John likes:
  Chocolate
  Sugar
2. Jason likes:
  Chocolate
  Sugar
3. Lisa likes:
  Chocolate
  Sugar

18. Each Command – Loop through Static Number Ranges

Instead of looping through an array, you can also loop through static numbers from a range as shown in the following example.

# cat iterator6.rb
(1..5).each do |counter|
  puts "#{counter} The Geek Stuff"
end

In the above:

  • (1..5).each – This indicates that we’ll be looping through the given range using each command. The given range is 1 through 5
  • do … end – This is the loop body (just like other loop command examples)
  • |counter| – This indicates that the variable counter will hold the current value of whatever we are looping through.

As you see from the following output, ther above command has looped through the given static range using each command.

# ruby iterator6.rb
1 The Geek Stuff
2 The Geek Stuff
3 The Geek Stuff
4 The Geek Stuff
5 The Geek Stuff

19. Times Command – Loop through X number of Times

Times is a very helpful loop command, which will help you to quickly loop through x number of times.

The following example will loop through the loop-body 5 times.

# cat times1.rb
5.times do |i|
  puts "#{i} The Geek Stuff"
end

In the above:

  • 5.times – This indicates that number of time that we like to loop through. Here we’ll be looping through 5 times
  • do … end – This is the loop body (just like other loop command examples)
  • |i| – This indicates that the variable i will hold the current value of the loop counter i.e 1st loop, or 2nd loop, or 3rd loop, etc.

One important thing to keep in mind is that, the times command will always start from 0.

So, when we say 5.times, it means: 0, 1, 2, 3 and 4

As you see from the following output, the above example looped through 5 times, but starting from 0 through 4.

# ruby times1.rb
0 The Geek Stuff
1 The Geek Stuff
2 The Geek Stuff
3 The Geek Stuff
4 The Geek Stuff

20. Upto Command – Loop through Upto X number Starting from Y

Another useful command is upto.

Unlike times command, you can specify the starting number for the loop.

The following example is similar to the previous example, but it starts from 1 (instead of 0) and loops through 5 times.

# cat upto1.rb
1.upto(5) do |i|
  puts "#{i} The Geek Stuff"
end

As you see from the following output, the above example looped through 5 times, but starting from 1 through 5.

# ruby upto1.rb
1 The Geek Stuff
2 The Geek Stuff
3 The Geek Stuff
4 The Geek Stuff
5 The Geek Stuff

In the following example, we are starting from 3 and looping through upto 6. So, this will loop through: 3, 4, 5 and 6

# cat upto2.rb
3.upto(6) do |i|
  puts "#{i} The Geek Stuff"
end

The following example has looped through 4 times using upto command, but starting from 3 through 6.

# ruby upto2.rb
3 The Geek Stuff
4 The Geek Stuff
5 The Geek Stuff
6 The Geek Stuff

What are Quantum computers and how do they work? WIRED explains

Google, IBM and a handful of startups are racing to create the next generation of supercomputers. Quantum computers, if they ever get started, will help us solve problems, like modeling complex chemical processes, that our existing computers can’t even scratch the surface of.

But the quantum future isn’t going to come easily, and there’s no knowing what it’ll look like when it does arrive. At the moment, companies and researchers are using a handful of different approaches to try and build the most powerful computers the world has ever seen. Here’s everything you need to know about the coming quantum revolution.

What is quantum computing?

Quantum computing takes advantage of the strange ability of subatomic particles to exist in more than one state at any time. Due to the way the tiniest of particles behave, operations can be done much more quickly and use less energy than classical computers.

In classical computing, a bit is a single piece of information that can exist in two states – 1 or 0. Quantum computing uses quantum bits, or ‘qubits’ instead. These are quantum systems with two states. However, unlike a usual bit, they can store much more information than just 1 or 0, because they can exist in any superposition of these values.

What can quantum computers do that normal one can’t?

Quantum computers operate on completely different principles to existing computers, which makes them really well suited to solving particular mathematical problems, like finding very large prime numbers. Since prime numbers are so important in cryptography, it’s likely that quantum computers would quickly be able to crack many of the systems that keep our online information secure. Because of these risks, researchers are already trying to develop technology that is resistant to quantum hacking, and on the flipside of that, it’s possible that quantum-based cryptographic systems would be much more secure than their conventional analogs.

Researchers are also excited about the prospect of using quantum computers to model complicated chemical reactions, a task that conventional supercomputers aren’t very good at all. In July 2016, Google engineers used a quantum device to simulate a hydrogen molecule for the first time, and since them, IBM has managed to model the behavior of even more complex molecules. Eventually, researchers hope they’ll be able to use quantum simulations to design entirely new molecules for use in medicine. But the holy grail for quantum chemists is to be able to model the Haber-Bosch process – a way of artificially producing ammonia that is still relatively inefficient. Researchers are hoping that if they can use quantum mechanics to work out what’s going on inside that reaction, they could discover new ways to make the process much more efficient.