Monday, 8 January 2018

Ruby basics

class MyInfo
   
   
   def initialize(id,name,addr) 
      
      @id=id
      @name=name
      @addr=addr
   end
    
    def printInfo
    
    puts "id "+ @id.to_s
    puts "name ="+@name
    puts "addr ="+@addr
    
    end
    
end



obj=MyInfo.new(1,"srini","hyd")
puts "this is simple prog"
obj.printInfo

puts "outside of class"

def f1
    puts "this is f1"
end 



END {
    
    puts "this is end of the prog"
    
    f1
}

BEGIN {
    puts "this is the start of the prog"
}




============
$ruby main.rb
this is the start of the prog
this is simple prog
id 1
name =srini
addr =hyd
outside of class
this is end of the prog
this is f1


==========

Wednesday, 13 December 2017

Git basic commands

git config --list
git config --global user.name "sree"
-------

git pull origin master
git check -b  ""
git diff
git status
--------------
git checkout master
git branch -d ""git


=================================

->git statsh
->git checkout master
->git status
->git pull origin master
->git checkout -b testbranch
(do changes in branch)
-> git commit -m "msg"

-> git push origin testbranch

-> git branch -d the_local_branch

==========================================
$₹£€

root
0penVXM1

adminstrator
holly12

====================================

Wednesday, 1 November 2017

Git hub pull request - displays only made changes


Add w=1 at end of url

https://github.com/VirtualHoldTechnology/VXML-IVR/compare/SecondChance...secondchance_simplecallback?w=1

Thursday, 5 October 2017

Creating batch file

Creating a batch file:

  1. Create a new file using Notepad
  2. Rename it as   filename.bat (select All files)
  3. copy the following Script and save
  4. Run it by double clicking it.
  5. That's it enjoy : )

-------------------------------------------------------------------------------------------------------
@echo off
echo Hey sree now i'm removing the log files
pause
sc stop Tomcat7
pause
rmdir "C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\logs" /S /Q
pause
mkdir "C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\logs"
pause
del "C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\webapps\VIS.war"
pause
rmdir "C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\webapps\VIS" /S /Q
pause
rmdir "C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\work\Catalina\localhost\VIS" /S /Q
pause
sc start TomCat7
pause
echo sree it's working fine....  !!!!   : )


------------------------------------------------------------------------------------------------------

Tuesday, 3 October 2017

Wordpress

  • First Download Original File of Newspaper 7.1.1 WordPress Theme by Click Here.

Two Methods of Activation Newspaper Theme

First Method:

  • First of all go this path Newspaper/includes/wp_booster/td_cake.php.
  • Open td_cake.php file in any PHP editor.
  • Find
    function td_cake_manual($s_id, $e_id, $t_id)
and change below code
if (md5($s_id . $e_id) == $t_id) {
    return true;
} else {
    return false;
}
with
if ($e_id == "crackorsquad.in" && $t_id == "crackorsquad") {
    return true;
} else {
    return false;
}
  • Then open “your_site/wp-admin/admin.php?page=td_cake_panel” in your browser and then click on Manual activation and Enter below code
Envato Purchase Code: crackorsquad.in

Activation Key: crackorsquad
After entering This code, Your theme successfully Activate.

Second Method:

  • Apply above method but change above code with
if (md5($s_id . $e_id) == $t_id) {
    return true;
} else {
    return true;
}
After this when you enter any Envato Purchase Code and Activation Key then correctly Activate without any error.

