Saturday 27 February 2016

How to communicate with browser using Java Socket Program ?


import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketTest {
public static void main(String args[])throws Exception{
  ServerSocket serverSocket = null;
       try {
             serverSocket = new ServerSocket(8083);
           } catch (IOException e)
           {
             System.err.println("Could not listen on port: 8083.");
             System.exit(1);
       }

       Socket clientSocket = null;
       try {
            clientSocket = serverSocket.accept();

            if(clientSocket != null)              
                System.out.println("Connected");

       } catch (IOException e) {
             System.err.println("Accept failed.");
             System.exit(1);
      }

     PrintWriter out = new PrintWriter(clientSocket.getOutputStream());


    out.println("HTTP/1.1 200 OK");
    out.println("Content-Type: text/html");
    out.println("\r\n");
    out.println("<html> <head/> <body> <p> Hello world </p> </body> </html>");
    out.flush();

    out.close();

    clientSocket.close();
    serverSocket.close();
}

}



Compile the code and run it in console using java command..
Enter url in browser is....http://localhost:8083 

It will show output like..

Thursday 18 February 2016

How to make the browser full-screen in HTML 5 and JavaScript ?

 <html>   
   <head>
        <script type="text/javascript">
        function toggleFullScreen() {
      if (!document.fullscreenElement &&    // alternative standard method
      !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFull      screenElement ) {  // current working methods
    if (document.documentElement.requestFullscreen) {
      document.documentElement.requestFullscreen();
    } else if (document.documentElement.msRequestFullscreen) {
      document.documentElement.msRequestFullscreen();
    } else if (document.documentElement.mozRequestFullScreen) {
      document.documentElement.mozRequestFullScreen();
    } else if (document.documentElement.webkitRequestFullscreen) {
      document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
    }
  } else {
    if (document.exitFullscreen) {
      document.exitFullscreen();
    } else if (document.msExitFullscreen) {
      document.msExitFullscreen();
    } else if (document.mozCancelFullScreen) {
      document.mozCancelFullScreen();
    } else if (document.webkitExitFullscreen) {
      document.webkitExitFullscreen();
    }
  }
}
                          </script> 
                       </head>
              <body>
                 Press this button, 
                    <button onclick="toggleFullScreen();">fullscreen my blog</button>
                        
              </body>
      
  </html>

 

It will work as....

   
   
              
                       
              
                 Press this button, 
                    
                        
                  
      
      

Monday 15 February 2016

How to capture Camera output in html5 by getUserMedia() api ?

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="stuff, to, help, search, engines, not" name="keywords">
<meta content="What this page is about." name="description">
<meta content="Display Webcam Stream" name="title">
<title>Display Webcam Stream</title>
  
<style>
#container {
    margin: 0px auto;
    width: 500px;
    height: 375px;
    border: 10px #333 solid;
}
#videoElement {
    width: 500px;
    height: 375px;
    background-color: #666;
}
</style>
</head>
  
<body>
<div id="container">
    <video autoplay="true" id="videoElement">
     
    </video>
</div>
<script>
 var video = document.querySelector("#videoElement");
 
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia || navigator.oGetUserMedia;
 
if (navigator.getUserMedia) {       
    navigator.getUserMedia({video: true}, handleVideo, videoError);
}
 
function handleVideo(stream) {
    video.src = window.URL.createObjectURL(stream);
}
 
function videoError(e) {
    // do something
}
</script>
</body>
</html>       
It will work as..






Display Webcam Stream
  


  


Friday 5 February 2016

How to make pdf of html document Using Jquery?

       
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.1.135/jspdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
<script >
$(document).ready(function(){
 //alert();
 $("button").click(function(){
 html2canvas(document.body, {
    onrendered: function(canvas) {
     //in case of @document.body you can select any element to make Img
     var canImg=canvas.toDataURL("image/jpg");
  //   alert(canImg);
     var doc = new jsPDF();

   doc.setFontSize(40);
   doc.text(36, 24, "http://plateofcode.blogspot.in/");
   doc.addImage(canvas, 'JPEG', 15, 40, 180, 180);
   doc.save("a.pdf");

    }
  });
 });
});
 </script>
</head>
<body>
Fork me on GitHub
cdnjsRequest a libChatNetworkUptimeIssuesgit_statsgitstatsAboutBrowse Libraries
html2canvas
http://html2canvas.hertzen.com/

Links/Tags: cdnjs api   git autoupdate enabled repository MIT license
Screenshots with JavaScript

canvas, screenshot, html5 
<button >download</button>
</body>
</html>



 
It will Show as..



Insert title here











Thursday 4 February 2016

How to make Base64 Encryption and Decryption Using javascript atob() & btoa() method in client side ?

     
  <!DOCTYPE html>
<html>
<body>

<p>Click the button to decode a base-64 encoded string.</p>

<button onclick="myFunction()">Test</button>

<p> The atob() method is not supported in IE9 and earlier.</p>

<p id="str"></p>

<script>
function myFunction() {
    var str = "http://plateofcode.blogspot.in/";
    var enc = window.btoa(str);
    var dec = window.atob(enc);

    var res = "Encoded String: " + enc + "<br>" + "Decoded String: " + dec;
    document.getElementById("str").innerHTML = res;
}
</script>

</body>
</html>


 
It will show as....




Click the button to decode a base-64 encoded string.





Note: The atob() is not supported in IE9 and earlier.





Tuesday 2 February 2016

How to make browser notification in JavaScript ?

       
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function notifyMe() {

  // Let's check if the browser supports notifications
  if (!("Notification" in window)) {
    alert("This browser does not support desktop notification");
  }

  // Let's check whether notification permissions have already been granted
  else if (Notification.permission === "granted") {
    // If it's okay let's create a notification
    var notification = new Notification("Hi user");
  }

  // Otherwise, we need to ask the user for permission
  else if (Notification.permission !== 'denied') {
    Notification.requestPermission(function (permission) {
      // If the user accepts, let's create a notification
      if (permission === "granted") {
        var notification = new Notification("");
      }
    });
  }

  // At last, if the user has denied notifications, and you 
  // want to be respectful there is no need to bother them any more.
}Notification.requestPermission();
function spawnNotification(theBody,theIcon,theTitle) {
  var options = {
      body: theBody,
      icon: theIcon
  }
  var n = new Notification(theTitle,options);
}
</script>
<button onclick="notifyDefultStyle()">Notify me!</button>
<button onclick="spawnNotification('notifyexample','https://lh6.googleusercontent.com/-jceMtMC7nk4/AAAAAAAAAAI/AAAAAAAAABQ/WOlkICkIH7c/s80-c/photo.jpg','title..')">NotifyByOption</button>
</body>
</html>


It will show as..












Monday 1 February 2016

how to logout a PC by using C program ?

In this Program console is hidden.
It logout your PC in shorten time interval..like a bug!!!!
You can stop this process in task manager process tab.

Compile the code in dev c or any GCC compiler and....have fun =_* 

#include<conio.h>
#include<windows.h>
main(){
// code for hiding the console_window

HWND stealth; /*creating stealth (window is not visible)*/
AllocConsole();
stealth=FindWindowA("Console WindowClass",NULL);

ShowWindow(stealth,0);
// code for hiding the console_window
while(1){
Sleep(30000);
system("rundll32.exe user32.dll, LockWorkStation");
}

}