How Do You Fix a Python Program that Returns “Killed”?

Problem scenario
You are trying to write a Python program. It returns "Killed" on a Linux terminal. How should you fix this?

Possible Solution #1
"Aside from running time, the memory space occupied by a program is a principal cost." (Taken from The Mythical Man-Month, page 238.)

Refactor your code. There is a programming method called "brute force" which is a reference to creating an exhaustive number of possibilities and processing those possibilities. This method will not work for certain problems because the input size is too large. You may want to read https://www.quora.com/I-am-a-brute-force-developer-how-do-I-improve-my-algorithms-skills. A program can still solve the problem, but you will have to be clever.

Is there a way to represent a string or data type symbolically without creating so many permutations? Can you calculate what you need to find without having every a string or bit of non-string data exist in memory? Sometimes arithmetic can be performed without creating the string in your program. You may be able to find a solution without putting the data in memory.

A sample pattern of a repeating string or larger data type can be processed as long as the pattern is representative of the whole. Then the result could be mathematically computed to determine the full size. This can reduce the amount of memory used.

You may be too mentally focused on one solution. There may be an alternative solution achievable with rewriting your code. For large input sizes, certain computational complexity will exhaust memory. Examine the logic, use Google, and try to find a way to solve the problem with Python without creating such large strings or putting so many variables/objects into memory.

Some sorting algorithms can solve your sorting needs in n(log(n)) time or better than this (if they do not involve comparisons).

Publilius said "[p]ractice is the best of all instructors" according to The Mythical Man-Month, page 87. Keep practicing, and eventually you will be able to create elegant solutions without writing to disk or adding memory. To see a list of Python books, click here.

Possible Solution #2
Run "dmesg" from the Linux terminal. This may show you what is wrong. You may need to add memory; to add memory, see this posting. To add swap space, see this posting. It could be that you need to refactor your program to use less memory.

Possible Solution #3
Sometimes writing to disk, if you have the disk space, is one way to solve a Python coding quiz. But these are not very performant solutions. This method uses less memory and can prevent your program from being killed by the Python interpreter.

How Do You Troubleshoot the Ansible Error “This task includes an option with an undefined variable”?

Problem scenario
You have a playbook, and your variables are defined. But you get an error "FAILED => {'msg": 'The task includes an option with an undefined variable. The error was 'dict object' has no attribute 'Name'…"

What do you do to solve this?

Solution
The variable's source could be blank. With "ec2_instance_info" the module will connect to AWS. If an EC-2 server has not been named in the web console, the item.tags.Name variable in Ansible will be blank. This error message may give you the idea that something else is wrong. The playbook may be fine, it just relies on EC-2 servers having a name in the web console (as opposed to a hostname at the OS level). Give the EC-2 instance a name in the AWS web console.

How Do You Install wxWidgets on Linux?

Problem scenario
You want to install wxWidgets on Linux. What should you do?

Solution
Run the following:

sudo zypper -n install bzip2 gcc-c++
sudo yum -y install bzip2
sudo apt -y install bzip2

widgetversion=3.0.4
cd /tmp/
curl -Ls https://github.com/wxWidgets/wxWidgets/releases/download/v$widgetversion/wxWidgets-$widgetversion.tar.bz2 > /tmp/wxWidgets-$widgetversion.tar.bz2
cp /tmp/wxWidgets-$widgetversion.tar.bz2 /bin/
cd /bin/
bzip2 -d wxWidgets-$widgetversion.tar.bz2
tar -xf wxWidgets-$widgetversion.tar
cd wxWidgets-$widgetversion

How Do You Access a Linux Server’s GUI Desktop?

Problem scenario
Normally you use Putty to a Debian distribution of a Linux server. You are having trouble using some of the Linux server's utilities. You try to run the "jsql" command, but you see this:

Apr 29, 2019 1:46:15 PM java.util.prefs.FileSystemPreferences$1 run
INFO: Created user preferences directory.
13:46:17,296 ERROR root:67 - HeadlessException, command line execution in jSQL not supported yet:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
        at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:204)
        at java.awt.Window.<init>(Window.java:536)
        at java.awt.Frame.<init>(Frame.java:420)
        at javax.swing.JFrame.<init>(JFrame.java:233)
        at com.jsql.view.swing.JFrameView.<init>(JFrameView.java:80)
        at com.jsql.MainApplication.main(MainApplication.java:62)

How do you access a Debian distribution of Linux's GUI?

Solution
Assuming you are using Linux Mint, Kali Linux, Ubuntu or a Debian derivative of Linux, run these commands:

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

Now you should be able to RDP into the server (e.g., use Remote Desktop from a Windows computer). If something is blocking port 3389, you may want to consult with this posting.

How Do You Find the AWS Namespaces?

Problem scenario
For a boto3 program, you want to find the AWS namespaces. What do you do to list the namespaces that are part of your AWS accounts?

Solution
Prerequisites

You must have the AWS CLI installed. If you need assistance with this, see this posting.

This also assumes that the Linux user has the policy for servicediscovery:ListNamespaces. If you aren't sure, try the solution first. Otherwise your user must be made to allow "servicediscover:ListNamespaces".

Procedures
Run this command: aws servicediscovery list-namespaces

How Do You Resolve the “env: ‘python’: No such file or directory” Error without Installing Python 2?

Problem scenario
The security team for your enterprise will not permit Python 2 to be installed. (You do not want to install a new minimal Python package either.) How do you fix the problem of env: ‘python’: No such file or directory when you run a make command?

Solution
The command "python" (not python3), will work after you run this script. Run this script as sudo (e.g., sudo bash /tmp/scriptbelow.sh):

if [ -f "/usr/bin/python" ]
then
  echo "Python has been installed."
else
  pysource=$(which python)
  ln -s $pysource /usr/bin/python
fi

How Do You Troubleshoot Craft CMS Not Presenting Its Website After the Installation?

Problem scenario
You installed CraftCMS. But there is no port activity on port 80. You want to go to the front-end now. You cannot get to it via a web browser. What do you do?

Solution
Is there a firewall or public cloud security group (e.g., an Azure Network Security Group) blocking traffic to the public IP address over port 80? GCP's firewall could block HTTP traffic such that nmap commands would not show activity over port 80. An nmap -Pn x.x.x.x command could return neither a port filtered/closed response if GCP's firewall was configured to govern the server to block HTTP traffic.

How Do You Install Rundeck?

Problem scenario
You want to set up Rundeck to see what it is like. How do you do this on a Debian distribution of Linux (e.g., Ubuntu, Kali Linux, or Linux Mint)?

Solution
Prerequisite
Java must be installed. Use this posting if you need help with that. We recommend a 4 CPU server with at least 8 GB of RAM. If you need assistance with adding memory, see this posting.

Procedures

  1. Run these commands:
curl -Ls https://dl.bintray.com/rundeck/rundeck-deb/rundeck_3.0.22.20190512-1.201905130100_all.deb > /tmp/rundeck_3.0.22.20190512-1.201905130100_all.deb
sudo dpkg /tmp/rundeck_3.0.22.20190512-1.201905130100_all.deb
  1. Update /etc/rundeck/rundeck-config.properties so the "grails.serverURL" stanza is like this where x.x.x.x is the external IP address of the web server (or the FQDN of the web server):

grails.serverURL=http://x.x.x.x:4440

  1. Run these commands:
    sudo systemctl start rundeckd
    sudo systemctl enable rundeckd
  1. Open a web browser. Go to x.x.x.x:4440 (where x.x.x.x is the external IP address of the server).
  2. Log into the Rundeck web UI. The default credentials are admin / admin.