Wednesday, July 30, 2008

Generics

Generics allow you to abstract over types. The most common examples are container types, such as those in the Collection hierarchy.

When you take an element out of a Collection, you must cast it to the type of element that is stored in the collection. Besides being inconvenient, this is unsafe. The compiler does not check that your cast is the same as the collection's type, so the cast can fail at run time.

Generics provides a way for you to communicate the type of a collection to the compiler, so that it can be checked. Once the compiler knows the element type of the collection, the compiler can check that you have used the collection consistently and can insert the correct casts on values being taken out of the collection.

Here is a simple example taken from the existing Collections tutorial:

// Removes 4-letter words from c. Elements must be strings
static void expurgate(Collection c) {
for (Iterator i = c.iterator(); i.hasNext(); )
if (((String) i.next()).length() == 4)
i.remove();
}

Here is the same example modified to use generics:

// Removes the 4-letter words from c
static void expurgate(Collection c) {
for (Iterator i = c.iterator(); i.hasNext(); )
if (i.next().length() == 4)
i.remove();
}

Monday, July 28, 2008

Firefox Add-ons - Fire bug

Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page...
Firebug 1.2 requires Firefox 3. Firefox 2 users should install the older 1.05 version of Firebug.

https://addons.mozilla.org/en-US/firefox/addon/1843

Thursday, July 24, 2008

Linux BASH command line

These are several useful Linux commands.

df ----Display free disk space
gzip ----Compress or decompress named file(s)
history ----Command History
ifconfig ----See the ip address of the machine

This is the url:
http://www.ss64.com/bash/

Wednesday, July 23, 2008

Selenium IDE


Selenium is a test tool for web applications. Selenium tests run directly in a browser, just like real users do. It runs in Internet Explorer, Mozilla and Firefox on Windows, Linux, and Macintosh, Safari on the Mac.I tested it in Firefox on Linux.The quickest way to learn Selenium is via a Firefox plugin called Selenium IDE.
http://selenium.openqa.org/

We can download it from
http://selenium-ide.openqa.org/download.jsp
I used Version 0.8.7

This is a good link for learning about selenium.
http://blog.taragana.com/index.php/archive/5-minute-guide-to-selenium-ide-and-selenium-rc-test-tools/

Our project(Admomentum) uses Selenium Remote Control rather than Selenium IDE. The Selenium Remote Control allows you to develop test cases and test suites in Java (supports JUnit & NGUnit), PHP, Ruby, Python, Perl and even .NET. It is the most flexible setup but requires some development knowledge to set up and use.

How To Raise a "File Download" Dialog Box

When you serve a document from a Web server, you might want to immediately prompt the user to save the file directly to the user's disk, without opening it in the browser. However, for known MIME (Multipurpose Internet Mail Extensions) types such as Microsoft Word ("application/ms-word"), the default behavior is to open the document in Internet Explorer.You can use the content-disposition header to override this default behavior. Its format is:

Content-disposition: attachment; filename=fname.ext

Content-disposition is an extension to the MIME protocol that instructs a MIME user agent on how it should display an attached file.When Internet Explorer receives the header, It raises a File Download dialog box whose file name box is automatically populated with the file name that is specified in the header.

To apply the header dynamically, create an Active Server Pages (ASP) file that writes the document out to the browser. Use the Response.AddHeader method to add the content-disposition header. For example:

Response.AddHeader "content-disposition","attachment; filename=fname.ext"

in Java
response.addHeader(CONTENT_DISPOSITION, conditionalParse(contentDisposition, invocation));

Tuesday, July 22, 2008

UTF-8 and shift-jis

UTF-8 (8-bit UCS/Unicode Transformation Format) is a variable-length character encoding for Unicode. It is able to represent any character in the Unicode standard, yet the initial encoding of byte codes and character assignments for UTF-8 is backwards compatible with ASCII. For these reasons, it is steadily becoming the preferred encoding for e-mail, web pages.

Shift JIS is a character encoding for the Japanese language.

This is a sample example of using encoding in Java.

filename = new StringBuilder();
private static final String DEFAULT_CHARSET = "ISO-8859-1";

