Python Tips when Dealing with Lists

Here are some tips when using Python and dealing with lists.

  1. Use snake_case for list variable names. For more information on coding style in Python, see the PEP 8 style guide here.
  2. Never call a variable “list”. (If you are using a variable for a list, use something like small_list or big_list — not “list”.) Any word that is not a reserved word and not a built-in data type will work.

How Do You Get PowerShell to Run Scripts?

Problem scenario
One of the following apply to you.

Problem scenario #1
You try a PowerShell command but you get an error like this “The ‘Login-AzureRmAccount’ command was found in the module ‘AzureRM.profile’, but the module could not be loaded.”

OR

Problem scenario #2
You try a PowerShell command but you get an error like this:

Files\WindowsPowerShell\Modules\AzureRM.profile\5.8.2\AzureRM.Profile.psm1 cannot be
loaded because running scripts is disabled on this system.

In Python How Do You Print Just The Values of The Two-dimensional List without The Quotes, Commas or Brackets?

Problem scenario
In Python your program has a two-dimensional list. It prints out like this:

[’ ‘, ‘X’, ‘ ‘, ‘ ‘, ‘ ‘]
[’ ‘, ‘X’, ‘X’, ‘ ‘, ‘ ‘]
[’ ‘, ‘X’, ‘X’, ‘X’, ‘ ‘]
[’ ‘, ‘X’, ‘X’, ‘X’, ‘X’]

You want it to print out like this:

X
XX
XXX
XXXX

Solution
Assuming that there are n rows of your matrix (aka two-dimensional array),

How Do You Troubleshoot a Java Compilation Error “class fooBar is public, should be declared public class…”?

Problem scenario
You try to compile a java program, but you get this error:

hello.java:1: error: class HelloWorld is public, should be declared in a file named HelloWorld.java
public class HelloWorld {
^
1 error

What is wrong?

Solution
The .java file must have a name of “HelloWorld” like the public class in the error.

How Do You Troubleshoot SonarQube Not Starting up Properly?

Problem scenario
SonarQube is not starting up properly. What should you do?

Possible Solution #1
For the sonar.properties file do not put “#” symbols on lines that are not completely commented out. They can cause you problems.

Possible Solution #2
You may want to click here to see more about re-installing it or troubleshooting the error.

How Do You Troubleshoot an External Monitor That Does Not Work and You Cannot See Any Reference to It in the Windows Control Panel?

Problem scenario
With an HDMI cable you cannot get an external monitor that is connected to your Windows computer to work. In the Control Panel section for “Screen Resolution” there is a drop down menu for “Display.” This will give some descriptive identification of your monitor when the monitor is working properly. It does not show an attached monitor. What should you do if the “Display” drop down in Screen Resolution (in the Windows Control Panel) does not show your monitor and the external monitor is not working to display any output?

How Do You Send an Email from the Command Prompt of Linux to a Long List of Recipients?

Problem scenarios
One or both of the following apply:

#1 You want to automate the sending of the exact same email to multiple people. You do not want to manually type in the recipients. You have the same subject and body that each recipient should receive. You want to customize the “from address” that the recipients see. How do you do this?

OR

#2 You are using the mail command on a Linux server.

How Do You Programmatically Search Hyperlinks on a Given Webpage?

Problem scenario
You have a web page that you access from the front-end (e.g., a web browser). You want to see if there is a hyperlink on the page that goes to a certain URL. You know the web page and the URL, but you are not sure if a hyperlink on the website has such a link. What should you do?

Solution
Use the curl command.

How Do You Troubleshoot the Puppet Error “file mode specification must be a string, not ‘Integer'”?

Problem scenario
You are running a manifest and you get this error:

Error: Failed to apply catalog: Parameter mode failed on File[/opt/hadoop/hadoop-2.2.0.tar.gz]: The file mode specification must be a string, not ‘Integer’ at /etc/puppetlabs/code/environments/production/modules/hadoop/manifests/init.pp:55

What is wrong?

Solution
Go to the Puppet Master server and open the file in the error. (The error provides the full directory path.) Go to the line number that the error message specifies.