Category Archives: Blog

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.

 

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.

Data Privacy & Federal Government Priorities

What is the Federal Data Strategy?

The use of data is transforming the world. The way the Federal Government provides, maintains, and uses data has a unique place in society and maintaining trust in federal data is pivotal to a democratic process. The Federal Government needs a coordinated and integrated approach to using data to deliver on mission, serve the public, and steward resources while respecting privacy and confidentiality.

The Federal Data Strategy will define Principles, Practices, and a Year 1 Action Plan to deliver a more consistent approach to federal data stewardship, use, and access. The Federal Data Strategy development team will also test solutions and assumptions along the way with The Data Incubator Project, which will help identify priority use cases and methods that should be replicated or scaled.

The Facebook – Cambridge Analytica fiasco may have grabbed headlines, but in reality, this is but one example of the data misuse and data privacy issues that are currently impacting nearly every industry sector. Consider for a moment, the potential impact of a cyberattack on a federal government agency. In the face of ever-evolving sophisticated cyber threats, federal agencies require increasingly complex data security solutions. Here are the primary data security concerns we’re currently hearing about from clients in the federal space and our recommendations to address these concerns.

Compromised Communications

Another area in which Washington seeks to outsmart digital criminals is in the prevention of eavesdropping. For example MSI catchers or MDIs (mobile device identifiers), also referred to as stingrays, are rogue mobile cell towers that intercept a phone’s voice and data transmission thereby providing the adversary full access to the individual’s phone conversations and text messages.

Stingray hardware is portable and can easily fit inside a backpack. Any member of Congress or government employee using their cellphone in the street could have their conversation intercepted. Even if the person is in their office, a nearby stingray could capture the call as long as it’s within range. The reality is anyone can easily listen in on official government conversations and messages. The Department of Homeland Security publicly acknowledged this activity in April 2018, but the existence of these devices has been known for years – maybe a decade. The issue has only recently appeared on the public radar, but addressing it is a serious matter of national security.

Standard cell phone service is highly vulnerable to hacking, and even carrier-grade cell services aren’t designed with extensive levels of security. Anytime data is archived with a third party, the chances for a breach increase substantially. For this reason, Silent Circle’s secure communications products use “peer-to-peer” encryption. For phones equipped with our Silent Phone application, any voice or text communication is encrypted from the sender’s device to the other party’s device. End-to-end encryption is truly an ideal defense against stingray interception because even if the conversation gets routed through a cell tower simulator, the communication remains encrypted.