What are SOLID Principles?

Follow SOLID Principals

SOLID principles are widely accepted set of rules that let you design/implement reusable and flexible Classes and methods. They consist of the following five principles.

Single Responsibility Principal – Promotes Encapsulation

A class/method should have a single, well-defined functionality. They should only contain code responsible to a single actor (of a use case).

Classes and Methods change because the requirements of the actors change. If a class / a method only contain code that is responsible for a single actor, they only have only one reason to change. This is important because different actors have different requirements, which evolves in different phases and for different reasons.

Open Closed Principal – Promotes Abstraction + Polymorphism

Classes (even Systems) you develop should be open for extension and closed for modification. New functionalities should introduce new codes to a system, not changes to the existing code. The modules you design should never change. When requirement changes you should extend and add more modules to change the behavior of the system.

This principle promotes Abstraction and Polymorphism. Your module should be designed on top of immutable abstractions so it never changes. However, anyone can implement different derivations of these abstractions to introduce new behaviors to the system.

Things that change for different reasons and in different rates, should exist in different places in the code. It is impossible to make a system 100% agnostic for all changes. The designer should find the most probable changes and should make the system to be resilient against them.

Find this very interesting paper on the topic – link.

Liskov Substitution Principal – Abstraction and Hierarchy

Any subtype should be directly substituted in place of a supertype reference. This means that a reference of the supertype should be replaceable with a subtype object without breaking the program. For this principle to work, it is essential that subtype does not change the behavior of supertype. The subtype should provide all the features of the supertype, then some extra

Find the research paper here.

Interface Segregation Principle

A client should not be forced to depend on the method that it does not need. This principle enforces splitting large interfaces to several small interfaces.

Dependency Inversion Principle

Abstract modules should contain high-level business logic. Concrete implementations should contain implementation details. When a high-level module needs to call a low-level module, define an interface on the side of the high-level module to invert the dependency.

 

 

Automate Reboot and Git push with Linux Crontab

1200px-Tux.svg

Introduction

I am going to explain how you can set up daily git pushes with crontab command.

Step 1 – Disable git username/password prompt during check-in

Follow the steps on this StackOverflow post.

Step 2 – Add git commands to a sh file

Add following sh file to the repository root directory.

#!/usr/bin/expect

#Pull remote repository
git pull

#Git commit and push
git add -A

#Commit
git commit -a -m "Daily Update"
git push

Step 3 – Open Crontab

sudo crontab -e

Step 4 – Setup Daily Executions

Add following line to the crontab file. This will run the script every 8am in the morning.

0 8 * * * PATH_TO_YOUR_SH_FILE

For example, the command I used was this.

0 8 * * * /home/myhome/project/gitpush.sh

Step 5 – Setup Daily Reboot

Refer to this askUbuntu post to set this up.

 

Set up Ubuntu Mate on Raspberry PI for Python Developers

Raspi-PGB001

Introduction

This blog explains how to set up a freshly installed Ubuntu mate on a Raspberry PI for Python and Django development. If you want to know how to install Ubuntu Mate on Raspberry PI please refer to this post.

Step 1 – Enable SSH

Not really needed for this task. But handy to have it. Run the following two commands to activate it.

sudo systemctl enable ssh
sudo systemctl start ssh

Step 2 – Update Ubuntu

Run following two commands. These two will take 1-2 hours to finish.

sudo apt-get update
sudo apt-get upgrade

Step 3 – Install Importent Packages

sudo apt-get install git
sudo apt install vim

Step 4 – Install Python/Django

sudo apt install python-pip -y
pip install --upgrade pip 
sudo python -m pip install django

Install Ubuntu Mate in Raspberry PI using Mac and no Keyboard

Raspi-PGB001

Introduction

In this blog, I am going to explain how you can install your Raspberry PI using a mac and without any keyboards. Also, you need minimal technical knowledge to do so. You will need a mouse and a display device. So here it goes.

Step 1 – Download Ubuntu Mate

Get it from the following link. Then extract it to get the .img file.

https://ubuntu-mate.org/raspberry-pi/

Step 2 – Plug Micro SD card to your Mac

Connect your Micro USB card to the mac. If your mac is a new (fancy) one with only Thunderbolt ports you can buy a micro SD card adapter from Amazon for a couple of bucks.

Step 3 – Find the Device Identifier

Mac will auto-mount your micro sd card. Go to the Disk Utility, select your SD card. Note the disk identifier of your card. For my case, it is disk4. Then unmount your disk (do not Eject).

Screen Shot 2019-03-09 at 4.26.54 PM

Step 4 – Write Ubuntu Mate image to the SD card

Here is the command you should execute.

sudo dd bs=1m if=path_of_your_image.img of=identifier_of_your_disk conv=sync

For my case, here is the exact command I had to run.

sudo dd bs=1m if=~/downloads/ubuntu-mate-16.04.2-desktop-armhf-raspberry-pi.img of=/dev/disk4 conv=sync

This command takes some time to complete, so stay put.

Step 5 – Boot your Raspberry

