How Do You Troubleshoot the Python Error “built-in method strip of str object at 0x7fc87bf4a0f0”?

Problem scenario
You are running a Python program with the "strip" string manipulation method. You get this problem:

<built-in method strip of str object at 0x7fc87bf4a0f0>

What should you do?

Solution
Did you remember to use the parentheses "()" with your strip call?

print(x.strip) can return "<built-in method strip of str object at 0x7fc87bf4a0f0>"

print(x.strip()) will return the intended value.

How Do You Use the AWS CLI to Return IAM Information with the AssumePolicyDocument Nested JSON?

Problem scenario
You want to craft an AWS CLI command to return the principal services of your IAM roles. You want the name and the ARN values of the roles to be printed along with the principal services. You know the principal services data is in the AssumePolicyDocument. Your previous attempts have returned "None" for this value. What do you do?

Solution
Run a command like this:

aws iam list-roles --output text --query 'Roles[*].[RoleName,Arn,AssumeRolePolicyDocument.Statement[*].Principal]'

Can an Apple Magic Keyboard Work with a Windows Computer?

Question
Can an Apple Magic Keyboard work with a Windows computer?

Answer
Yes. An Apple Magic Keyboard will work with a Windows 10 desktop/laptop. It is plug and play too. We tried it with the USB cable initially. After that the wireless functionality was normal. (We tried this in December of 2020.) You can buy a Magic Keyboard here.

Why Do Some Job Descriptions Emphasize Object-oriented Programming?

Question
Why do some job descriptions emphasize object-oriented programming as opposed to procedural programming, scripting or other alternatives?

Background
Some people think that OOP is overused in certain contexts (page 379 of Python 3 Object-Oriented Programming and page 1303 of Programming Python by Mark Lutz). For example OOP may not be ideal for something like regexing (or matching string patterns per page 247 of Python 3 Object-Oriented Programming). However other sources say "… there is no controversy that OOP makes programming easier, faster, more dynamic, and secured." (This quote was taken from nerd.vision.)

Answer
Inexperienced professionals who are new to object-oriented programming tend to use non-object-oriented techniques in programming that they are familiar with. Object-oriented programming is desirable for the following reasons: One, it allows code to be modular and reusable. Two, it allows code to be flexible and extensible. Three, object-oriented code is tied to compilation thus the execution in the CPU is faster. Scripts that are run through an interpreter are not as performant as binary code (compiled code such as .class files). Reusing portions of well-tested code is an efficient practice. OOP involves reusing code.

Moreover, object-oriented programming supports data encapsulation. This benefit of OOP ensures that the code can perform complex and numerous operations on data without the risk of sharing the data. While encapsulation may not be difficult to implement, it generally does not come up in single-pass programming, interactive programming or coding scripts.

There is a legitimate need for some employers' to prefer candidates with object-oriented programming knowledge. For a basic example of object-oriented programming, see this posting. To learn more about object-oriented programming, you may want to read the Gang of Four book also known as Design Patterns: Elements of Reusable Object-Oriented Software. If you want to read when to use a class in Python, see this posting. To test yourself on OOP, take this free quiz.

How Do You Troubleshoot the Hadoop Error “Connecting to ResourceManager”?

Problem scenario
You run a Hadoop command, but you get this error:

2020-12-20 18:19:33,706 INFO client.DefaultNoHARMFailoverProxyProvider: Connecting to ResourceManager at /0.0.0.0:8032
2020-12-20 18:19:36,068 INFO ipc.Client: Retrying connect to server: 0.0.0.0/0.0.0.0:8032. Already tried 0 time(s); retry policy is RetryUpToMaximumCountWithFixedSleep(maxRetries=10, sleepTime=1000 MILLISECONDS)

You tried restarted the start-dfs script with this command: bash /usr/local/hadoop/sbin/start-dfs.sh

It did not help. You ran "jps" to see if Resource Manager was running. What should you do?

Solution
Restart the Yarn script. Run a command like this:

bash /usr/local/hadoop/sbin/start-yarn.sh

How Do You Get Permanent Variables Set in the MacOS Terminal?

Problem scenario
You are using a Mac and you want an environment variable to be configured. What should you do?

Solution

  1. From a terminal, run this: echo $SHELL
  2. If you see /bin/zsh modify the ~/.zshrc to have the export statement that you need. You can learn more here.
    If you do not see "/bin/zsh", update the ~/.bash_profile file to have the export statement that you want. You are now done.

We tested this with macOS Catalina Version 10.15.7 on 12/29/20. To browse Mac products, see this link.

How Do You Troubleshoot Maven Giving You an Error Such as “java.lang.OutOfMemoryError java heap space”?

Problem scenario
You are getting an error such as "java.lang.OutOfMemoryError java heap space"

You have plenty of swap space available, but this error persists. The problem is as if nothing is using swap space you know exists. Why won't your Java program or Maven build utilize the swap space that is available to it?

Possible solution #1 (for Maven builds)
Run a command like one of these (but uncomment the second one if you want to commit roughly 5 GB of memory to the maven build):

export MAVEN_OPTS=-Xmx512m
# export MAVEN_OPTS=-Xmx5120m

Now retry your mvn command.

Possible solution #2 (for Java programs)
Make sure you are using an option like -Xmx512m with you Java program.

Possible solution #3
Run these four commands for clues:

jps -lv
free -mh
df -h
top

Possible solution #4
Try rebooting the server.

Possible solution #5
Read this external article: https://www.cyberciti.biz/faq/linux-which-process-is-using-swap/

Possible solution #6
Changing the heap size can cause the "out of memory" error. You may need to change the heap size to something different.

How Do You Handle a Discrepancy between NMAP Results?

Problem scenario
From two different servers the nmap results show different ports are open. What is the likely cause of this problem?

Possible Solution #1
Is there a firewall between the two servers? Some firewalls block incoming or outgoing connections exclusively. An OS level firewall or other intermediate firewall could easily produce discrepant nmap results based on the servers running the nmap command.

Possible Solution #2
Human error could be the problem. There are numerous ways for this to happen. Is the font size too small? The IP address you are testing is not what you think it is. Look at it carefully because human error can be a factor. Private IP addresses in private networks may be duplicated and pertain to entirely different servers. You may be on different servers with the same private IP address through two different terminals. The IP address may belong to a different server from the one you think you are testing. Use ip addr show | grep x.x.x.x where x.x.x.x is the IP address that you are testing. Try also copying and pasting it between the terminals.

Possible Solution #3
You could be using sudo with one command, and not using sudo with another. If this might be your situation, please see this posting.

How Do You Install SUSE when You Encounter “The System cannot be installed because … There is no device mounted at ‘/'”?

Problem scenario
You are trying to install Linux SUSE. You get an error "The System cannot be installed because the following errors were found: There is no device mounted at '/'. How do you get passed this problem?

Solution
Use the "Expert Partitioner". Verify you have one device (e.g., /dev/sda1) that has the Type "BIOS Boot Partition." Verify you have one device (e.g., /dev/sda2) that has the Mount Point "/". You theoretically might be able to have one device have both traits.

If there is a device that is mounted to "/mnt", highlight it, go to Modify -> Edit Partition then go to the "Mount Point" and change it to "/". You may be prompted "Really skip formatting the partition?" Choose "Yes". Now try to resume the installation.

You may be prompted to abort the install or continue anyway to a variety of errors/questions. You may be able to just keep clicking "continue" through this series of prompts.