============================
Easy steps to activate newspaper theme 8 or above Find td_ajax.php file on includes/wp_booster In the function td_validate_data Replace this: private static function td_validate_data($id, $ec, $ad) { if (md5($id . $ec) == $ad) { return true; } else { return false; } with this: private static function td_validate_data($id, $ec, $ad) { if (md5($id . $ec) == $ad) { return true; } else { return true; }

================================


Thursday, 28 September 2017

Reading a web page in Java

Reading a web page in Java

 Reading a web page in Java is a tutorial that presents several ways to to read a web page in Java. It contains six examples of downloading an HTTP source from a tiny web page.

Java reading web page tools

Java has built-in tools and third-party libraries for reading/downloading web pages. In the examples, we use URL, JSoup, HtmlCleaner, Apache HttpClient, Jetty HttpClient, and HtmlUnit.
In the following examples, we download HTML source from the something.com tiny web page.

Reading a web page with URL

URL represents a Uniform Resource Locator, a pointer to a resource on the World Wide Web.
ReadWebPageEx.java
package com.zetcode;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class ReadWebPageEx {

    public static void main(String[] args) throws MalformedURLException, IOException {

        BufferedReader br = null;

        try {

            URL url = new URL("http://www.something.com");
            br = new BufferedReader(new InputStreamReader(url.openStream()));

            String line;

            StringBuilder sb = new StringBuilder();

            while ((line = br.readLine()) != null) {

                sb.append(line);
                sb.append(System.lineSeparator());
            }

            System.out.println(sb);
        } finally {

            if (br != null) {
                br.close();
            }
        }
    }
}
The code example reads the contents of a web page.
br = new BufferedReader(new InputStreamReader(url.openStream()));
The openStream() method opens a connection to the specified url and returns an InputStream for reading from that connection. The InputStreamReader is a bridge from byte streams to character streams. It reads bytes and decodes them into characters using a specified charset. In addition, BufferedReader is used for better performance.
StringBuilder sb = new StringBuilder();

while ((line = br.readLine()) != null) {

    sb.append(line);
    sb.append(System.lineSeparator());
}
The HTML data is read line by line with the readLine() method. The source is appended to the StringBuilder.
System.out.println(sb);
In the end, the contents of the StringBuilder are printed to the terminal.

Reading a web page with JSoup

JSoup is a popular Java HTML parser.
<dependency>
    <groupId>org.jsoup</groupId>
    <artifactId>jsoup</artifactId>
    <version>1.9.2</version>
</dependency>
We have used this Maven dependency.
ReadWebPageEx2.java
package com.zetcode;

import java.io.IOException;
import org.jsoup.Jsoup;

public class ReadWebPageEx2 {

    public static void main(String[] args) throws IOException {

        String webPage = "http://www.something.com";
        
        String html = Jsoup.connect(webPage).get().html();
        
        System.out.println(html);
    }
}
The code example uses JSoup to download and print a tiny web page.
String html = Jsoup.connect(webPage).get().html();
The connect() method connects to the specified web page. The get() method issues a GET request. Finally, the html() method retrieves the HTML source.

Reading a web page with HtmlCleaner

HtmlCleaner is an open source HTML parser written in Java.
<dependency>
    <groupId>net.sourceforge.htmlcleaner</groupId>
    <artifactId>htmlcleaner</artifactId>
    <version>2.16</version>
</dependency>
For this example, we use the htmlcleaner Maven dependency.
ReadWebPageEx3.java
package com.zetcode;

import java.io.IOException;
import java.net.URL;
import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.SimpleHtmlSerializer;
import org.htmlcleaner.TagNode;

public class ReadWebPageEx3 {

    public static void main(String[] args) throws IOException {

        URL url = new URL("http://www.something.com");

        CleanerProperties props = new CleanerProperties();
        props.setOmitXmlDeclaration(true);
        
        HtmlCleaner cleaner = new HtmlCleaner(props);
        TagNode node = cleaner.clean(url);

        SimpleHtmlSerializer htmlSerializer = new SimpleHtmlSerializer(props);
        htmlSerializer.writeToStream(node, System.out);        
    }
}
The example uses HtmlCleaner to download a web page.
CleanerProperties props = new CleanerProperties();
props.setOmitXmlDeclaration(true);
In the properties, we set to omit the XML declaration.
SimpleHtmlSerializer htmlSerializer = new SimpleHtmlSerializer(props);
htmlSerializer.writeToStream(node, System.out);    
SimpleHtmlSerializer creates the resulting HTML without any indenting and/or compacting.

Reading a web page with Apache HttpClient

Apache HttpClient is a HTTP/1.1 compliant HTTP agent implementation. It can scrape a web page using the request and response process. An HTTP client implements the client side of the HTTP and HTTPS protocols.
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.2</version>
</dependency>
We use this Maven dependency for the Apache HTTP client.
ReadWebPageEx4.java
package com.zetcode;

import java.io.IOException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

public class ReadWebPageEx4 {

    public static void main(String[] args) throws IOException {

        HttpGet request = null;

        try {

            String url = "http://www.something.com";
            HttpClient client = HttpClientBuilder.create().build();
            request = new HttpGet(url);

            request.addHeader("User-Agent", "Apache HTTPClient");
            HttpResponse response = client.execute(request);

            HttpEntity entity = response.getEntity();
            String content = EntityUtils.toString(entity);
            System.out.println(content);

        } finally {

            if (request != null) {

                request.releaseConnection();
            }
        }
    }
}
In the code example, we send a GET HTTP request to the specified web page and receive an HTTP response. From the response, we read the HTML source.
HttpClient client = HttpClientBuilder.create().build();
An HttpClient is built.
request = new HttpGet(url);
HttpGet is a class for the HTTP GET method.
request.addHeader("User-Agent", "Apache HTTPClient");
HttpResponse response = client.execute(request);
A GET method is executed and an HttpResponse is received.
HttpEntity entity = response.getEntity();
String content = EntityUtils.toString(entity);
System.out.println(content);
From the response, we get the content of the web page.

Reading a web page with Jetty HttpClient

Jetty project has an HTTP client as well.
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-client</artifactId>
    <version>9.4.0.M1</version>
</dependency>
This is a Maven dependency for the Jetty HTTP client.
ReadWebPageEx5.java
package com.zetcode;

import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;

public class ReadWebPageEx5 {

    public static void main(String[] args) throws Exception {

        HttpClient client = null;

        try {

            client = new HttpClient();
            client.start();
            
            String url = "http://www.something.com";

            ContentResponse res = client.GET(url);

            System.out.println(res.getContentAsString());

        } finally {

            if (client != null) {

                client.stop();
            }
        }
    }
}
In the example, we get the HTML source of a web page with the Jetty HTTP client.
client = new HttpClient();
client.start();
An HttpClient is created and started.
ContentResponse res = client.GET(url);
A GET request is issued to the specified URL.
System.out.println(res.getContentAsString());
The content is retrieved from the response with the getContentAsString() method.

Reading a web page with HtmlUnit

HtmlUnit is a Java unit testing framework for testing Web based applications.
<dependency>
    <groupId>net.sourceforge.htmlunit</groupId>
    <artifactId>htmlunit</artifactId>
    <version>2.23</version>
</dependency>
We use this Maven dependency.
ReadWebPageEx6.java
package com.zetcode;

import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebResponse;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import java.io.IOException;

public class ReadWebPageEx6 {

    public static void main(String[] args) throws IOException {
        
        try (WebClient webClient = new WebClient()) {
            
            String url = "http://www.something.com";
            
            HtmlPage page = webClient.getPage(url);
            WebResponse response = page.getWebResponse();
            String content = response.getContentAsString();
            
            System.out.println(content);
        }
    }
}
The example downloads a web page and prints it using the HtmlUnit library.
In this article, we have scraped a web page in Java using various tools, including URL, JSoup, HtmlCleaner, Apache HttpClient, Jetty HttpClient, and HtmlUnit.





Java URL


URL Encoding basic


import java.net.URLEncoder;

public class URLTesting {
public static void main(String args[]) throws Exception{
String para1Before="Java Programming";
String para1After=URLEncoder.encode(para1Before,"UTF-8");

System.out.println(para1Before);
System.out.println(para1After);


String para2Before = "Java, Programming Tutorial";

String para2After=URLEncoder.encode(para2Before, "UTF-8");

System.out.println(para2Before);
System.out.println(para2After);

}
}



Java Programming
Java+Programming
Java, Programming Tutorial
Java%2C+Programming+Tutorial


// space is replace by +
// , is replaced by %2c

--------------------------------------------------------------------------------------------------------------

URL Decoding


import java.net.URLDecoder;

public class URLDecodingTest {

public static void main(String args[]) throws Exception{
 
String para1="Java+Programming";
String para2="Java%2C+Programming+Tutorial";
 
String para1After=URLDecoder.decode(para1,"UTF-8");
         String para2After=URLDecoder.decode(para2,"UTF-8");
         
         System.out.println(para1After);
         System.out.println(para2After);
 
}

}


Java Programming
Java, Programming Tutorial


--------------------------------------------------------------------------------------------------------------

Reading directly from URL


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

public class ReadingFromURL {

public static void main(String args[]) throws Exception{

URL url =new URL("http://www.oracle.com/");
BufferedReader br =new BufferedReader(
new InputStreamReader(url.openStream()));

String inputLine;

while((inputLine=br.readLine())!=null);
System.out.println(inputLine);

br.close();
}

}


--------------------------------------------------------------------------------------------------------------

Convert URI to URL

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public class ConvertURItoURL {

public static void main(String args[]) throws URISyntaxException, MalformedURLException{

URI uri =new URI("http", "java.com", "/hello world/", "");

URL url=uri.toURL();
System.out.println(url.toString());
}
}




java.net.URI class to automatically take care of the encoding 


--------------------------------------------------------------------------------------------------------------

Parsing URL

import java.net.MalformedURLException;
import java.net.URL;

public class ParseURL {

public static void main(String args[]) throws MalformedURLException{

URL url =new URL("http://java.com:80/docs/books/tutorial"
                           + "/index.html?name=networking#DOWNLOADING");




     System.out.println(url.getProtocol());

     System.out.println(url.getAuthority());

     System.out.println(url.getHost());

     System.out.println(url.getPort());

     System.out.println(url.getPath());

     System.out.println(url.getQuery());

     System.out.println(url.getFile());

     System.out.println(url.getRef());
    
}

}




http
java.com:80
java.com
80
/docs/books/tutorial/index.html
name=networking
/docs/books/tutorial/index.html?name=networking

DOWNLOADING


--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------


--------------------------------------------------------------------------------------------------------------

--------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------

https://docs.oracle.com/javase/tutorial/networking/urls/index.html