Wednesday 19 April 2017

Get Started with Docker in Ubuntu






1. $sudo apt install docker.io

An image is a lightweight, stand-alone, executable package that includes everything needed to run a piece of software, including the code, a runtime, libraries, environment variables, and config fil

A container is a runtime instance of an image – what the image becomes in memory when actually executed. It runs completely isolated from the host environment by default, only accessing host files and ports if configured to do so.

2. $sudo docker run hello-world
to run your first app in docker

3. $sudo docker images
To see the installed images

4. $docker --help
To see the list of commands in docker

5. $sudo docker run -it fedora bash
   $sudo docker run -it ubuntu bash
To lauch terminal with fedora's instance.

6. $sudo docker inspect fedora
To get the details of the fedora image

7. $sudo docker version
To get the version

8. $sudo docker ps
To see the container id and other details

9. $sudo docker stop
To gracefully stop the container

10. $ sudo docker history fedora
Shows history of images



Refrences :
1. https://docs.docker.com/engine/reference/commandline/container_start/#parent-command
2. https://docs.docker.com/engine/userguide/

Saturday 4 March 2017

Machine Learning! Where To Start? - Tools

Popular Tools in 5 points

Octave

  1. This is an Open Source project.
  2. Easy to write complex Machine Learning equations.
  3. Vectorization helps with easy manipulations for matrices operations.
  4. Python like CLI
  5. Limited to small data sets (cannot handle BIGDATA). 

 R

  1. This is an Open Source project.
  2. R can create graphics to be displayed on the screen or saved to file. It can also prepare models that can be queried and updated.
  3. R is a tool to use when you need to analyze data, plot data or build a statistical model for data.
  4. Build with an idea of statistic centric design for computation.
  5. This Blog covers almost every thing: http://machinelearningmastery.com/what-is-r/ 

Python 

  1. NumPy and Pandas are two most recommended libraries to get you started with data manipulation and some statistical calculations.
  2. IPython notebook is also gaining popularity now a days. 
  3. Sci-kit learn and Tensor-Flow are machine learning libraries that are available which makes model building simpler for everyone.
  4. Python is more popular choice amongst the programmers.

Apache Mahout 

  1. Open source Scalable Machine learning platform.
  2. Runs multiple map-reduce jobs to run a machine learning algorithm.
  3. Its build over top of Hadoop.
  4. Its batch processing.

Apache Spark

  1. Open source Big Data platform. 
  2. MLlib is the machine learning library available here.
  3. It is in-memory processing, that's why faster than Mahout.
  4. It supports micro-batch processing.

Summary

Hopefully, it will help you to make right choice. I would recommend if you would like to understand the mathematics of machine learning then use octave or python to implement machine learning algorithms without any library. If your objective is to only apply these algorithms then you may start with python and scikit learn, moreover there are plenty tutorials over the Internet that can get you started. Other Popular libraries are Apache Apex-SAMOA, H2O, Flink, Weka, Java-ML etc. Please comment if you would like to have some other comparisons.

Sunday 26 February 2017

Auto Import Python libraries at startup


*Requirements Below description is applicable for Linux OS

Create a file auto_import.py 

import numpy as np
import pandas as pd
#.... and so on...
#with all your import statements 

In Terminal 

1. Open $HOME/.bashrc file

$ gedit $HOME/.bashrc

2. Copy paste the following line at the end of file:   

#be sure of the path you provide

export PYTHONSTARTUP=/path/to/auto_import.py 

3. Save and close the file 

4. Relaunch the Terminal or use command below to execute changes in bashrc file

$ exec bash

4.In terminal

$ python 

>>> #Congratulations!!! all your libraries are auto imported.

 


Saturday 9 April 2016

Axis Bank

  1. Name Of Applicant  
  2. Date of Enquiry       
  3. Faxed to No. :           91-022-25274403
  4. Sent to :                    The AVP(IT), AXIS Bank Data Centre,15-Corporate Park, Sion-Trombay Road, Chembur, Mumbai-400 071
  5. Type of Business:    
Merchant Customer           
Software Trial                        
Partner Govt. 
Corporate Business
Government Subsidiary Other
  1. Date of Contract       

Wednesday 14 October 2015

Socket prog in Python