try {
filename.append(new String(getText("campaign.download.filename.prefix").getBytes("UTF-8"), DEFAULT_CHARSET))
.append("-")
.append(sdf.format(now))
.append("-")
.append(new String(getCampaign().getName().toLowerCase().replace(" ", "-").getBytes("UTF-8"), DEFAULT_CHARSET))
.append(".csv");
} catch (UnsupportedEncodingException e) {
addActionError(getText("error.advertisementCsv.failedToDownload"));
return INPUT;
}

Monday, July 21, 2008

CSS float Property

The float property allows two div elements to display in same line.The float property sets where an image or a text will appear in another element.Note: If there is too little space on a line for the floating element, it will jump down on the next line, and continue until a line has enough space.

img
{
float: left
}

Remote Access in PostgreSQL databases

When we need to allow to someone to access our PostgreSQL database in our machine, we need to put following code in our pg_hba.conf file.

# Allow a user from host 192.168.12.10 to connect to database
# "postgres" if the user's password is correctly supplied.
#
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host postgres all 192.168.12.10/32 md5

This is a useful site regarding that.

http://developer.postgresql.org/pgdocs/postgres/auth-pg-hba-conf.html

Friday, July 18, 2008

Remote login in Ubuntu

When you need to remote login to a another machine, first you need to change the remote desktop preferences of the machine which you need to connect and then run following command withing your machine.

vncviewer 172.23.69.90
or
vncviewer -fullscreen 172.23.69.90

change the ip address as u need. This is remote login with user interface.

The command for remote login in command pront is:
eg:
ssh silsaj@cmb1u119.cmb1.fast.no

Thursday, July 17, 2008

md5sum in Linux

A checksum is a form of redundancy check, a simple way to protect the integrity of data by detecting errors in data that are sent through space (telecommunications) or time (storage). It works by adding up the basic components of a message, typically the assorted bits, and storing the resulting value.
These types of redundancy check are useful in detecting accidental modification such as corruption to stored data or errors in a communication channel. However, they provide no security against a malicious agent as their simple mathematical structure makes them trivial to circumvent. To provide this level of integrity, the use of a cryptographic hash function, such as SHA-256,MD5 is necessary. In cryptography, MD5 (Message-Digest algorithm 5) is a widely used, partially insecure cryptographic hash function with a 128-bit hash value.

md5sum is a computer program that calculates and verifies 128-bit MD5 hashes, as described in RFC 1321. The MD5 hash (or checksum) functions as a compact digital fingerprint of a file. It is extremely unlikely that any two non-identical files existing in the real world will have the same MD5 hash (although as with all such hashing algorithms, in theory there is an unlimited number of files that will have any given MD5 hash).

In Linux, we use following command to check the checksum of a file.
md5sum -b ojdbc14.jar

Wednesday, July 9, 2008

Regular Expression

This is a simple java application for using regular expressions in Java.

import java.util.regex.*;

public class Regex {

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

Pattern p = Pattern.compile("[,\\s]+");
String[] result = p.split("one,two, three four , five");
for (int i=0; i System.out.println(result[i]);



String textSubject = "aasasa2323";
Pattern brackets = Pattern.compile(".*\\{[h][e][l][l][o]\\}.*");
Matcher fit = brackets.matcher(textSubject);
if (fit.find()) {
System.out.println ("Found");
} else {
System.out.println ("Not found");
}

}

}

Thursday, July 3, 2008

Download accelerator for Ubuntu

I'm using Ubuntu 7.10 (Gutsy Gibbon) in the working place. This link was useful for me to find details about it.

http://ubuntuguide.org/wiki/Ubuntu:Gutsy

Axel is a lightweight command line download accelerator for ubuntu. This link provides the procedure to use it.

http://blog.codefront.net/2007/04/29/axel-lightweight-command-line-download-accelerator/


Web developer 1.1.6 is an add-on to Firefox which is a very useful tool for web developers. This is the url:
https://addons.mozilla.org/en-US/firefox/addon/60

Today when I'm giving permissions to files and folders, this article was useful for me.
http://www.freeos.com/articles/4440/