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)

Jdbc Connection test

import java.sql.*;

class Ass1
{
    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");
        conn.close();
    }
    catch(Exception e)
    {
        System.out.println(e.getMessage());
    }
   
    }


}

JDBC-EAsy codes Ass1 -PL1

//content is wrapped so actual see that below comments must remain comments
import java.sql.*;

class Ass1_final
{
    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("UPDATE  COMP SET QTY=QTY+1 WHERE NAME='DELL' ");//update
        ps2.executeUpdate();
        System.out.println("Qty updated by 1 ...");
       
        PreparedStatement ps3 = conn.prepareStatement("SELECT * FROM COMP");//display......
        ResultSet rs=ps3.executeQuery();
       
        while(rs.next())
        {
                System.out.print("NAME" + "\t"+rs.getString("NAME"));
                System.out.print("QTY" + "\t"+rs.getInt("QTY"));
                System.out.println("NAME" +"\t"+ rs.getDouble("PRICE"));
        }
       
        PreparedStatement ps4 = conn.prepareStatement("UPDATE  COMP SET QTY=QTY+1 WHERE NAME='DELL' ");//update
        ps4.executeUpdate();
       
        PreparedStatement ps5 = conn.prepareStatement("DROP TABLE COMP ");//update
        ps5.executeUpdate();
       
        System.out.println("table dropped or deleted..");
       
       
        rs.close();
        conn.close();
    }
    catch(Exception e)
    {
        System.out.println(e.getMessage());
    }
   
    }


}

Saturday, 5 September 2015

Register -how to add a entry to a database using a jsp form and a servlet


watch the video


newjsp2.jsp

<%--
    Document   : newjsp
    Created on : 2 Sep, 2015, 10:25:39 PM
    Author     : harsh
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Login page</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div>
            <h2>Register</h2>
            <form action="NewServlet1" method="post">
                Email:<input type="email" name="email"><br>
                Name :<input type="text" name="name"><br>
                PASS :<input type="password" name="pass"><br>
                <input type="submit" name="submit" value="submit">
            </form>
        </div>
    </body>
</html>

NewServlet1.java

// a pure processing servlet to authenticate the user
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class NewServlet1 extends HttpServlet
{
   /// private static final String url = "jdbc:mysql://localhost/vusers";

    //    private static final String user = "root";

      //  private static final String pw = "mysql";
           
    public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException
    {
        try
        {
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/users","hall","bed");
            PreparedStatement ps = conn.prepareStatement("INSERT INTO USERNAME VALUES (?,?,?)");
            // get data of form
                        String email=req.getParameter("email");
            String username = req.getParameter("name");
            String password = req.getParameter("pass");
            // set the values for parameters
            ps.setString(1,username);
            ps.setString(2,password);
                        ps.setString(3, email);
            ps.executeUpdate();//database is updated
                //HttpSession session = req.getSession(true);
                                //session.setAttribute("Welcome",username);
                res.sendRedirect("newjsp.jsp");  // Wel is
               
       
               
        }
        catch (Exception e)
        {
                    res.sendRedirect("newjsp1.jsp");
            System.out.println(e.getMessage());
        }
    }
}
       


       

JSP Servlet Databse LoginPage

 Watch this video
newjsp.jsp

<%--
    Document   : newjsp
    Created on : 2 Sep, 2015, 10:25:39 PM
    Author     : harsh
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Login page</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div>
            <form action="log" method="post">
                Name :<input type="text" name="name"><br>
                PASS :<input type="password" name="pass"><br>
                <input type="submit" name="submit" value="submit">
            </form>
        </div>
    </body>
</html>

NewServlet.java

// a pure processing servlet to authenticate the user
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class NewServlet extends HttpServlet
{
   /// private static final String url = "jdbc:mysql://localhost/vusers";

    //    private static final String user = "root";

      //  private static final String pw = "mysql";
           
    public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException
    {
        try
        {
            Class.forName("org.apache.derby.jdbc.ClientDriver");
            Connection conn = DriverManager.getConnection("jdbc:derby://localhost:1527/users","hall","bed");
            PreparedStatement ps = conn.prepareStatement("SELECT * FROM USERNAME WHERE username=? AND password=?");
            // get data of form
                       
            String username = req.getParameter("name");
            String password = req.getParameter("pass");
            // set the values for parameters
            ps.setString(1,username);
            ps.setString(2,password);
            ResultSet rs = ps.executeQuery();
            if (rs.next())
            {
                HttpSession session = req.getSession(true);
                                session.setAttribute("Welcome",username);
                res.sendRedirect("index.html");  // Wel is
               
            }
            else
                            res.sendRedirect("newjsp1.jsp");
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}
       


       

Wednesday, 2 September 2015

Jsp Login Example

copy paste the code below

newjsp.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <title>Login page</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div>
            <form action="log" method="post">
                Name :<input type="text" name="name"><br>
                PASS :<input type="password" name="pass"><br>
                <input type="submit" name="submit" value="submit">
            </form>
        </div>
    </body>
</html>

NewServlet.java


// a pure processing servlet to authenticate the user
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
//import java.sql.*;

public class NewServlet extends HttpServlet
{
           
    public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException
    {
        try
        {
            // get data of form
                       
            String username = req.getParameter("name");
            String password = req.getParameter("pass");
  
          
            if (username.equals("student") && password.equals("student"))
            {
              
                res.sendRedirect("index.html");                 
            }
            else
                            res.sendRedirect("newjsp1.jsp");
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}
        

Sunday, 9 August 2015

Monday, 3 August 2015

Disadvantages of IOT


Automation cool ha... but every automation is possible because of power/electricity/energy.

DATA COMMUNICATION  and Wireless Networks have a huge drawback that is

1,SLEEP when not in use
2. WakeUp to a response

The transaction from sleep to wakeup is where the lots of energy is reqired by the sensors.

Energy Harvesting is a real challenge in case of IOT circuits .Here is a doc  that will enahance your view over this disadvantage. 

Arduino IOT

1.Arduino UNO(ref-arduino.cc)
 Arduino/Genuino Uno is a microcontroller board based on the ATmega328P (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.. You can tinker with your UNO without worring too much about doing something wrong, worst case scenario you can replace the chip for a few dollars and start over again.
"Uno" means one in Italian and was chosen to mark the release of Arduino Software (IDE) 1.0. The Uno board and version 1.0 of Arduino Software (IDE) were the reference versions of Arduino, now evolved to newer releases. The Uno board is the first in a series of USB Arduino boards, and the reference model for the Arduino platform; for an extensive list of current, past or outdated boards see the Arduino index of boards.
You can find here your board warranty informations
CODING :_
void setup(){
// all declaration asre done a
}
 void loop(){//any thing you want to work all over again 
// eg- blink of led
}a single-board computer developed in the UK by the Raspberry Pi Foundation with the intention of stimulating the teaching of basic computer science in schools. The design is based on a Broadcom BCM2835 system on a chip (SoC), which includes an ARM1176JZF-S 700MHz processor, VideoCore IV GPU, and 512 megabytes of RAM. The design does not include a built-in hard disk or solid-state drive, instead relying on an SD card ooting and long-term storage - 

Introduction

HI friends this blog is all about  Internet of things.
AS if we want many of our daily simple tasks to be completed in an automated manner.
  • Home automation 
  • Agriculture 
  • Military Applications

Any thing you think needs a loop to run IOT is the answer to it.

Windows 10 -recover 25gb or more disk space in 5minutes