Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

Generate random String using org apache commons lang3 RandomStringUtils

| 0 comments |

This example show how to generate random String using org.apache.commons.lang3.RandomStringUtils.

You have to download Apache Commons Lang, and add the jar to Android Studio Projects libs. Refer to the video.


package com.blogspot.android_er.androidrandomstring;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import org.apache.commons.lang3.RandomStringUtils;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button btnGenerate = (Button)findViewById(R.id.gen);
final TextView textResult = (TextView)findViewById(R.id.result);

btnGenerate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
textResult.setText("");
for(int i=1; i<20; i++){
String randomString = RandomStringUtils.randomAlphabetic(i) + " ";
textResult.append(randomString);
}
}
});

}
}


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout


android_layout_width="match_parent"
android_layout_height="match_parent"
android_paddingBottom="16dp"
android_orientation="vertical"
tools_context="com.blogspot.android_er.androidrandomstring.MainActivity">

<TextView
android_layout_width="wrap_content"
android_layout_height="wrap_content"
android_layout_gravity="center_horizontal"
android_autoLink="web"
android_text="http://android-er.blogspot.com/"
android_textStyle="bold" />

<Button
android_id="@+id/gen"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_text="Generate Random Strings"/>

<TextView
android_id="@+id/result"
android_layout_width="match_parent"
android_layout_height="wrap_content"
android_typeface="monospace"
android_textSize="22sp"/>
</LinearLayout>



Read More..

Local WebServer – Apache Tomcat

| 0 comments |

Pre-requisites: You should have Apache Tomcat installed on your machine, downloadable from http://tomcat.apache.org/download-60.cgi and you should have eclipse 3.6 on your machine
Configure the webserver to be used within eclipse as follows:

1.       Unzip the download into your local directory
2.       Tell Eclipse about Tomcat

First, start Eclipse and go to the Workbench as shown in the previous section. Then, click on Servers tab at bottom. R-click, New, Server, Apache, Tomcat v6.0, navigate to folder, OK. You should now see "Tomcat v6.0 Server at localhost" listed under the Servers tab at the bottom.
 

3. Run Tomcat.
Click on Servers tab at bottom. R-click on Tomcat v6.0, choose "Start". Open http://localhost/ in a browser: you should see an empty page showing a blank directory listing (but not a 404 error). Eclipse incorrectly fails to copy the welcome pages when it sets up Tomcat, so if you want the friendlier welcome page, go to your-eclipse-workspace.metadata and search for "ROOT". Copy all of the files from C:apache-tomcat-6.0.28webappsROOT into the ROOT folder inside your-eclipse-workspace.metadata...ROOT. 
If you fail to copy the ROOT files as mentioned above, http://localhost/ will result in an empty directory listing. It is often mistaken for an error page, but if you look closely you will see that it says "directory listing for /" and is not an error at all. However, if you copy the ROOT files, http://localhost/ will give the nice friendly "Welcome to Tomcat" page.
4.  Make empty project.
a.       File, New, Project, Web, Dynamic Web Project.
b.      Give it a name (e.g., "SampleWebServer").
c.       Accept all other defaults.

5. Make a Welcome.html and place it on the ‘WebContent’ folder of your new Dynamic Web App.
6. Now if you type http://localhost:8080/SampleWebServer/Welcome.htmlin your browser, you should be able to view the page. 



Read More..

Optimizing for Bandwidth on Apache and Nginx

| 0 comments |
This post originally appeared on Webmaster Central
by Jeff Kaufman, Make the Web Fast


Webmaster level: advanced
Everyone wants to use less bandwidth: hosts want lower bills, mobile users want to stay under their limits, and no one wants to wait for unnecessary bytes. The web is full of opportunities to save bandwidth: pages served without gzip, stylesheets and JavaScript served unminified, and unoptimized images, just to name a few.
So why isnt the web already optimized for bandwidth? If these savings are good for everyone then why havent they been fixed yet? Mostly its just been too much hassle. Web designers are encouraged to "save for web" when exporting their artwork, but they dont always remember.  JavaScript programmers dont like working with minified code because it makes debugging harder. You can set up a custom pipeline that makes sure each of these optimizations is applied to your site every time as part of your development or deployment process, but thats a lot of work.

An easy solution for web users is to use an optimizing proxy, like Chromes. When users opt into this service their HTTP traffic goes via Googles proxy, which optimizes their page loads and cuts bandwidth usage by 50%.  While this is great for these users, its limited to people using Chrome who turn the feature on and it cant optimize HTTPS traffic.

With Optimize for Bandwidth, the PageSpeed team is bringing this same technology to webmasters so that everyone can benefit: users of other browsers, secure sites, desktop users, and site owners who want to bring down their outbound traffic bills. Just install the PageSpeed module on your Apache or Nginx server [1], turn on Optimize for Bandwidth in your configuration, and PageSpeed will do the rest.

If you later decide youre interested in PageSpeeds more advanced optimizations, from cache extension and inlining to the more aggressive image lazyloading and defer JavaScript, its just a matter of enabling them in your PageSpeed configuration.

Learn more about installing PageSpeed or enabling Optimize for Bandwidth.

[1] If youre using a different web server, consider running PageSpeed on an Apache or Nginx proxy.  And its all open source, with porting efforts underway for IIS, ATS, and others.

Posted by Mano Marks, Google Developer Platform Team
Read More..