How Do You Use a Generator and the Yield Keyword in Python?

Problem scenario
You want to use a generator in Python.  You also want to use the yield keyword in Python.  How do you use these?

Solution
The short answer to the question about how do you use a generator is to create a function with the yield keyword (source Programiz.com).  “Both yield and return will return some value from a function.”  (The source of this quote is 

How Do You Create Your Own Dockerfile to Create a Flask Application?

Problem scenario
You want to use Flask inside a Docker container.  You want to build your own image for the Docker container.  How do you create your own Dockerfile to create a Flask application?

Solution
Prerequisite

Install Docker.  See this posting if you need directions.

Procedures
1.  Create a Dockerfile with the following content (you may want to replace “16.04” with “latest” and if you want to change the location of where the .py file is,

How Do You Install Ansible on a Debian Linux Server Running in GCP?

Problem scenario
You are using Google Cloud Platform, and you have a Debian server.  You do not want to configure any PPAs for your system.*  How do you install and configure Ansible on a Debian Linux system?

Solution
Prerequisite

We strongly recommend having 2.5 GB of memory (either in RAM or with a combination of RAM and swap space).  

How Do You Use GCP’s App Engine?

Problem scenario
You want to leverage GCP’s serverless App Engine component with its scalability.  What do you do?

Solution
1.  Go to the cloud shell.  In the web UI of GCP in the upper righthand corner go to the icon that looks like this: “>_” and click on it.  From cloud shell run these commands:

git clone https://github.com/GoogleCloudPlatform/python-docs-samples

cd python-docs-samples/appengine/standard_python37/hello_world

virtualenv –python python3 ~/envs/hello_world

source ~/envs/hello_world/bin/activate

pip install -r requirements.txt

python main.py

2. 

How Do You Create a Docker Image That Has Java 10 in It?

Problem scenario
You want to create Docker containers with Java 9.  How do you create a Docker image to make containers with Java 9 installed in them?

These directions were updated on 12/26/18.

Solution
Prerequisite

This assumes that you have Docker installed. If you need assistance with this, see these postings depending on your operating system:

Debian/Ubuntu
CentOS/Fedora/RHEL
SUSE

Procedures
1. 

How Do You Troubleshoot the SonarQube Service Not Working with a “vendor preset: disabled” Error?

Problem scenario
The SonarQube service failed to start.  

You see this message:

? sonar.service – SonarQube service
   Loaded: loaded (/etc/systemd/system/sonar.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Mon 2018-05-21 14:34:34 UTC; 12min ago

May 21 14:34:33 sonarserver systemd[1]: Started SonarQube service.
May 21 14:34:34 sonarserver systemd[1]: sonar.service holdoff time over, scheduling restart.
May 21 14:34:34 sonarserver systemd[1]: start request repeated too quickly for sonar.service
May 21 14:34:34 sonarserver systemd[1]: Failed to start SonarQube service.

How Do You Write a BubbleSort Algorithm in Python That Runs in O(n) in a Best Case Scenario?

Problem scenario
You want to use BubbleSort in Python that runs in O(n) time when the list to be sorted is already in perfect order.  How do you write such a program?

Solution
Use this code for BubbleSort with a refinement:

def refinedBubbleSort(coollist):
needtoswap = True
x = len(coollist)-1 # x is now the index value of last item in list
while x 0 and needtoswap:
needtoswap = False
for i in range(x): # start with leftmost number and iterate to the xth position one space at a time
if coollist[i] coollist[i+1]: # swap if left item in pair is greater than right item
needtoswap = True
coollist[i],coollist[i+1] = coollist[i+1],coollist[i]
x = x-1 # Go through the list from rightmost item until the leftmost item
coollist = [1,2,3,4,5,6,7,8,9,10]
refinedBubbleSort(coollist)
print(coollist) …

How Do You Install Sysdig in an Existing Debian-Based Docker Container?

Problem scenario
You want to monitor Docker containers.  Therefore you want to install Sysdig to try it out.  How do you install Sysdig in a pre-existing Docker container?

Solution
Run these three commands:
apt-get -y update
apt-get -y install curl
curl -s https://s3.amazonaws.com/download.draios.com/stable/install-sysdig | bash

What Do You Need to Do to Get a RHEL Server to Be a DNS Server?

Problem scenario
You have a RHEL server in AWS.  You want it to be a DNS server.  What do you do?

Solution
For security reasons, you should have the network that this DNS server will serve be behind a firewall.  Following a short Question and Answer guide like this is fine for testing and learning.  However, denial of service attacks are more possible when a primary DNS server engages in recursive look ups (page 857 of A Practical Guide to Fedora and RedHat Enterprise Linux).