How Do You List the Repositories in GitHub for a Specific Organization without Using the Web UI?

Problem scenario
How do you use the GitHub API to list repositories for an organization?

Solution
Draft a command like this:

curl -u jdoe https://api.github.com/orgs/foobar/repos | grep git_commits_url

  • Change "jdoe" to the username of your GitHub account
  • Change "foobar" to the name of your organization

Why Does a PHP Program Call to a Python Program Work from the Back-End but Not from the Front-End?

Problem scenario
In your PHP program, the Python binary is executing regardless of how the PHP program is run (e.g., from a command line with the php command or when downloaded from a web browser). The PHP program will launch Python programs if the PHP program is invoked from the back-end with PHP. But Python programs are not being interpreted by Python when a web browser loads the PHP file.

What could be wrong with calling it from the front-end?

Possible solution
Prerequisites
This assumes that PHP and Apache2 have been installed on your server. If you need assistance, run this if you have Ubuntu/Debian Linux: sudo apt -y install php apache2

Procedures
If you are using Debian/Ubuntu Linux, make sure that the .py program is owned by www-data and associated with the www-data group. This is a security concern. Only do this if you know what you are doing. If regular website users can invoke a Python program, there could be serious consequences to this.

In some instances different users or groups may be in play (besides www-data). To find the relevant user or group, use this PHP program and view it from a web browser:

<?php

   $output = shell_exec('/usr/bin/python3 --version');
   echo $output;

   $output1 = shell_exec('/usr/bin/env');
   echo $output1;
?>

<html>
<body>

HELLO!

</body>
</html>

The output will give you the Linux back-end environment variables. Look for the APACHE_RUN_USER and APACHE_RUN_GROUP variable settings. This should help you determine what user and group to associate your .py file.

We are not sure about the solution for CentOS/RHEL/Fedora. If you need to start all over, see How Do You Get a PHP Program to Invoke a Python Program via Browsing a Website?

How Do You Troubleshoot a Web UI Problem with GitLab?

Problem scenario
When you are using GitLab, you receive various 500 errors. The web UI is not working correctly. What should you do?

Possible solution #1
1. Go to the back-end of the GitLab server. Run this: sudo gitlab-ctl tail
2. Reproduce the web UI problems that you are having. Examine the output.

Possible solution #2
You may want to install Fiddler on your desktop to get more details about the front-end. Once installed you can open it and try to reproduce the 500 error. Watch what Fiddler displays when you reproduce the problem.

Possible solution #3
Reboot the GitLab server from the back-end.

Possible solution #4
See if there is a firewall on your GitLab server causing a problem. See this posting if you need help determining if there is a firewall on the Linux server.

Possible solution #5
Start over. Use this posting if you need assistance: How Do You Upload Code to a GitLab Project from a Server That Does Not Have a Desktop UI?

These posting may of be some use to you:

How Do You Troubleshoot the Python Problem “NameError: global name ‘var2’ is not defined”?

Problem scenario
You have a Python program that works, but you get an error when you run it. You get a message like this: "NameError: global name 'var2' is not defined"

Here is your source code:

def fun1(var1):
   print("this is how it works")
   var1 = var2
   return var2 
b = fun1("check it out")
 print(b)

What should you do about this error?

Solution
A variable inside a function must be defined. You can either define var2 locally or globally. But you have to define it.

Here is an example of using a global variable inside a function:

var2 = "" 
def fun1(var1):
   print("this is how it works")
   global var2
   var1 = var2
   return var2
 b = fun1("check it out")
 print(b) 

Here is an example of using a local variable inside a function:

def fun1(var1):
   print("this is how it works")
   var2 = "33333"
   var1 = var2
   return var2
 b = fun1("check it out")
 print(b)

How Do You Create a Master Branch (or First Branch) with the GitHub API?

Problem scenario
You do not want to copy a branch to create a new one. How do you create a branch of a repository that has no branches?

