Squoggle

Mac's tech blog

Category Archives: Uncategorized

Install Homebrew on Mac OS

The version of Mac OS I’m working with here is 12.6.6 Monterey

Open a terminal and paste in the following:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

You will be told what Homebrew is going to do and to confirm or abort. Go ahead and Confirm.

You will see a lot of stuff scroll past but in the end you should have Homebrew installed.

Confirm with this:

% brew help

You should see the help screen for Homebrew.

Now you can install packages. I’m in the need of telnet to test network connections so I install like this:

% brew install telnet

sdf

My Python Notes

Virtual Environments for Python

Python3 is already installed on my Linux distro.

Install Virtual Environments

You will want to use Virtual Environments for Python. Install Virtualenv:

$ pip install virtualenv

Create a Virtual Environment

Create a base directory where you want your Virtual Environments to live:

$ cd ~
$ mkdir -p Python/VirtualEnv

Now create a Virtual Environment within that directory structure. I’m going to use P3VirtEnv to signify it is a Python 3 Virtual Environment.

$ cd ~/Python/VirtualEnv
$ virtualenv P3VirtEnv

You should see some message that essentially mean that the Virtual Environment was successfully created. You should see a new directory named ~/Python/VirtualEnv/P3VirtEnv.

Now you need to enter the Virtual Environment and set it active:

$ cd P3VirtEnv/
$ source bin/activate

Your prompt will now show what environment you are logged into. At this point it looks like this:

(P3VirtEnv) mac@Gob:~/Python/VirtualEnv/P3VirtEnv$

This process essentially copies your Python installation form the standard location to this Virtual Environment.
You can test this by seeing where Python is installed

$ which python
/home/mac/Python/VirtualEnv/P3VirtEnv/bin/python

Exit the Virtual Environment by simply typing the word deactivate.

$ deactivate

Your prompt and path are now returned to normal.

sdfsdfsdf

Packages

Python has packages that can be installed.

To see what packages have been installed do:

$ pip list

You should see a list of all the packages that have been installed. Mine looks something like this at this point:

Package Version
---------- -------
pip        22.2.2
setuptools 65.3.0
wheel      0.37.1

To see a list of all packages that have been installed by pip then do:

$ pip freeze

Why the virtualenv package is not listed is a mystery to me at this point.

Now is a good time to check that out. Install Selenium like this:

$ pip install selenium

A whole bunch of stuff gets installed. Now you can check pip freeze again and see all of what got installed

Another library that we will need for making API calls is called Requests. Install it like this:

$ pip install requests

The do the freeze thing to verify.

Install PyCharm

Instructions for downloading and installing PyCharm are located here:

https://www.jetbrains.com/help/pycharm/installation-guide.html

Review Section 2, Chapter 10 in the Class

Variables

When you define a string as a variable you can use a single quote or double quote to encapsulate the string. Numbers do not need to be put in quotes. I think if you put it in quotes then it becomes a string and not a number.

Variables cannot start with a Number, just letters or Underscore. The variable may contain numbers or underscore but cannot start with a number.

Data Types

Integers

Integers are numbers without decimals. They can be positive, negative or zero.

You can do math on integers such as Addition, subtraction, multiplication and division as well as other operations.

If you have multiple operations in a single line you should use parenthesis.

Float

Floats (Floating Point Numbers) are numbers with decimal places.

Operations on floating numbers will result in floating numbers.

In Python if you were comparing 1 vs 1.0 the comparison would be false because the first is an integer and the second is a float.

Strings

Strings are a sequence of single characters and are represented with quotes. Quotes can be single or double.

You can use one type of quote within the other type but not one type within the same type.

For example these is valid:

"Bring me your 'stash' of contraband"

But this is not valid:

"Bring me your "stash" of contraband"
Slicing

Slicing or a Slice is a subset of a String. The index number is the character counting from either right or left of the string and gives you a specific character of the string. See chapter 16 in the course.

If counting left to right you start at 0. If counting right to left you start with -1.

Syntax for slicking is:

variable_name[start index : finish index]

The slice does not include the finish index.

Example:

my_string[0]

Would give the first character of the string.

my_string[0:]

Would give the entire string

my_string[9:12]

Would give characters 9 through eleven. Remember that counting starts at 0 and not 1

Type command

You can determine what data type a variable is with the type command.

Lets assume you have a variable named var. You can get what type of data is with the type command like this:

type(var)

And the class of data will be returned to you.

String Methods

https://docs.python.org/3/library/stdtypes.html#string-methods

Electrum

Install Electrum on Linux Mint 20.3

Install the pre-requisites for Electrum:

sudo apt install python3-setuptools python3-pyqt5 python3-pip libsecp256k1-0

This will pull in a bunch of dependencies as well. Say Yes.

Go to https://download.electrum.org/ and see what version is the latest version.
As of this writing the latest version is 4.2.1

Install the tar.gz file located in the latest version directory:

pip3 install https://download.electrum.org/4.2.1/Electrum-4.2.1.tar.gz

Add /home/mac/.local/bin to your path. Add this to the end of your ~/.bashrc file:

# Set your path to include $HOME/.local/bin
PATH="$HOME/.local/bin:$PATH

You can now simply run electrum from the command line like this:

$ electrum &

Documentation on Electrum is found here:

https://electrum.readthedocs.io/en/latest/index.html

Unofficial Guide:

https://bitcoinelectrum.com/

Using Electrum

BackUps

The unofficial guide suggests not backing up your wallet to cloud even though you have encrypted the wallet. They suggest backing up your wallet to a removable drive such as a flash drive.

Yes you can restore your wallet from your seed phrase but you cannot restore metadata from seed. By metadata I mean your transaction and address labels/descriptions and the addresses saved in your contact book. So backup your wallet every time you make a change to it.

Wallets are stored in:

~/.electrum/wallets

The idea of backups also includes the seed phrase written on a piece of paper. The guide suggests that it should not be stored only on a computer because hard drives fail. It should not be stored in the cloud as that could theoretically be compromised. The guide suggests it should strictly be stored on paper and suggests a notebook that you would not lose or throw away accidentally.

I’ve struggled with this idea. Take for example the idea of your house burning to the ground. You would lose both the notebook, the computer and any backups if not stored on the cloud. I suppose you could store the backup and paper in a fire proof safe.

I did a search for bitcoin cold storage on Amazon and found metal plates you can engrave with your seed. This might be the solution. None of them really say fireproof but if they were in a fireproof safe they might be safe. They appear to be made of aluminum and I suspect they might not survive a house burning down unless in a fireproof safe. There are versions made of titanium that can withstand 3000 degree temps.

Another option I have thought about would be to store the paper and backup offsite or in a different physical building. That brings in additional questions on how secure the offsite place is.

You can backup the wallet by going to:

File > Save Backup

I decided to put my wallet on my NFS share which with RAIDed drive redundancy.

Cryptocurrencies

Electrum only supports Bitcoin. I probably should have researched this earlier as it is now an exercise in futility since I need it to support multiple ccryptos.