How Do You Write a Python Program to Parse a Log File and Return Lines with the Word “Failed”?

Problem scenario
You want to retrieve lines from a log file with the word "failed". How do you do this with Python?

Solution

Assuming the log file is named "auth.log", this will work:

log_reader = open('auth.log', 'r')
for line in log_reader:
  lower_line = line.lower()
  if lower_line.find("failed") != -1:
    print(line)

How Do You Force the Reinstallation of curl?

Problem scenario
You are trying to remove curl with dnf or yum commands. You cannot do it because dnf or yum requires curl. What should you do to reinstall curl?

Solution
Prerequisites

You need make installed. If you need assistance with this, see this posting.

Procedures
Manually back up then delete curl. Run "which curl". Move it to a user's home directory.

Go here: https://curl.haxx.se/download/?C=M;O=D

Get a link to the .tar.gz media. Download it.

Use commands like this to expand the files and install curl:

copy the file downloaded into /opt/
tar -zxvf NameOfFileAbove.tar.gz

cd into the directory created
Run commands such as these:

./configure
make
sudo make install

How Do You Get a Table in HTML/Javascript to Display Only The First n (or 10) Rows?

Problem scenario
You have a web page with a table. It uses HTML and Javascript. You want only a sub-portion of the rows to be displayed and allow the user from the front-end to click a drop down menu to see more results. What should you do?

Possible Solution #1
Have two blocks in the .html file. Have the top one define a function that accepts a parameter and filters the table results if/when called. The parameter will accept a variable (e.g., a Boolean). The function will have conditional logic based on this Boolean value.

Have the lower block invoke the function. This function can be invoked with a drop down menu (associated with an event from the front-end of the web page). This function can be invoked in the Javascript code embedded in the .html file or in a separate .js file (referenced in the .html file).

Possible Solution #2
Use DataTables (the JQuery plugin) in Javascript code. HTML can have embeddeed Javascript (between tags) or refer to a separate .js file.

"DataTables is a powerful Javascript library for adding interaction features to HTML tables." Taken from https://www.c-sharpcorner.com/article/create-datatable-in-jquery/

The Javascript code can have stanzas such as these:

…
bpaginate: true,
bLengthChange: true,
…

You can read more about them here. Here is an example of how to do it: https://www.programmersought.com/article/44601760749/

How Do You Install Open Broadcast Studio on Fedora Linux?

Problem scenario
You want to install a feature rich screen capture video software program that can record via a camera too. What do you do?

Solution
Prerequisite
Install snap: sudo dnf install snapd

sudo snap install obs-studio

# If you are using Fedora 32, run this command:
sudo dnf install http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-32.noarch.rpm

# If you are using a different version of Fedora, see this external page: http://download1.rpmfusion.org/free/fedora/

sudo dnf install obs-studio-libs
sudo dnf install qt5-qtsvg 

# Run these commands:
sudo find / -name librtmp.so.1
sudo ln -s <pathFoundAbove> /lib64/

How Do You Troubleshoot the Error Message “libQt5svg.so.5 cannot open”?

Problem scenario
You try to run obs (Open Broadcaster Studio Software) on Fedora, but you get a message like this:

/var/lib/snapd/snap/obs-studio/1195/usr/bin/obs: error while loading shared libraries: libQt5Svg.so.5: cannot open shared object file: No such file or directory

What should you do?

Solution
Run this command:

sudo dnf install qt5-qtsvg

How Do You Troubleshoot a Computer Camera That Is Not Rendering Images?

Problem scenario
The built-in camera of your laptop or desktop is not working. What should you do?

Possible Solutions

  1. Did you slide the cover open on the camera lense?
  2. Is your laptop connected to a KVM or other monitor? Could this KVM or other monitor have a camera of its own with a cover on the camera? Maybe there are two cameras and you do not realize it. If you are in a new desk or using new hardware, there may be an extra camera you do not know about.
  3. Are there many wires connected to your computer? Are they connected to something else and not the camera?
  4. Can you try rebooting?

