How Do You Use Nomics to a Retrieve Cryptocurrency Prices?

Problem scenario
You want to use Nomics to retrieve cryptocurrency prices. What do you do?

Prerequisite
Get an API key. It is free here: https://p.nomics.com/pricing#free-plan
(You do not need to provided credit card information to obtain one.)

Procedures
Run this Python program but replace YOUR_KEY_HERE with the key:

import requests
resp = requests.get("https://api.nomics.com/v1/prices?key=YOUR_KEY_HERE&format=json")
for item in resp.json():
if item['currency'] in ["BTC", "ETH", "XRP", "LTC", "XLM", "XMR"]:
print(item)

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

How Does an ssh Command Work in Detail?

Question
You want an overview of how SSH works because it seems confusing. You want to comprehend how it works or know exactly what happens when you run an SSH command like ssh jdoe@acme.com. Where can you find a precise explanation on using ssh as well as some background information on SSH?

Solution
SSH is named after the secure shell way of remotely connecting to another server using encryption. You can use ssh commands to enter a shell or remotely execute ad hoc commands. The "ssh" command, and the tools that leverage SSH such as scp and sftp, come from the OpenSSH suite (https://www.openssh.com/). SSH supports GUI forwarding via X11 (according to this external posting).

When an SSH command is executed on a client, a binary file is found (often in /usr/bin/ssh) because of the $PATH environment variable. Then a TCP/IP request is made involving a hostname or an IP address. Routing happens starting from the client, and a request is ultimately made on the server with the address provided. This connection happens over port 22 by default; it can be configured to use a different IP TCP port number.

When this happens, the known_hosts file (normally in .ssh) on the server will look at the "fingerprint" of the client server. If the fingerprint is recognized, then authentication will proceed to happen as normal. If the fingerprint is not recognized, the client will be prompted to continue or abort the connection process. The fingerprint is a string of colon-separated hexadecimal pairs created when the public key is generated. This process helps the client from logging into a different server accidentally.

To see the details of an SSH operation, you can use the --v, --vv, or --vvv flags when you run the SSH command. Once the connection has been established, the user on the server can be different from the user on the client.

The identity file (aka the private key) is often in the .ssh directory of the user of the client. It often is named id_rsa. If it was configured with a passphrase*, the user on the client side will need to enter a passphrase interactively to authenticate to the server. In some configurations of SSH, only the keys need to authenticate and no password is needed. In other configurations of SSH, only a password needs to be entered correctly and no special file on the client side needs to be configured. The ssh-keygen command can create identity files; this utility comes with the OpenSSH suite. With SSH, everything is encrypted between the client and the server including the passphrase for the authentication process. However SSH can work without a passphrase.

To improve the speed of SSH (e.g., for Ansible or Hadoop), you could potentially do five things with the ssh_config file. We highly recommend you back up this file before modifying it! You could not use IPv6; you could turn off DNS lookups on the server of an SSH connection; you could reuse an existing SSH connection on the client; and you could use passwordless authentication. (The first four optimization techniques came from https://www.tecmint.com/speed-up-ssh-connections-in-linux/.)

You could also use the -o flag to override the ssh_config file and pass various directives to speed up, on an ad hoc basis, SSH commands. Finally you could eliminate SSH logging by changing the sshd_config file on the server. The ssh_config and/or sshd_config files can be found in the .ssh directory.

On the subject of optimizing the performance of SSH, encryption and decryption via SSH utilize CPU (according to an external site and other postings on the internet). (It is rare that the bottleneck is with the CPU and not the network in the context of optimizing SSH according to this external posting.)

The ssh-keygen command can generate a private and public key pair. Normally an id_rsa.pub will be the public key. The RSA stands for Rivest Shamir Adelman, a specific type of asymmetric cryptography that SSH supports; there are other types that SSH supports too.

The session key in SSH is symmetric, but it only lasts for the session itself. To read more, see this medium.com article.

The logging of the SSH process will normally happen in /var/log/auth.log for Ubuntu and Debian distributions of Linux. For CentOS/RHEL/Fedora, the file would be /var/log/secure.

SSH does use a three way handshake (SYN from the client to the server, SYN-ACK from the server to the client, and ACK from the client back to the server). To read more about this, see: https://www.inetdaemon.com/tutorials/internet/tcp/3-way_handshake.shtml

To harden SSH, ensure you are using a software firewall or have protection from a hardware firewall. Use the hosts.deny file to not allow connections from wide ranges of IP addresses. If you want tips on hardening a server in general, see this posting.

Use "man ssh" or "man ssh_config" for more information.

For even more information about the details of SSH see these three postings:

See also this book SSH, The Secure Shell.


For troubleshooting SSH, you may want to see these postings:


*A passphrase can accept spaces whereas a password may not accept them.

How Do You Retrieve Cryptocurrency Data for One Day in the Past Using Python?

Problem scenario
You want to find the historic data for a given cryptocurrency using Python. You want to print out the low, high, open and close prices on a specific day. How do you get data for one specific date?

Solution

Prerequisite
This assumes you have installed pandas: pip install pandas

Procedures
Run this program:

"""
Usage instructions: Change the "2016-12-25" the value (assigned to "date_to_see") to the day you want to view.
Change "BTC" to the symbol of the cryptocurrency you want to examine.
You may or may note want to change "USD" or "Coinbase"

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

from_symbol = 'BTC'
to_symbol = 'USD'
exchange = 'Coinbase'      # "Bitstamp" and "Coinbase" are valid among others.
datetime_interval = 'day'
date_to_see="2016-12-25"

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('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):
    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
    return df


file_creator(from_symbol, to_symbol, exchange, datetime_interval)

latest_date = datetime.now().date().isoformat() 
df_btc = read_dataset(get_filename(from_symbol, to_symbol, exchange, datetime_interval, latest_date))
btc_date = open((get_filename(from_symbol, to_symbol, exchange, datetime_interval, latest_date)), 'r')
get_top = btc_date.read()[0:-1]


print("This prints out data for one cryptocurrency on one day.  It downloads a file first.")
print(" ")
print("Here is data for " + from_symbol + " for " + date_to_see + ":")

print(get_top.split('\n')[0])
for line in get_top.split():
    if line.split(",")[0] == date_to_see:
        print(line)

For aggregate data over a date range, see this posting.


If you sign up for Coinbase for the first time, you often can get up to $200 in free coins; it is ideal for Americans. For Europeans, the platform/company Iconomi.com can allow you to buy crypto or learn more.

Miscellaneous Programming Quiz

(This quiz does not cover object-oriented programming or sorting algorithms. For a Python quiz, see this.)

1. What is a sink in a directed graph?
__________________

2. What is the difference between a vertex and a node?
__________________

3. Space complexity of a program, or its memory usage requirements, are often irrelevant compared to the computational complexity of the solution.

True
False

4. What usually happens when a data set is too large for memory but the data set needs to be ordered?

______________________________

5. How is an anchor case different from a base case in recursion?

a. An anchor case ensures the recursion doesn't go on forever, and the base case handles the iterations (the main benefit of recursion).
b. The case ensures the recursion doesn't go on forever, and the anchor case handles the iterations (the main benefit of recursion).
c. There is no such thing as an "anchor" case in recursion.
d. There is no such thing as a "base" case in recursion.
e. None of the above as they are synonyms.

6. What is the computational complexity of an operation going through a list of m lists with n items?

a. O(m)
b. O(n)
c. O (m log n)
d. O(n*m) (a quadratic)

7. What is the space complexity of an algorithm with an operation that exists simultaneously on the call stack for every list of m lists and every n item of those lists when the lists have a length of n?

a. O(1)
b. O(N)
c. O(m log n)
d. O(n log m)
e. O(n*m)

8. What is the space complexity of an operation going through a list of m lists where each list has n items with no simultaneous calls to the stack? The operation happens one at a time and does not simultaneously keep each individual operation on the stack.

a. O(1)
b. O(N)
c. O(m log n)
d. O(n log m)
e. O(n*m)

9. What is the significance of 10**9 + 7?

a. The highest integer value for a float.
b. The way to calculate pi to 9 decimal places.
c. 1000000007, a very large prime number used regularly in computer programming.
d. The largest known prime number.
e. None of the above

10. Can a Boolean conditional statement be considered ternary operator if there is one expression for True and one expression for False?

Yes.
No.

11. To do CI, you must have automated testing.

True
False

12. What could be the best space complexity of a given "for" loop that iterates through n items calling a function each time?

a. O(1)
b. O(n)
c. O(nlog(n))
d. None of the above.

13. What is a mutex?

a. A binary semaphore
b. A system-wide lock
c. A mutually exclusive lock
d. A concept for thread synchronization in multi-threading programming
e. All of the above.
f. None of the above

14. Which of the following statements is true for programs that solve problems with subproblems?

a. Dynamic programming excels when you do not need to compute every sub-problem and memoization is preferred when every sub-problem must be solved.
b. Memoization excels when you do not need to compute every sub-problem and dynamic programming is preferred when every sub-problem must be solved.
c. Dynamic programming is optimal compared to memoization.
d. Memoization is optimal compared to dynamic programming.
e. None of the above.

15. What is the computational complexity of looking for a node in a heap?

a. O(1)
b. O(log n)
c. O(n log n)
d. O(n)
e. None of the above.

16. What book says that "Representation is the essence of programming."?

a. The Art of Programming
b. The Mythical Man-Month
c. The Cathedral and the Bazaar
d. The DevOps Handbook
e. Refactoring by Beck and Fowler
f. Design Patterns: Elements of Reusable Object-Oriented Software
g. None of the above.

17. What are the differences between "string interpolation", "variable interpolation", "variable substitution", and "variable expansion"?
____________________


To see the answers, see this page.

Miscellaneous Programming Quiz & Answers

(This quiz does not cover object-oriented programming or sorting algorithms. For a Python quiz, see this.)

1. What is a sink in a directed graph?
__________________
Answer: A vertex with no route/edge to another vertex; a terminating vertex. Source: Elements of Programming Interviews in Python

2. What is the difference between a vertex and a node?
__________________

Answer: There is no difference. Source: StackOverflow.

3. Space complexity of a program, or its memory usage requirements, are often irrelevant compared to the computational complexity of the solution.

True
False

Answer: False. Source page 238 of The Mythical Man-Month.

4. What usually happens when a data set is too large for memory but the data set needs to be ordered?
_____________________

Answer: Data is separated into subfiles that are small enough to be read into memory two at a time. These subfiles are read into memory, sorted, and persisted into files again. Source: Page 149 of Programming Interviews Exposed: Secrets to Landing Your Next Job.

5. How is an anchor case different from a base case in recursion?

a. An anchor case ensures the recursion doesn't go on forever, and the base case handles the iterations (the main benefit of recursion).
b. The case ensures the recursion doesn't go on forever, and the anchor case handles the iterations (the main benefit of recursion).
c. There is no such thing as an "anchor" case in recursion.
d. There is no such thing as a "base" case in recursion.
e. None of the above as they are synonyms.

Answer: E. Taken from https://www.datacamp.com/community/tutorials/understanding-recursive-functions-python

The base case allows for termination (according to IBM's website).

We find the term "anchor case" to be used less frequently than the term "base case" in the context of recursion. Sometimes the term is called a "termination condition" or a "terminating condition".

6. What is the computational complexity of an operation going through a list of m lists with n items?

a. O(m)
b. O(n)
c. O (m log n)
d. O(n*m) (a quadratic)

Answer: D. Source: Page 40 of Cracking the Coding Interview.

7. What is the space complexity of an algorithm with an operation that exists simultaneously on the call stack for every list of m lists and every n item of those lists when the lists have a length of n?

a. O(1)
b. O(N)
c. O(m log n)
d. O(n log m)
e. O(n*m)

Answer: E. Source: Pages 40 and 41 of Cracking the Coding Interview. Recursion can involve simultaneous calls.

8. What is the space complexity of an operation going through a list of m lists where each list has n items with no simultaneous calls to the stack? The operation happens one at a time and does not simultaneously keep each individual operation on the stack.

a. O(1)
b. O(N)
c. O(m log n)
d. O(n log m)
e. O(n*m)

Answer: A. Source: Page 41 of Cracking the Coding Interview. Avoiding recursion can involve non-simultaneous call stack usage.

9. What is the significance of 10**9 + 7?

a. The highest integer value for a float.
b. The way to calculate pi to 9 decimal places.
c. 1000000007, a very large prime number used regularly in computer programming.
d. The largest known prime number.
e. None of the above

Answer: C. Source https://www.geeksforgeeks.org/modulo-1097-1000000007/

10. Can a Boolean conditional statement be considered ternary operator if there is one expression for True and one expression for False?

Yes.
No.

Answer: Yes. The conditional statement evaluating to True/False is the first expression. The action for True and the action for False are the second and third statements respectively. The word "ternary" means pertaining to three.

For the source of this answer see this: https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c-c/

11. To do CI, you must have automated testing.

True
False

Answer: False
Sources and their relevant excerpts:
"… automated testing is not strictly part of CI it is typically implied." taken from CloudBees' website.

"Simply put, CI is the process of integrating code into a mainline code base…CD is more complicated. CD is about the processes that have to happen after code is integrated for app changes to be delivered to users. Those processes involving testing, staging and deploying code." Taken from
https://devops.com/continuous-integration-vs-continuous-delivery-theres-important-difference/

12. What could be the best space complexity of a given "for" loop that iterates through n items calling a function each time?

a. O(1)
b. O(n)
c. O(nlog(n))
d. None of the above.

Answer: A. Source page 41 of Cracking the Coding Interview. To paraphrase, the calls do not simultaneously exist on the stack. Avoiding recursion can involve non-simultaneous call stack usage.

13. What is a mutex?

a. A binary semaphore
b. A system-wide lock
c. A mutually exclusive lock
d. A concept for thread synchronization in multi-threading programming
e. All of the above
f. None of the above

Answer: E.
Source: These three links help explain why:

StackOverlfow.com. (for A and B)

Sciencedirect.com. (For C)

Geeksforgeeks.org. (For D)

14. Which of the following statements is true for programs that solve problems with subproblems?

a. Dynamic programming excels when you do not need to compute every sub-problem and memoization is preferred when every sub-problem must be solved.

b. Memoization excels when you do not need to compute every sub-problem and dynamic programming is preferred when every sub-problem must be solved.

c. Dynamic programming is optimal compared to memoization.

d. Memoization is optimal compared to dynamic programming.

e. None of the above.

Answer: B. Source: https://stackoverflow.com/questions/6184869/what-is-the-difference-between-memoization-and-dynamic-programming
Explanation:

You can use memoization for only the subproblems you definitely need.

Dynamic programming can involve building up a table of subproblems. This can involve working backward from a solution where an algorithm is designed to compute different combinations of sub-problems; this is considered a bottom-up approach and it is ideal when every sub-problem must be evaluated any way (for business reasons).

The top-down approach of memoization involves keeping the call stack open and iterating through the subproblems to find a solution; the business requirement of avoiding certain sub-solutions could make the top-down approach of memoization ideal.

15. What is the computational complexity of looking for a node in a heap?

a. O(1)
b. O(log n)
c. O(n log n)
d. O(n)
e. None of the above.

Answer: D. Source page 80 of Programming Interviews Exposed by Mongan, Kindler and Giguere. See also stackoverflow.com.

16. What book says that "Representation is the essence of programming."?

a. The Art of Programming
b. The Mythical Man-Month
c. The Cathedral and the Bazaar
d. The DevOps Handbook
e. Refactoring by Beck and Fowler
f. Design Patterns: Elements of Reusable Object-Oriented Software
g. None of the above.

Answer: B. Page 229 of the 20th Anniversary Edition of The Mythical Man-Month.

17. What are the differences between "string interpolation", "variable interpolation", "variable substitution", and "variable expansion"?
____________________

Answer: There are no differences. A constant expression in computer programming is a placeholder of a variable. The terms to describe this practice are "string interpolation", "variable interpolation", "variable substitution", and "variable expansion"?

Three Companies Grew by 1,000% in Five Years

In the past five years as of 8/30/21,

Cryptocurrency and financial technology appear to have very bright futures. To learn more about cryptocurrency, read these postings. To get a book about cryptocurrency, see this list.

How Do You Troubleshoot WordPress Posting Previews That Don’t Wrap on One Page?

Problem scenario
You have a website powered by WordPress. You see a big gulf of space between your widgets/ads and your posting previews. It only happens on one page of previews (not other pages). The ads are too far to the right when the preview doesn't wrap. Why are your previews not wrapping on one page?

Solution
The problem may be one posting. Change the postings (e.g., dates or categories), so they appear on different pages. You may need to have fewer articles on a given page to narrow it down. Once you determine (isolate and identify) the posting that is causing the problem, modify that posting. The previews it is among will not wrap with the problem posting. Sometimes republishing the problem posting will eliminate the problem. Alternatively you could republish every posting on the preview page that has the problem.

How Do You Print the Current Price of Bitcoin with Python without Installing New Packages?

Problem scenario
You do not want to install new Python modules. How do you use Python to print out the latest price of Bitcoin?

Solution
Run this program:

import requests
resp = requests.get("https://api.coindesk.com/v1/bpi/currentprice/USD.json")
print(resp.json()['bpi'])

Here is a modified version of the program:

import requests
resp = requests.get("https://api.coindesk.com/v1/bpi/currentprice/USD.json")
print(resp.json()['bpi']['USD']['rate'])

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 Troubleshoot ‘Target “release” does not exist in the project “apache-cassandra”‘?

Problem scenario
You try to run an ant command. But you get this error: 'Target "release" does not exist in the project "apache-cassandra"'

What should you do?

Solution
Omit the word "release" when you run the ant command.