R – Plumber Error “404 – Resource Not Found” Solution

This is frequently found error while running plumber proxy ( such as nginx)

location /api/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:9977/;
}

Match settings in nginx config . Rewrite url and proxy pass have ending “/” . This is working solution , tested on nginx on ubuntu ( 18.04)

How to Install different kernal in Jupyter Notebook

Install R Kernal :

Info could be found at https://github.com/IRkernel/IRkernel

install.packages('IRkernel')
IRkernel::installspec()

# in R 3.3
IRkernel::installspec(name = 'ir33', displayname = 'R 3.3')
# in R 3.2
IRkernel::installspec(name = 'ir32', displayname = 'R 3.2')



A connection to the notebook server could not be established. The notebook will continue trying to reconnect, but until it does, you will NOT be able to run code. Check your network connection or notebook server configuration

This problem is due to incorrect configuration of torando server. You need to uninstall tornado version 6 and install tornado version 5.1.1

To uninstall run : pip uninstall tornado

Install tonado : pip install tornado==5.1.1

Generate SSH key for your cloud server

Why you need ssh key for cloud server ?

This is one time setup which enable quicker and safe login experience . Username ,password login is no longer safe and reproducible. Switch to ssh login for quicker and secured login system.

How to generate it ?

Step 1: ssh-keygen -t rsa -b 4096

ssh-keygen -t rsa -b 4096

Step 2: Read keys and print it content , so you can copy-paste it in destination ssh keys (public key)

Step 3 : Login using ssh

ssh -i /path/to/ssh username@host_ip

Top 3 Stock Broker in India

I am sharing this with my experience and this is for retail investors. According to my experience , top 3 stock brokers are :

  1. Zerodha
  2. Upstox
  3. Samco Securities

Zerodha is best due to technical superiority,clean UI, lowest brokrages.
Pros:

  1. lowest brokrages – zero brokrage for delivery . Huge savings
  2. Easy interface.. Anyone will love it. Clean,organized and beautiful
  3. Good intraday margin for quality stocks
  4. Nice Calculator
  5. Nice Backoffice Admin

Cons :

  1. On volatile days, system slows , login errors and some client report unexpected trade executions
  2. Slower response to customer query.
  3. No margin on cash-n-carry delivery trades

Upstox :

Upstox is replicating zerodha model. Backoffice is not just good as Zerodha. Two noticable advantages on Upstox compared to zerodha is –

  1. Upstox started providing 2x margin on delivery trades at rate of 20/50000 excess margin utilized.
  2. API trading and historical data cost is cheaper than zerodha. API trade through upstox is 850 vs 2000 of zerodha. Similar historical data api is 550 vs 2000 of zerodha.

Both upstox and zerodha calculate same day squareoff trades as intraday. This is saving for both. Trader have to pay less transaction tax(STT) and Brokers earn some brokrages( as their delivery model is zero brokrage). Here brokrage is huge savings .

Samco is for long term quality traders. Samco brokrage is bit higher but with Samco Plus, you get upto 4x margin on selected stocks. You need to pay interest on extra margin utilized but in most cases, it is favor of you. Samco earn interest and more brokrage. You can buy more stocks in multi-legged strategy. With investment of re 50000, buy reliance worth 200000 and upon a simple per stock profit of 50, you can earn 4000 ( simple calculation ) with investment of just 50000 and it is without huge risk . You can buy stocks at 1300 and mamage free fall upto 1100 with any worries. When price will move upward after 15-30 days, still income is good. Samco for long term trading.

Get started with python and postgres

import psycopg2
from psycopg2.extras import RealDictCursor
from datetime import date
connection = psycopg2.connect(user = "root",
                              password = "password",
                              host = "localhost",
                              port = "5432",
                              database = "database")
cursor = connection.cursor(cursor_factory=RealDictCursor)
cursor.execute("""select * from table where date(created_at)=%s order by id desc limit 100""",(date.today(),))
res=cursor.fetchall()

Explanation :

First you need to import required module.For postgres database access,psycopg2 is latest and recommended modue. RealDictCursor is required to get data in proper dictinary form otherwise data will arrive without column name( hard to guess for wide tables).

Create a connection object with defined connection string. Prepare query. Execute it with a cursor and fetch result from cursor . Fetching and selections will be discussed in later series.

You can start with it. Use the data to apply different types of visualization or draw useful conclusions using python,postgres,pandas and python visualization library

How to Increase the amount of inotify watchers

increase the amount of inotify watchers
To find count of inotify watcher - cat /proc/sys/fs/inotify/max_user_watches
Set a new limit of inotify watchers - echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
Apply systemwide changes - sudo sysctl -p
Recheck and confirm changes - cat /proc/sys/fs/inotify/max_user_watches

How to use docker for common applications

Docker help us to reuse softwares without worrying about its environments and sideaffects. You can not easily run 2 versions of software( 2 different version of redis or mongo or mysql or apache etc ) on same host without making any special arrangment. Docker make it portable and reusable. So, do not install , dock it

Some Common cli flags for dockers

  1. -d = demonised mode
  2. -it = interactive mode
  3. -v = attach volume
  4. -p = port mapping from host to docker
  5. –name = naming an instance for quick reference

Now some popular dockers for us.

  1. Couch db server = docker run -d –name couchdb -p 8091-8094:8091-8094 -p 11210:11210 couchbase
  2. Mongo db = docker run –name some-mongo -d mongo
  3. Postgres = docker run –name some-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
  4. redis db = docker run –name some-redis -d redis
  5. maria-db = docker run –name some-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb

I will keep adding more information about docker, container management in coming post.. Switch to better