In Python, How Do You Call a Bound Function as a New Thread with the thread Module?

Problem scenario
You want to write a program to call a bound function in a new thread. How do you do this?

Solution
Run this program (e.g., python foobar.py):

import _thread as thread
class mighty:
def cool():
print(“Cool.”)
def contint():
print(“Hello!”)
if name == “main”:
foobar = thread.start_new_thread(mighty.cool, () )
print(“thread finished…exiting”)

 » Read more..

How Do You Generate a 100 GB Log File?

Problem scenario
You want to generate a large log file to use later on (e.g., for the Elastic Stack or Splunk). How do you create a 100 GB log file?

Solution
Find an example log to base the generation off. Run these commands to find a log that you would want to copy its format:

cd /var/log
ls -lh –sort=size
sudo tail foobar # where foobar is the name of the log file you want to sample

2.

 » Read more..

How Do You Create Bytecode with Golang?

Problem scenario
You want to create bytecode using Golang. What do you do.

Solution
Prerequisite
Install Golang. If you need assistance, see this posting.

Procedures
Create a Go script that you can run with go run nameOfProgram.go
Run this: go build nameOfProgram.go
Run this: ./nameOfProgram

 » Read more..

How Do You Create a List of Strings in Golang?

Problem scenario
Lists have a fixed length number of discrete items. You want the items in the list to be strings. How do you create a list of strings in Golang?

Solution
1. Use this program called animal.go:

package main

import “fmt”

func main() {
var x [10]string
x[0] = “dog”
x[1] = “cat”
x[2] = “hamster”
x[3] = “rabbit”
x[4] = “chicken”

for i := 0;  » Read more..

How Do You Get SonarQube to Use a New Database Connection and Change It from the Previous One It Was Working with?

Problem scenario
You try to start an old SonarQube instance but with a new database connection. In the web.log file you see a message like this: “Can not connect to database. Please check connectivity and settings.” What should you do?

Solution
Go to sonar.properties. Find the connection string for the new database. It should look something like this:

sonar.jdbc.url=jdbc:oracle://FQDN:1521:XE

The default port for Oracle databases is 1521.

 » Read more..

How Do You Delete Browser Data from Chrome when Your First Attempt Failed?

Problem scenario
In Chrome you deleted browsing data including cookies and autofill form data. You closed the browser and reopen it, but old URLs still show up. What should you do?

Solution
Go to History -Clear browsing data -and go to “Time Range” (the drop down menu). Choose “All time” and then go to “Clear data”.

 » Read more..

How Do You Find Out if a GitHub Repository’s Branch is Protected or Not?

Problem scenario
Using the API you want to know if a given GitHub repository’s branch is protected. What do you do?

Solution
Draft the four commands below. Replace “jdoe” with the GitHub username. Replace “organizationname” with the organization name in your repo. Replace “repositoryname” with the repository name. Replace “master” with the branch you want to check. Then run the four commands below.

 » Read more..

How Do You Create Your Own RPM Package (Binary File) for Your Own C Program?

Problem scenario
You want to know more about RPM packaging so you can create your own .rpm file (a custom RPM package file).  In other words you want to create your own RPM package (a binary file).  You want it for installing an uncompiled C program you wrote.  The uncompiled C program is one .c file and very simple.  You don’t know how to use a spec (specification) file to create your own RPM package file. 

 » Read more..

How Do You Get curl to Work when the Web Page is Working?

Problem scenario
You can download a file with Lynx and wget. But curl is not working. What should you do?

Solution
First, try to curl the web page without redirecting the output. If the curl command creates a file, it does not necessarily give you an accurate depiction. You may want to examine the file with a text editor. What you see without redirecting the output to a file (that is allowing the output to echo to the screen) may provide a clue.

 » Read more..

How Do You Save a Linux Machine with You Overwrote the PATH Variables Such That No Command Will Work?

Problem scenario
No commands in Linux are working. You get “command not found” with simple commands such as ls. You cannot use sudo, cat, rm, or reboot. What should you do?

Solution
Use absolute paths. For example, use this command:

/bin/sudo reboot

If there is a new file that is causing the problem, you can use /bin/vi to modify the file or /bin/rm to delete it.

 » Read more..