What Is an Affordable EC-2 Instance Type with Two vCPUs?

Problem scenario
You want an EC-2 flavor that has two vCPUs that is fairly affordable too. What should you use?

Solution
Use the t3.micro instance size (for x86_64). This has only 1 GB of memory. If you are using ARM architecture, try the t4g.micro instance size; it also has only 1 GB of memory with two vCPUs.

How Do You Run an AWS CLI Command to Allow Access to an EC-2 Instance in Security Group?

Problem Scenario
You want to modify a security group to allow SSH connections from an IP address. How do you do this with the AWS CLI?

Solution
You have to know the security group's ID. Replace "sg-abcd1234" with the group ID, and replace 1.2.3.0/24 with the IP address and subnet mask you want to allow to connect from in this command and then run it:

aws ec2 authorize-security-group-ingress \
--group-id sg-abcd1234 \
--protocol tcp \
--port 22 \
--cidr 1.2.3.0/24

Is a Private Key on a Linux Client Used in SSH Authentication to a Remote Server?

Question
This website (https://kb.iu.edu/d/aews) says "On the SSH command line: Add the -i flag and the path to your private key."

When running an SSH command, you do not think that the client's private key would not come into play. You think that the public key would be used. The man page for SSH says

-i identity_file
Selects a file from which the identity (private key) for public key authentication is read

ssh will also try to load certificate information from the filename obtained by appending -cert.pub to identity filenames.

You think that identity_files are public keys, and the website that you mentioned above is incorrect. Does this -i flag allow a user to denote a public key?

Answer
No, the -i flag denotes a private key. The man page and the link above are correct. The private key does come into play when using an SSH command.

Page 166 of SSH, The Secure Shell: The Definitive Guide version 1 explains that the identity file is a private key. For various reasons this private key is used when authenticating via SSH to a remote server.

Terraform: Up & Running, 2nd Edition by Yevgeniy Brikman (O'Reilly), Copyright 2019, 978-1-492-04690-5 (page 214) says that the authorized_keys file on a Linux server that is an EC-2 instance will have the public key of an SSH pair. To access this server your client would need to have the private key that corresponds to the public key on the server.

FFR
The convention for a private key's name is often the same, except the public key has a .pub extension. https://superuser.com/questions/232362/how-to-convert-ppk-key-to-openssh-key-under-linux

How Do You Log Out of cj.com (aka Commission Junction)?

Problem scenario
You have logged into the CJ website. You want to log out. What do you do?

Solution
Click your name/company name in the upper right hand corner. You should see "Login Manager", "Privacy Policy", "© Commission Junction LLC". Underneath those three things there is a light gray bar that may almost blend in with the background. It says "Logout" in possibly faint gray (medium gray) letters. It looks like this:

How Do You List the ELBs in Your AWS Account when You Know One Exists But the Command You Run Shows None?

Problem scenario
You run an AWS CLI command to list load balancers. It returns none. You know there are load balancers. What should you do?

Solution
Run these commands:

aws elb describe-load-balancers
aws elbv2 describe-load-balancers

(It could be that you have a newer load balancer or an older style load balancer. If you run both of the above commands, you should find it.)

What is a Bootstrap DNS Server?

Question
What is a bootstrap DNS server? When is a bootstrap DNS server needed?

Answer
In computing the term "bootstrap" can mean to initiate a self-sustaining process (the source is this posting). A bootstrap DNS server is a DNS server that allows other domain name entries (such non-IP addresses) to be found by finding a DNS server. If you have hostnames in an /etc/hosts file or similar configuration, the bootstrap DNS server maps and routes hostnames to IP addresses initially (such as to other regular DNS servers). Similar to how /etc/resolv.conf works to point a host server to a specific DNS server, the bootstrap DNS server resolves various entries of hostnames to IP addresses when such hostnames would otherwise not be resolved, mapped or found.

A bootstrap DNS server is needed for a given pod or server for the initial resolution/finding of hostnames that are themselves DNS servers but need mapping from the pod or server. Thus a bootstrap DNS server allows regular DNS to be configured when regular IP address routing is insufficient (e.g., for the first time a server or pod comes online).

For more information, see these postings:

How Do You Find What GUI/Desktop Environment Your Linux Server Is Using?

Problem scenario
There is a GUI desktop environment that your Linux machine is using. You want to know which one it is. What do you do?

Possible Solution #1
Run these commands:
sudo ps -ef | grep gnome
env | grep -i xdg

Possible Solution #2
echo $XDG_CURRENT_DESKTOP
echo $DESKTOP_SESSION

(Taken from https://unix.stackexchange.com/questions/46305/is-there-a-way-to-retrieve-the-name-of-the-desktop-environment)

Possible Solution #3
This command may give you clues if it is gnome: whereis gnome

Possible Solution #4
In the desktop GUI, go to Systems Tools or YAST (or some Control Panel equivalent) and go to "About". It may say there.

Possible Solution #5
apt list --installed | grep gnome
sudo yum list installed | grep gnome
sudo zypper se | grep gnome

If you suspect something other than Gnome is installed, see this page for other choices: https://en.wikipedia.org/wiki/Desktop_environment

How Do You Print Out Aggregate Cryptocurrency Information Based on a Date Range?

Problem scenario
You want to print out the average cryptocurrency price along with the minimum and maximum prices based on a range of dates. What do you do?

Solution
This solution only goes back to 2015 for BTC. For other cryptocurrencies, the oldest price data is usually more recent than that.

Prerequisite
This assumes you have installed pandas: pip install pandas
If you need assistance installing pip, see this posting.

Procedures
Run this Python program; you may change the exchange to the one of your choice, the currency symbols to the cryptocurrency symbol of your choice, and the "to_symbol" to the currency of your choice.

"""
Written in March of 2021 by www.continualintegration.com

It was adapted from these postings:
https://towardsdatascience.com/cryptocurrency-analysis-with-python-buy-and-hold-c3b0bc164ffa
https://towardsdatascience.com/cryptocurrency-analysis-with-python-macd-452ceb251d7c?gi=12b983021ac2


"""

import pandas as pd
import requests
from datetime import datetime

def get_filename(from_symbol, to_symbol, exchange, datetime_interval, download_date):
    return '%s_%s_%s_%s_%s.csv' % (from_symbol, to_symbol, exchange, datetime_interval, download_date)

def download_data(from_symbol, to_symbol, exchange, datetime_interval):
    supported_intervals = {'minute', 'hour', 'day'}
    print('Downloading %s trading data for %s %s from %s' %
          (datetime_interval, from_symbol, to_symbol, exchange))
    base_url = 'https://min-api.cryptocompare.com/data/histo'
    url = '%s%s' % (base_url, datetime_interval)    
    params = {'fsym': from_symbol, 'tsym': to_symbol,
              'limit': 2000, 'aggregate': 1,
              'e': exchange}
    request = requests.get(url, params=params)
    data = request.json()
    return data

def convert_to_dataframe(data):
    df = pd.json_normalize(data, ['Data'])
    df['datetime'] = pd.to_datetime(df.time, unit='s')
    df = df[['datetime', 'low', 'high', 'open',
             'close', 'volumefrom', 'volumeto']]
    return df

def filter_empty_datapoints(df):
    indices = df[df.sum(axis=1) == 0].index
    print('Filtering %d empty datapoints' % indices.shape[0])
    df = df.drop(indices)
    return df

def file_creator(from_symbol, to_symbol, exchange, datetime_interval):
    data = download_data(from_symbol, to_symbol, exchange, datetime_interval)
    df = convert_to_dataframe(data)
    df = filter_empty_datapoints(df)
    latest_date = datetime.now().date().isoformat() 
    filename = get_filename(from_symbol, to_symbol, exchange, datetime_interval, latest_date)
    #print('Saving data to %s' % filename)
    print('The oldest day in the range obtained for ' + from_symbol + ' was ' + str(df['datetime'].min()))
    df.to_csv(filename, index=False)


def get_filename(from_symbol, to_symbol, exchange, datetime_interval, download_date):
    return '%s_%s_%s_%s_%s.csv' % (from_symbol, to_symbol, exchange, datetime_interval, download_date)

def read_dataset(filename):
    #print('Reading data from %s' % filename)
    df = pd.read_csv(filename)
    df.datetime = pd.to_datetime(df.datetime) # change to datetime
    df = df.set_index('datetime') 
    df = df.sort_index() # sort by datetime
    #print(df.shape)
    return df

print("This prints out aggregated data for certain cryptocurrencies.  It downloads files first.")

from_symbol = 'BTC'
to_symbol = 'USD'
exchange = 'Coinbase'      # "Bitstamp" and "Coinbase" are valid among others.
datetime_interval = 'day'
file_creator(from_symbol, to_symbol, exchange, datetime_interval)

from_symbol = 'ETH'
file_creator(from_symbol, to_symbol, exchange, datetime_interval)

from_symbol = 'LTC'
file_creator(from_symbol, to_symbol, exchange, datetime_interval)

latest_date = datetime.now().date().isoformat() 
df_btc = read_dataset(get_filename('BTC', to_symbol, exchange, datetime_interval, latest_date))
df_eth = read_dataset(get_filename('ETH', to_symbol, exchange, datetime_interval, latest_date))
df_ltc = read_dataset(get_filename('LTC', to_symbol, exchange, datetime_interval, latest_date))

df = pd.DataFrame({'BTC': df_btc.close,
                   'ETH': df_eth.close,
                   'LTC': df_ltc.close}) 

print(" ")

print(df.describe())

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

How Do You Write a Palindrome Testing Program in Python That Ignores Punctuation and Spaces?

Problem scenario
You want to write a palindromic testing program without importing any modules that ignores a string's punctuation or spaces. What do you do?

Solution
Use this program:

def is_palindrome(s: str) -> bool:
    # i moves forward, and j moves backward
    i, j = 0, len(s) -1
    while i < j:
        while not s[i].isalnum() and i < j:
            i += 1
        while not s[j].isalnum() and i < j:
            j -= 1
        if s[i].lower() != s[j].lower():
            return False
        i, j = i + 1, j - 1
    return True

# The above lines of code were taken from page 78 of Elements of Programming Interviews in Python.

print(is_palindrome("aaaabaabaa"))

To buy the cited book, click here.