Solution
You must know the relevant organization name of the Git repository and the name of the repository itself. Do these changes:

  • Change "acme" to the organization name
  • Change "goodrepo" to the repository name of your choice.
  • Change "jdoe" to the user for GitHub
  • Change "securepassword" to the password for the above user
user=jdoe
password=securepassword
ORGNAME='acme'
REPONAME='goodrepo'
git clone https://github.com/$ORGNAME/$REPONAME.git
cd $REPONAME
echo "This file was added automatically." > file3.txt
git add file3.txt
git commit -m "Added a file to the repository."
git push https://$user:$password@github.com/$ORGNAME/$REPONAME.git

How Do You Troubleshoot a pom.xml File?

Problem scenario
You are trying to run your Java program from a .jar file. You get an error like this:

Error: Could not find or load main class target.contint-0.1.0.jar
Caused by: java.lang.ClassNotFoundException: target.contint-0.1.0.jar

What should you do?

Solution
Examine the mainClass stanza. The word to the left of the period should be the name of the package. You should have a .java program that will have a line such as package foobar. If the name is "foobar", then your pom.xml file's mainClass stanza should have a stanza such as this:

<mainClass>foobar.somethingelse</mainClass>

How Do You Use Multi-Line String Variables in JavaScript?

Problem scenario
You want to present multiple lines in an "alert" message in JavaScript. How do you have new lines with text in JavaScript?

Possible Solution #1 (less preferred)
Use syntax like this:

var y  = `
  line1
  line2
  line3
`;

Possible Solution #2 (preferred)

var z = [
  line1,  
  line2, 
  line3  
].join("\n");

You could use this stand-alone file multiline.html:

<!DOCTYPE html>
<html>
<body>

<h2>This demonstrates a multi-line variable in JavaScript</h2>


<p id="demo"></p>

<script>

line1 = "aaa"
line2 = "bbb"
line3 = "ccc"

var z = [
  line1,  
  line2, 
  line3  
].join("\n");


alert(z)

</script> 

</body>
</html>

How Do You Get Past “ImportError: No module named ‘boto'”?

Problem scenario
You want to retrieve VPC peering connection info and other VPC info via Boto3. With Python 3 you tried to run this Python 2 (and Boto 2.x) program:

import boto.vpc
c = boto.vpc.connect_to_region('us-east-1')
vpcs = c.get_all_vpcs()
vpc_peering_connection = c.create_vpc_peering_connection(vpcs[0].id, vpcs[1].id)

(It was written by the person who developed Boto 2.x here.)

You have a variety or problems with the syntax not working. Here are some example error messages:

ImportError: No module named 'boto'

NameError: name 'boto' is not defined

NameError: name 'vpc' is not defined

What do you do to adapt "import boto.vpc" and using Boto3 to interact with VPC components (with Python 3) or otherwise get the above program to work?

Solution
Try this program (but replace "pcx-abcd1234" with a VpcPeeringConnection ID):

import boto3
ec2_contint = boto3.client('ec2')
pcs = ec2_contint.describe_vpc_peering_connections(VpcPeeringConnectionsIds=['pcx-abcd1234'])
#to list all peering connections uncomment out this line:
#pcs = ec2_contint.describe_vpc_peering_connections()
print(pcs)

How Do You Create a Function in JavaScript?

Problem scenario
You want to create a function in JavaScript. This way you can use code over-and-over. How do you use a function in JavaScript?

Solution
Call this file contint.html

<!DOCTYPE html>
<html>
<body>

<h2>This demonstrates accepting input and using a function in JavaScript</h2>


<p id="demo"></p>

<script>

x = 5
var foo = prompt("Please enter a number");

function contintFunction(p1, p2) {
  return p1 * p2;   // The function returns the product of p1 and p2
}

last = contintFunction(x, foo)
alert(last)

</script> 

</body>
</html>