How Do You Troubleshoot the Python Problem “UnicodeEncodeError: ‘ascii’ codec can’t encode character”?

Problem scenario
You are trying to print out a variable in Python. But you get an error like this: "UnicodeEncodeError: 'ascii' codec can't encode character '\xa0' in position 70567: ordinal not in range(128)"

What should you do?

Solution
Root cause: A variable needs to be encoded as UTF instead of the default ASCII encoding.

Procedures
Assuming that var1 is a variable holding the results of a requests.get(url), use these lines:

x = var1.text
print((x).encode('utf'))

How Do You Troubleshoot the C Error “No such file or directory…compilation terminated”?

Problem scenario
You try to compile a C program, but it fails with "compilation terminated." The error message says "foobar/foobar.h No such file or directory." What should you do?

Solution
This solution does not address where should header files for c go. But it addresses the problem.
Find where foobar.h is: sudo find / -name foobar.h

Run the gcc command again, but with the flag -I/path/to/ nameofc.c

# where /path/to/ is the directory that houses "foobar" that has the file "foobar.h" in it.
# and "nameofc.c" is the name of the c program you are trying to compile.

How Do You Troubleshoot the Cargo/Rust Error “use of undeclared type or module”?

Problem Scenario
You run a "cargo run" command. You get an error like one or more of the following:

use of undeclared type or module api

use of undeclared type or module serde_json

use of undeclared type or module async-std

What should you do?

Solution
Update the Cargo.toml file. The dependencies section should have an entry like one of the following (but the version number may or may not differ):

[package]
name = "in3-tutorial"
version = "0.0.1"
authors = ["reader@medium.com"]
edition = "2018"

[dependencies]
in3 = "0.1.7"
async-std = "1.5.0"
futures-executor = "0.3.5"
serde_json = "1.0"
ethabi = "13.0.0"
ethereum_abi = "0.2.0"
ethbloom = "0.10.0"

[[bin]]
name = "in3"
path = "/home/jdoe/rust/contint.rs"

If you are not sure what version is valid, go here: https://crates.io/

How Do You Delete an Instavoice Voicemail?

Problem scenario
You have some Instavoice voicemails on your smart phone. You want to delete them. What do you do?

Solution
Go to the voicemails in the app. Tap and hold a voicemail you want to delete. It should be highlighted with a gray color. A trash can icon should appear in the upper right hand corner. Click the trash can icon.

How Do You Troubleshoot “cp: cannot stat …: No such file or directory” when Running build_rust.sh?

Problem scenario
You are running build_rust.sh to use Blockchains' Incubed. But you get an error message like this:

cp: cannot stat 'c/CMakeLists.txt': No such file or directory
cp: cannot stat 'c/macro.cmake': No such file or directory
cp: cannot stat 'c/compiler.cmake': No such file or directory
cp: cannot stat 'c/docs': No such file or directory
cp: cannot stat 'c/src': No such file or directory
cp: cannot stat 'c/include': No such file or directory
cp: cannot stat 'CMakeLists.txt': No such file or directory

What should you do?

Solution
Change into the "scripts" directory of in3. For example, you should be in this directory when you run the bash script: /opt/in3-3.1.2/scripts/


If you want to receive free cryptocurrency by just learning more, try Coinbase. For Europeans, the platform/company Iconomi.com can allow you to buy crypto or learn more.

How Do You Delete a Trail from CloudTrail?

Problem scenario
You want to delete a trail from CloudTrail so you can delete an S3 bucket (to avoid AWS charges). How do you do this?

Solution
Warning: You may be able to delete the non-empty S3 bucket that the Trail was supposed to use without deleting the Trail.

Procedures

  1. Log into the AWS Management Console (i.e., the web UI).
  2. Go here: https://console.aws.amazon.com/cloudtrail/
  3. On the left, click on "Trails".
  4. Click the radio button near the name of the CloudTrail you want to delete.
  5. Click "Delete".
  6. You are done, but the logs from the trail will still exist. You can delete the S3 bucket now.

How Do You Analyze Java Thread Dumps?

Problem scenario
You run Java programs on your Linux server. You want to view content of Java thread dumps. What should you do?

Solution
Prerequisites
Install Java if it has not already been installed. See this posting if you need assistance.

You may or may not want to learn more about what a Java thread is; you can read more here.

Procedures

  1. Find the PID of the Java program. To do this, run this:
sudo ps -ef | grep java

You should see this:

ubuntu   13687 13579  0 20:45 pts/3    00:00:00 java ContIntSleep
ubuntu   13702 13499  0 20:45 pts/2    00:00:00 grep --color=auto java

For the example above, 13687 is the PID you need. If you want a Java program that uses the sleep command (so it lasts for a while) use this program:

class ContIntSleep extends Thread{
 public void run(){
  for(int i=1;i<50;i++){
    try{Thread.sleep(500);}catch(InterruptedException e){System.out.println(e);}
    System.out.println(i);
  }
 }
 public static void main(String args[]){
  ContIntSleep contint1=new ContIntSleep();
  ContIntSleep contint2=new ContIntSleep();

  contint1.start();
  contint2.start();
 }
}

Run this (but replace 13687 with the PID you found above):

jstack 13687

If you want to redirect the output to a file, you could run this:

jstack 13687 > /tmp/goodfile.txt

How Do You Troubleshoot the Cargo Problem “error: no such subcommand: add”?

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

error: no such command `add`
Did you mean `b
`?

What should you do?

Solution
Run this: sudo cargo install cargo-edit

It can take 15 minutes to run. This should eliminate the problem.

How Do You Get Python to Search a Web Page for a Specific Pattern?

Problem scenario
How do you write a Python 3 program to parse the text of a web page and determine if a string is on the web page or not?

Solution
Change the "yoururl" variable assignment and the "searchterm" assignment below to what you desire. Then run the program below:

import re
import requests
yoururl = 'https://www.continualintegration.com/'
searchterm = "learned"
r = requests.get(yoururl)
found = re.search(searchterm, r.text)
if found:
  print("The string/pattern '" + searchterm + "' was found when searching " + yoururl)
# found.group(0))
else:
  print("The string/pattern '" + searchterm + "' was not found when searching " + yoururl)