How Do You Create a Class That Is an Iterator in Python?

Problem scenario
You want to implement an object that is an iterator in Python. What do you do to implement iterator behavior in the class?

Solution
Run this program as an example:

class Computation:

    def __init__(self, max = 0):
        self.max = max

    def __iter__(self):
        self.n = 0
        return self

    def __next__(self):
        if self.n <= self.max:
            product = 2 * self.n
            self.n += 1
            return product

objecta = Computation(4) # The number must be 3 or greater if you want to print something other than "None" with this program. 
variter1 = iter(objecta)
next(variter1)
next(variter1)
next(variter1)
pf = next(variter1)
print(pf)

How Do You Install the make Utility on Any Type of Linux?

Problem scenario
You want to install make on Linux. You want it to work on any type of Linux (e.g., Red Hat, Debian and SUSE derivatives). What should you do?

Solution
Prerequisite

Install the C language compiler. If you need assistance, see this posting: How Do You Install a C Compiler on Linux?

Procedures
Run this script:

a=$(which gcc)
echo $a" was found."
echo "This will fail if no c compiler is installed."
sleep 2
version=4.3
curl -L http://ftp.gnu.org/gnu/make/make-$version.tar.gz > /tmp/make-$version.tar.gz
mv /tmp/make-4.3.tar.gz /usr/bin/
cd /usr/bin
tar xf make-$version.tar.gz
cd make-$version
./configure --prefix=/usr/local
rm make
bash build.sh
rm /usr/bin/make
echo "Ignore a message like this:"
echo "rm: cannot remove '/usr/bin/make': No such file or directory"
echo "That message can be safely disregarded."
ln -s /usr/bin/make-$version/make /usr/bin/make

How Do You Hyperlink to Specific Paragraphs (Not the Top) of a WordPress Article?

Problem scenario
You are using WordPress. You have a posting that is long, and you want a link to a paragraph at about halfway down in it. How do you create a hyperlink to a specific paragraph of a WordPress article?

Solution

  1. In your web UI editor for WordPress, click on the three vertically-stacked dots in the upper right-hand corner.
  2. Click on "Code Editor"
  3. Go to the place in the posting where you want the hyperlink to be. Insert this text (but change "contint" to the phrase of your choice):
<div id="contint"></div>
  1. Click update (in the upper right-hand corner).
  2. Create a URL like this (where foobar.com is the URL of the posting): www.foobar.com/#contint
  3. Open a web browser and test this hyperlink as it should bring you to the paragraph of your choice.

Why Does “aws ssm” Return False Messages about a Package Being Installed?

Problem scenario
You run an "aws ssm" command. It returns that a given package has been installed. You know the package is not really installed. What is the reason for the discrepancy?

Solution
A previous "aws ssm" command may have run successfully. But later someone may have deleted specific files without using "aws ssm". This is a limitation of "aws ssm". It can provide false positives or negatives if engineers/administrators bypass aws ssm for their tasks.

How Do You Use Burp (the Burp Suite tools)?

Problem scenario
You want to test out Burp to verify your website is secure. What do you do?

Solution
1. We use the desktop GUI of Linux for this solution. Deploy Kali Linux (e.g., in Azure).

2. Run these commands on it if you are not connected to the GUI Desktop:

sudo apt -y update
sudo apt -y install xrdp
sudo service xrdp start

3. Use the Remote Desktop Protocol (RDP) program to connect to the GUI.

4. Open a terminal and type "burpsuite" and press enter.

How Do You Find Files with a Specific Pattern of Text?

Problem scenario
You want to do a regex with PowerShell. Using PowerShell, how do you retreive all .txt files that have the sequence of characters "foobar" in them?

Solution
Run a command like this:

Select-String -Path c:*.txt -pattern foobar

This solution was adapted from this external website.

How Do You Fix an A Record in Active Directory That Has Two Domain Names?

Problem scenario
You added an A Record to DNS in Active Directory. You accidentally added the FQDN and the parent domain name was added. Now the A Record is too long and has a duplicative domain name like this:

server1.continualintegration.com.continualintegration.com

You tried modifying the FQDN in the A record, but it was immutable. What should you do?

Solution
Try waiting one hour. This problem may correct itself. It is possible that A.D. will notice it and fix it.

How Do You Extract an Email Address from a CSV File?

Problem scenario
You have a CSV file with email addresses. You want to return only the email address -- not lines that have an email address. What do you do?

Solution
Assuming the email addresses are in a file named email.txt, use this Python 3 program:

with open('email.txt', 'r') as a:
  for b in a:
    if '@' in b: #operate only on lines with "@"
      c = b.split() #split up words on line
      for d in c: #iterate through characters of words
        if '@' in d: #if email address,
          print(d+';') #print email address

How Do You Adjust the Landscape Orientation of a PDF to Be a Portrait?

Problem scenario
You have a letter 8.5 X 11 PDF. When it is opened the longest way is the width (the horizontal distance) and the shortest dimension of the PDF is the height (the vertical distance). You want it to be oriented in a more "normal" way so it shows as a portrait not as a landscape. You have a non-commercial need, and you do not want to spend any money. What should you do for a free solution?

Solution
Use PDFMate by going here: https://pdfmate.com/

How Do You Troubleshoot the SUSE Error “No curses library functions found”?

Problem scenario
In SUSE you get an error like this:

configure: error: No curses library functions found
ERROR: /bin/otp/erts/configure failed!
./configure: line 353: kill: (-13244) - No such process

What should you do?

Solution
Run this:

sudo zypper -n install ncurses-utils ncurses-devel