SERVER.py

import sys
import socket
if len(sys.argv) != 2:
    print "Server"
    sys.exit()
port = int(sys.argv[1])
sd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)#returns an object
#AF.INET constants represent the address (and protocol) families used for the first argument to socket().
#SOCK_STREAM  These constants represent the socket types
#sd is the object of socket here
address = ("0.0.0.0", port)# address is just a variable
#Bind the socket to address. The socket must not already be bound
sd.bind(address)
print 'Successfully started the server.'

sd.listen(2)
print "Listening for connections now."
sock, addr = sd.accept()

file_name_len = int(sock.recv(2))
file_name = sock.recv(file_name_len)
print "Receiving " + file_name + " from " + addr[0]
outfile = open(file_name, 'w')
# Read 4096 bytes at a time and write them to
# the file. If an empty string is read, it means
# the end of the file has been reached.
while True:
    data = sock.recv(4096)
    if data != '':
        outfile.write(data)
    else:
        break
outfile.close()
print "Done."



CLIENT.py

import sys
import socket
if len(sys.argv) != 4:
    print "Client"
    sys.exit(0)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
address = (sys.argv[1], int(sys.argv[2]))
file_name = sys.argv[3]
sock.connect(address)
file_p = open(file_name, 'r')
file_data = file_p.read()
file_name_len = str(len(file_name))
sock.sendall(file_name_len.zfill(2))
sock.sendall(file_name)
sock.sendall(file_data)
print file_name + " successfully sent!"
sock.close()

Ass3 PL-1 university of pune

import java.sql.*;

class Ass3{
   
    public static void main(String args[]){
    try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/data1","user1","user1");
        System.out.println("Connection Success");
        PreparedStatement ps = conn.prepareStatement("CREATE TABLE COMP (NAME VARCHAR(20),QTY INT(5),PRICE DOUBLE(10,4))");//CREATE TABLE table_name (column_name column_type);
        ps.executeUpdate();
        System.out.println("Tbale created and data is inserting ...");
        PreparedStatement ps1 = conn.prepareStatement("INSERT INTO COMP VALUES(?,?,?)");//ps1
        //Set the values that will replace quesetion marks
        String name="DELL";
        int qty =1;
        double price= 45000.45;
        // now replace ?'s of PS1
        ps1.setString(1,name);
        ps1.setInt(2,qty);
        ps1.setDouble(3,price);
        ps1.executeUpdate();
        System.out.println("values are inserted ....");
        PreparedStatement ps2 = conn.prepareStatement("CREATE INDEX COMP1 ON COMP('NAME')");//ps1
        ps2.executeUpdate();
        System.out.println("INDEX ....");
       
        PreparedStatement ps3 = conn.prepareStatement("SHOW INDEX FROM COMP");//ps1
        ResultSet rs= ps3.executeQuery();
        while(rs.next())
        {
           
            System.out.println(rs.getString("Column_name"));
        }
       
        PreparedStatement ps4 = conn.prepareStatement("CREATE VIEW view AS SELECT PRICE,NAME FROM COMP");//ps1
        ps4.executeUpdate();
       
        PreparedStatement ps5 = conn.prepareStatement("SELECT * FROM view");//ps1
        ResultSet rs2= ps5.executeQuery();
        while(rs2.next())
        {
            System.out.print(rs2.getDouble("PRICE"));
            System.out.println(rs2.getString("NAME"));
        }
     }
    catch(Exception e){
        System.out.println(e.getMessage());
    }
    } 
}

Tuesday 22 September 2015

Inode in python

import os,sys
print 'Enter file name'
name=raw_input()
fd=os.open(name,os.O_RDONLY)
info=os.fstat(fd)
print "The file Information is as follows:"
print "File inode number:",info.st_ino
print "Device number:",info.st_dev
print "Number of link:",info.st_nlink
print "UID of the file:%d" %info.st_uid
print "GID of the file:%d" %info.st_gid
print "Size:",info.st_size
print "Access time:",info.st_atime
print "Modify time:",info.st_mtime
print "Change time:",info.st_ctime
print "Protection:",info.st_mode
print "Number of blocks allocated:",info.st_blocks
print "Size of blocks:",info.st_blksize

os.close(fd)