These links may also help:
https://www.technewstoday.com/laptop-camera-not-working/
https://www.youtube.com/watch?v=KOJHbJxiJZ8

https://www.youtube.com/watch?v=NSXPZYlV1sY

https://www.youtube.com/watch?v=w6geNk3QnBQ

https://www.youtube.com/watch?v=uggw6Bnlsjs

For a Windows computer, you may want to try these:
https://support.wepow.com/hc/en-us/articles/360021426334-My-Lenovo-camera-isn-t-working
https://windowsreport.com/fix-laptop-camera-wont-work/

For a Mac, you may want to try these:
https://support.apple.com/en-us/HT211130
https://setapp.com/how-to/fix-camera-on-mac-not-working

https://nektony.com/how-to/fix-mac-camera-not-working

https://www.igeeksblog.com/macbook-camera-not-working/

For a Linux system with a USB-connected camera, see this.

For a USB-connected camera, see this.

What is a Recommended Practice for Handling Asynchronous Requests with Long-Running Processes with Flask?

Problem scenario
You are designing a Flask application with Python running some long-running processes. You want to handle the requests asynchronously. The individual requests will have a duration of more than one hour. What is the recommended way of handling this?

Solution
Use a task queue like Celery or RQ (Redis Queue).

Sources:
https://stackoverflow.com/questions/42790362/how-to-handle-long-sql-query-in-flask

How Do You Use Custom Resource Definitions in Kubernetes?

Problem scenario
You want to extend Kubernetes' functionality. You want to use CustomResourceDefinitions. You can view API resources by running "kubectl api-resources". You want to add to the list. How do you use a CRD?

Solution

  1. Create a file called contint.yaml with the following content:
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: contintexamples.continualintegration.com
spec:
  group: continualintegration.com
  names:
    kind: ContintExample
    plural: contintexamples
    listKind: ContintExampleList
    singular: contintexample
  scope: Namespaced
  versions:
  - name: v1
    # Each version can be enabled/disabled by Served flag.
    served: true
    # One and only one version must be marked as the storage version.
    storage: true
    schema:
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              owner:
                type: string
                description: The name of the owner of this Contint Example franchise
              address:
                type: string
                description: The physical address of the Contint Example
              currency:
                type: string
                description: The currency which this Contint Example accepts payments in
              replicas:
                type: integer
                description: The number of instances of the Contint Example app to deploy
    additionalPrinterColumns:
      - name: Owner
        jsonPath: .spec.owner
        type: string
      - name: Currency
        jsonPath: .spec.currency
        type: string
      - name: Replicas
        jsonPath: .spec.replicas
        type: integer
      - name: Age
        jsonPath: .metadata.creationTimestamp
        type: date

(# The above file was adapted from https://www.tutorialworks.com/kubernetes-custom-resources/ )

2. Run this: kubectl apply -f contint.yaml

3. You have now created a CustomResourceDefinition. The below steps 3a, 3b, 3c, 3d, and 3e are optional.
3.a. Run kubectl api-resources to view what API resources are currently at your disposal. Run kubectl get crd to view what you already may exist.

3.b. Run kubectl get crd to view what you created among everything else that was already there.

3.c. Run kubectl describe crd contintexamples.continualintegration.com to view the details.

3.d. Run kubectl api-resources to view what API resources are currently at your disposal.

3.e. Test it by running this: kubectl api-resources --api-group=continualintegration.com

In The Context of Replication Clusters or Synchronization Backups (Either Cold, Warm, or Hot), what is a Sink?

Question
When you have high availability of servers, you have seen diagrams with a "sink" server. What does the word "sink" signify?

Answer
A sink, homophonic with "sync", is a secondary server in a cluster or replication configuration. That is, there is a primary server that is actively processing transactions of databases or registering changes to files. This primary server may replicate changes over to a secondary or sink server. The sink server receives the changes secondarily from the primary server.