Plugin the micro sd. You need to connect a mouse and display to it as well. Turn on the raspberry and boot it up.

Step 6 – Set up username/password without a Keyboard

When it boots up it will ask you to give a login and a password. But you can’t do it because you don’t have a keyboard. The trick is to copy any text from the window and paste it on the login and password text boxes. For this example, I used “computer” username and “computercomputer” as the password. Set it up, you are good to go.

Step 7 – Enable On Screen Keyboard

Go to Applications–> Universal Access –> Onboard

Hope this helps. Refer this blog to see how you can set up Ubuntu Mate after installation for programming.

Best Machine Learning / Data Science Reads

Here are the most interesting research papers / articles that I came across.

  1. A Few Useful Things to Know about Machine Learning. This papers discusses twelve important topics that every machine learning practitioner should pay his attention to. https://homes.cs.washington.edu/~pedrod/papers/cacm12.pdf
  2. This article describes foundations of algorithmic bias. http://approximatelycorrect.com/2016/11/07/the-foundations-of-algorithmic-bias/
  3. How machine learning algorithms are evaluated in real world uses in web and other online applications. https://ai.stanford.edu/~ronnyk/2007GuideControlledExperiments.pdf

Investing Guide for Solo Investors

invest

Seven Key Rules

Keep following seven rules on your mind, on your desk and on the wall of your bedroom if possible. Read them at least once a week. When you are making an investment use this rules to evalute the quality of the investment.

  1. Always try to minimize loosing money. This involves making investments with minimal downside risks.
  2. Focus on acquiring and holding stocks with consistent dividend growth so the revenues can be compounded.
  3. Stocks are never undervalued. Stock is today worth what investors willing to pay for it, no more no less.
  4. No more than 20 symbols. Hard to keep track more than 20 companies. At least Half of them with high dividend pay companies.
  5. Evaluate each investment twice an year
  6. Have a predefined exit criteria for all the holdings.
  7. Always have a pool of cash ready

Numbers to Consider

  1. Company should have a high dividend yield. At least higher than the inflation.
  2. Consistent, moderate dividend growth – High dividend growth rates are not sustainable. Financial statements can be deceptive. Executives work goes to make them attractive for investors. But the dividend payment always tell the truth. Consistent growth of dividends is the hallmark of a good company. See at least 5 years of history.
  3. Debt / Capitalization should be less than 50%
  4. Coverage of at least 3 : 1. Cash flow of the company after taxes should be at least three times as the interest it pays
  5. Consistent, moderate annual earning growth 5 – 10%
  6. Payout ratio less than 60%
  7. Low Price / Sales ratio – Price of a share divided by the sales per share. Very fist prerequisite of business is revenue. If  revenues are high compare to the stock price, profitability can be easily increased though cons controls and increased productivity. Minimum price to sales ration of 1.5.
    1. Low P/E Ratio – must be at minimum. This value should be less than the reciprocal of the long-term bond rate. If bond rate is  5% –> 100 / 5 = 20 –> PE value should be less than 20. If the price of the company is above this level. Then the stock is expensive. Evaluate the PE value of a stock relative to the PE value of the market. If a stocks PE has been 125% of the market, but now it sells at 80% of the market, there is a good chance that it is under valued at the moment.
  8. Buy shares less than it’s book value. Book value does not represent intangible values of the company such as the brand name.
  9. Growth in cash reservers or investments made by the company
  10. Less volatile sharp rice. Can calculate the standard deviations of the share price to find this.

Measurements of the Quality

  1. Company has Performed well during the troublesome economic environments
  2. How well acquisitions are absorbed and integrated into the company –> smart acquisitions
  3. Do best to avoid new businesses. Look for companies with long-term consistent moderate growth, long-term dividend yields, long-term growth of yield.
  4. Look for a company that produce real goods or services which serves peoples needs, has a reliable user demand. Avoid reseller companies.
  5. What you should really buy is a competitive advantage. Try to identify the competitive advantages a company has over others.
  6. Look for growth kickers. That could be selling for a low performing division or a new sub division with great potential

General Guidelines

  1. Information available to everyone is not valuable anymore. PE ratio is not valuable as it was before
  2. TIme of max optimism is the best time to sell. the time of max pessimism is the best time to buy
  3. Don’t confuse genius with a bull market
  4. A list of stocks that you want to earn but which are not representing correct value at the moment. use this list during next correction/crash to buy

 

Selling Strategy

Sell when the dividend does not make sense to hold it for long team. make the decision based on the dividends. If we know that dividends are not going to keep rising, then it is time to sell. When dividends are affected, so is the share price.

Also when the share price increases it’s fair value, and the dividend yield relatively smaller to the other shares

One year goes with dividend increase. See the reason is one time occurring. If it fails two consecutive years, may be it is a good time to sell.

Document selling decisions and analyze them annually

If a company grows really fast with keep increasing sales, if those sales comes from the consumer credit, that may not be a sustainable business. When the debt cycle turns, customers will not be able to consume services as often.