Category Archives: General

Mac Terminal Setup

SetUp Mac OS Terminal

sudo systemsetup -getcomputersleep
sudo systemsetup -setcomputersleep 60
sudo pmset -a displaysleep 40 disksleep 60 sleep 600

1. Install brew

If you do not have Xcode installed

sudo chown -R $(whoami) $(brew --prefix)/*
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

If you have Xcode installed

xcode-select -- install
curl -fsSL --output homebrew_installer.sh https://raw.githubusercontent.com/Homebrew/install/master/install.sh
bash homebrew_installer.sh

Brew comes with git

git --version

git version 2.32.0 (Apple Git-132)

2. Install Sublime

brew install --cask sublime-text

3. Install Vim

brew install vim
brew install macvim
brew update

append the following line to ~/.vimrc

set clipboard=unnamed

4. Install iTerm 2

brew  install --cask iterm2

5. Check installation of Zsh

zsh --version
echo $0

6. Better Mac Terminal Window

Based on: https://opensource.com/article/20/8/iterm2-zsh

Install Oh My Zsh

Oh My Zsh uses a .zshrc file to save your customizations instead of a .bash_profile

1.

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
2. Add the following in .zshrc

plugins=( git github zsh-syntax-highlighting zsh-autosuggestions bundler dotenv macos
  python pip pyenv virtualenv aws brew docker golang helm
  sudo tmux
  vi-mode vim-interaction
)
source /usr/local/opt/powerlevel10k/powerlevel10k.zsh-theme
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh

#ZSH_THEME="powerlevel10k/powerlevel10k"
ZSH_THEME="robbyrussell"
#ZSH_THEME="agnoster"
3. Install the recommended font

brew install romkatv/powerlevel10k/powerlevel10k
echo "source $(brew --prefix)/opt/powerlevel10k/powerlevel10k.zsh-theme" >>~/.zshrc

4. In order to re-configfure

p10k configure

5. Recommended plugins

git clone https://github.com/zsh-users/zsh-autosuggestions \ ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git \ ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

6. Verification of on-my-zsh

Check 'oh-my-zsh' folder

brew install tree
tree .oh-my-zsh -L  1


.oh-my-zsh
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE.txt
├── README.md
├── SECURITY.md
├── cache
├── custom
├── lib
├── log
├── oh-my-zsh.sh
├── plugins
├── templates
├── themes
└── tools

Generating an SSH key

ssh-keygen -t rsa

Install Python3

brew install python3
brew install pyenv
python3 -m venv pyvirt
source pyvirt/bin/activate
deactivate

AWS setup

Install the AWS CLI using GUI installer

https://docs.aws.amazon.com/cli/latest/userguide/installing.html

Install the awscli tool via python pip:

pip3 install awscli --upgrade --user

Install the aws-iam-authenticator application

https://docs.aws.amazon.com/eks/latest/userguide/install-aws-iam-authenticator.html

Install kubectl

https://kubernetes.io/docs/tasks/tools/install-kubectl/

Install eksctl (admin only)

https://docs.aws.amazon.com/eks/latest/userguide/eksctl.html

References

https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.html
https://github.com/weaveworks/eksctl
https://eksctl.io/

AWS

aws configure

AWS Access Key ID [None]: XXXX
AWS Secret Access Key [None]: XXXXXXXXX
Default region name [None]: us-west-2
Default output format [None]: json

aws configure list
aws s3 ls

Singleton Pattern

class Logger(object):
_instance = None
def __init__(self):
raise RuntimeError('Error: Call instance() instead')
@classmethod
def instance(cls):
if cls._instance is None:
print('Creating new instance')
cls._instance = cls.__new__(cls)
return cls._instance
def __str__(self):
return "singleton pattern"

try:
l = Logger()
except RuntimeError as err:
print(err)
l = Logger.instance()
print(type(l))
print(l)

Factory Pattern

class CompressionFactory:
compression = {}
def __new__(cls):
cls.compression = {"rar": Rar(), "tar": Tar(), "zip": Zip()}
return cls

@classmethod
def getCompression(cls, method):
return cls.compression[method]

import abc
class File(abc.ABC):
def __init__(self, txt):
self.txt = txt
def __str__(self):
return self.txt


class Compression(abc.ABC):
@abc.abstractmethod
def compress(file):
pass

class Rar:
@staticmethod
def compress(file):
print(f"Rar compresstion {file}")

class Tar:
@staticmethod
def compress(file):
print(f"Tar compresstion {file}")

class Zip:
@staticmethod
def compress(file):
print(f"Zip compresstion {file}")

file = File("Text File")
factory = CompressionFactory()
CompressionFactory.getCompression("rar").compress(file)
CompressionFactory.getCompression("tar").compress(file)
CompressionFactory.getCompression("zip").compress(file)