Uzi's Blogs

Things I learn, observe and try out

Wednesday, December 02, 2009

Blogging moved

Further blogging will be done at http://usmans.info

Kindly update your bookmarks.

Tuesday, September 22, 2009

Fix for sound issue in Ubuntu 9.04 HP Pavilion dv4000

The sound was giving error on my HP dv4000 running Ubuntu 9.04.

Here is the listing of my hardware modules:

00:1e.2 Multimedia audio controller: Intel Corporation 82801FB/FBM/FR/FW/FRW (ICH6 Family) AC'97 Audio Controller (rev 04)
Subsystem: Hewlett-Packard Company Device 309d
Flags: bus master, medium devsel, latency 0, IRQ 17
I/O ports at 1c00 [size=256]
I/O ports at 18c0 [size=64]
Memory at b0040800 (32-bit, non-prefetchable) [size=512]
Memory at b0040400 (32-bit, non-prefetchable) [size=256]
Capabilities:
Kernel driver in use: Intel ICH
Kernel modules: snd-intel8x0

Adding following at the end of /etc/modprobe.d/alsa-base.conf

options snd-intel8x0 ac97_quirk=1 buggy_irq=1 buggy_semaphore=1


if ac97_quirk=1 doesn't work, try 0,2,3 or 4 as value.

Reboot.

Labels: , , , , , , , , ,

Saturday, July 12, 2008

A very simple java based Ident server

Every now and then I need to connect to IRC servers and I don't run a full blown identd daemon on my Ubuntu machine. Hence I come up with a very simple java based Ident server. Simply run it before connecting to an IRC server, it will terminate once the response is served. Its a quick and dirty code, not production quality at all. Feel free to use it at your own risk.


import java.net.*;
import java.io.*;

/*
* This class acts as a simple Ident server
* usage: sudo java jident [<fakeid>]
* fakeid is optional, if not passed, nobody is used.
* It simply terminates once ident response is served.
* Best use is to run before connecting to an irc server.
* If on Linux, it should be called using 'sudo' since it
* runs on port 113.
* Use at your own risk.
* @author Usman Saleem
* @version 1.0
*/
public class jident {

public static void main(String args[]){
//create a server socket on port 113
try {
int port = 113;
System.out.println("Simple java based identd server by Uzi");
ServerSocket srv = new ServerSocket(port);

// Wait for connection from client.
Socket socket = srv.accept();

BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String msg = br.readLine();
//should be in format <port-on-server> , <port-on-client>
System.out.println("Request: "+msg);
if(msg != null) {
//send response back to server
msg+= " : USERID : UNIX : " + (args.length>=1?args[0]:"nobody");
System.out.println("Response: "+msg);
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
wr.write(msg);
wr.newLine();
wr.flush();
System.out.println("Response sent, waiting from server");
System.out.println("server:"+br.readLine());

}
socket.close();
srv.close();
System.out.println("Done.");

} catch (IOException e) {
e.printStackTrace();
System.exit(-1);
}



}

}

Thursday, June 12, 2008

Removing c compilation error: stdio.h: No such file or directory on Ubuntu

If you are compiling a simple c program on Ubuntu and you get following stupid error(s):error: stdio.h: No such file or directory then you need to install 'build-essential' package. This can be install using Synaptic Package Manager or apt-get.

Friday, May 02, 2008

Wii, Wasabi and Wii-Clip

The other day I luckily manage to purchase a Nintendo Wii while I was here in Florida at a client site for a month. Since I had to take that back to home, I wasn't sure if the games available there would be playable on this Wii or not. So, I did some research ... order wasabi modchip alongside Wii-Clip ... installed it in Wii with the help of a friend and hopefully I will be now able to play region free games on it :-).

Labels: , ,

Wednesday, March 07, 2007

NJ Album

Tuesday, March 06, 2007

My visit to EnterpriseDB Edison office

I am at EnterpriseDB Iselin (New Jersey) office for a business trip of 6 weeks.

Enjoying the warm welcome by everyone in the office. It will be a memorable trip of my life.

Monday, October 16, 2006

I became Sun Certified Web Component Developer

Cleared SCWCD today on October 16, 2006 around 11:15 PST with passing score of 82%. Not very happy with the score, it should have been higher :-). But, as they say 'a pass is a pass'.

Monday, August 28, 2006

Setting Custom icon for individual nodes in JTree

For changing and removing the Default Icons in a JTree Component see following link:
http://javaalmanac.com/egs/javax.swing.tree/DefIcons.html

However, above approach does not take care of individual icons. Here is the solution that I used in one of my projects:

1. Let your nodes extend from a generic super class, say MyNode, where MyNode is extended from DefaultMutableTreeNode. Define public abstract Icon getIcon(); in MyNode.


/**
* My Node
* @author usman
*/
public abstract class MyNode extends DefaultMutableTreeNode{

 public MyNode () {
  super("Title Of Node);
 }

 public abstract javax.swing.Icon getIcon();
}


2. Create sub classes of MyNode which are supposed to be inserted into the tree, implementing getIcon method, for instance:

/**
* Custom Node
* @author usman
*/
public class CustomNode extends MyNode{

 public CustomNode() {
  super("Title Of Node);
 }

 public
javax.swing.Icon getIcon() {
  return new javax.swing.ImageIcon(getClass().getResource("/icons/myicon16.png"));
 }
}

Now create a custom tree cell renderer, in which you set the default icon based on the sub class type:

import java.awt.Component;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;

public class CustomTreeCellRenderer extends DefaultTreeCellRenderer{
 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
 if((value instanceof MyNode) && (value != null)) {
  setIcon(((MyNode)value).getIcon());
  }

//we can not call super.getTreeCellRendererComponent method, since it overrides our setIcon call and cause rendering of labels to '...' when node expansion is done

//so, we copy (and modify logic little bit) from super class method:

 String stringValue = tree.convertValueToText(value, sel,
expanded, leaf, row, hasFocus);

 this.hasFocus = hasFocus;
 setText(stringValue);
 if(sel)
   setForeground(getTextSelectionColor());
 else
   setForeground(getTextNonSelectionColor());

 if (!tree.isEnabled()) {
   setEnabled(false);
 }
 else {
   setEnabled(true);
 }
  setComponentOrientation(tree.getComponentOrientation());
 selected = sel;
 return this;

}
}


The method of interest is getTreeCellRendererComponent in which we call getIcon method of our sub classes and sets the icon of current node. We don't call super class method directly because it somehow mess up with default width calculation of our nodes and cause '...' in rendering the labels. The '...' is specially visible if we programmatically expand children of a node.

Wednesday, August 23, 2006

EnterpriseDB Replication Server

EnterpriseDB adds replication server under its belt. For official details see http://www.enterprisedb.com/news_events/press_releases/15_08_06b.do

This is the project I am currently working on. I am responsible for refactoring the user interface and building it from grounds up using NetBeans IDE. NetBeans GUI builder a.k.a Mattise is perhaps the best Java UI designer I have ever worked with. Well, it is good enough to make me switch from Eclipse IDE to NetBeans IDE as my primary development platform :-)

Under the hood, project Replication Server UI (internally we call it Replication Console) is built upon best coding practices as well as utilizes MVC and several GOF design patterns. Build as pure swing based thin client, it uses RMI to communicate with backend Replication Servers and web services to communicate with EnterpriseDB DBA Management Server.

Here is the screenshot of the upcoming Replication Server Beta 2 UI.



Other cool things that I am "responsible" for integrating in this project are: .1. Integrating AXIS based web services engine to control replication servers life cycles, .2. extending JBoss Microcontroller (JBoss MBean Services) to hook up replication servers with DBA Management Server and last but not least, several backend code refactoring back in the days of Beta 0 and Beta 1 :-)

EnterpriseDB Wins Best Database Award at LinuxWorld

EnterpriseDB Wins Best Database Award at LinuxWorld for Second Consecutive Year; Enterprise Open Source Database Takes Top Honor, Besting Oracle, Others...

http://www.enterprisedb.com/news_events/press_releases/18_08_06.do

Well, since it is my company, I won't say much :-), just that I am so proud.

Friday, March 10, 2006

Sun Certified Business Component Developer for J2EE 1.3

Today on Friday, March 10, 2006 around 3'o clock I have attempted and cleared Sun Certified Business Component Developer for J2EE 1.3 with flying colors ... an excellent score of 95% .... 67 correct questions out of a total of 70 questions .... hip hip hurray :-)

Thursday, March 02, 2006

Neural Java Index

Neural Java Index: "Neural Networks Tutorial with Java Applets"

Wednesday, February 15, 2006

FlazX - Welcome to your Computer & IT learning center

Tuesday, January 31, 2006

Autopackage : Easy Linux Software Installation

Autopackage : Easy Linux Software Installation: "Autopackage makes software installation on Linux easy. Software distributed using Autopackage can be installed on multiple Linux distributions and integrate well into the desktop environment."

Thursday, January 26, 2006

Windows XP: Changing IP Address, Gateway and DNS from command line (or batch script)

netsh interface ip set address [connection] static [ip] [mask] [gateway] 1

netsh interface ip set dns [connection] static [first]

netsh interface ip add dns [connection] [second] index=2

For example, Following entries will change network connection "Local Area Connection" with IP address 10.10.1.15, Mask 255.255.255.0, Gateway 10.0.0.10 and Primary DNS 10.90.1.1 and Seconday DNS 10.90.1.2 (All values are hypothetical)

netsh interface ip set address "Local Area Connection" static 10.10.1.15 255.255.255.0 10.0.0.10 1

netsh interface ip set dns "Local Area Connection" static 10.90.1.1

netsh interface ip add dns "Local Area Connection" 10.90.1.2 index=2


Using above entries/commands one can update network settings/configuration of Laptop in different LAN environments.

Thursday, January 05, 2006

Universal Console Redirector - The Code Project - Threads, Processes & IPC

Wednesday, December 28, 2005

JSF Tutorial from Marty Hall and coreservlets.com

Cewolf - Chart Enabling Web Object Framework

Cewolf can be used inside a Servlet/JSP based web application to embed complex graphical charts of all kinds (e.g. line, pie, bar chart, plots, etc.) into a web page. Therefore it provides a full featured tag library to define all properties of the chart (colors, strokes, legend, etc.). Thus the JSP which embedds the chart is not polluted with any java code. Everything is described with XML conform tags.

Thursday, December 08, 2005

Drawing eyes...

Wednesday, November 30, 2005

Sed one liner examples

Wednesday, November 23, 2005

Automatic form submission after specified time using javascript

Put following code after your form tag:

<script language="Javascript">
function doSubmit() {

//asubmit is the name of the SUBMIT button in the form
document.yourForm.asubmit.click();
}
//auto submit after 5 second
setTimeout("doSubmit()",5000);
</script>

Thursday, November 03, 2005

Eid Greetings

Eid Greetings .... today would be the last day of holy month Ramadan and tomorrow would be Eid InshaAllah.

Thursday, October 20, 2005

Reading windows environment variable in java

import java.io.*;
public class Test{
public static void main(String args[]) throws IOException{
//JDK1.5
System.out.println(System.getenv("USERDOMAIN"));

//Pre-JDK1.5
Process p = Runtime.getRuntime().exec("cmd.exe /c echo %USERDOMAIN%");
BufferedReader br = new BufferedReader
( new InputStreamReader( p.getInputStream() ) );
String myvar = br.readLine();
System.out.println(myvar);

}
}

NIST Internet Time Service

NIST Internet Time Service: "Set Your Computer Clock Via the Internet
NIST Internet Time Service (ITS)"

Free Java JSP Servlet Web Hosting and WebServices Hosting

Free Java JSP Servlet Web Hosting and WebServices Hosting: "Java servlet/JSP/MySQL web hosting, web service hosting, J2SE 5.0(1.5), Apache 2.0, Tomcat 5.5 (Private JVM), MySQL 4.1(Your own db), SMTP, POP accounts, 99% uptime, 24x7 monitoring."

Friday, October 14, 2005

LinuxQuestions.org- How To Configure the KDE 3.3 Menu manually (without KMenuEdit) - LinuxAnswers

Monday, September 26, 2005

Rob van der Woude's Scripting Pages: Batch Files, Rexx, KiXtart, Perl, VBScript

Wednesday, September 21, 2005

Javassist

Javassist:

"Javassist (Java Programming Assistant) makes Java bytecode manipulation simple. It is a class library for editing bytecodes in Java; it enables Java programs to define a new class at runtime and to modify a class file when the JVM loads it. Unlike other similar bytecode editors, Javassist provides two levels of API: source level and bytecode level. If the users use the source-level API, they can edit a class file without knowledge of the specifications of the Java bytecode. The whole API is designed with only the vocabulary of the Java language. You can even specify inserted bytecode in the form of source text; Javassist compiles it on the fly. On the other hand, the bytecode-level API allows the users to directly edit a class file as other editors."

Tuesday, September 20, 2005

Java Examples - JExamples.com

Java Examples - JExamples.com We analyze the source code of production Java open source projects such as Ant, Tomcat and Batik and load that analysis into a java examples database designed for easy searching. You enter the name of a Java API Class you want to see example invocations of and click Search.

Friday, September 16, 2005

pastebin - collaborative debugging tool

pastebin - collaborative debugging tool

You have some code that you want to share on some forum or with a group of people on internet, use the above site, it does exactly that.

You will get a URL like http://pastebin.com/365340

Simply excellent.

--Uzi

How to create and use a patch in Linux

Tuesday, September 13, 2005

SNMP4J - Free Open Source SNMP API for Java

SNMP4J - Free Open Source SNMP API for Java
The SNMP4J Java SNMP API provides the following features:

* SNMPv3 with MD5 and SHA authentication and DES and AES 128, AES 192, and AES 256 privacy.
* Pluggable Message Processing Models with implementations for MPv1, MPv2c, and MPv3
* All PDU types.
* Pluggable transport mappings. UDP and TCP are supported out-of-the-box.
* Pluggable timeout model.
* Synchronous and asynchronous requests.
* Command generator as well as command responder support.
* Free open source with the Apache license model
* Java™ 1.4.1 or later
* Logging based on Log4J
* Row-based efficient asynchronous table retrieval with GETBULK.
* Multi-threading support.
* JUnit tests (will be available soon)

The SNMP4J-Agent pure Java SNMP agent API adds command responder support to the SNMP4J core API and comes with:

* Implementations for SNMP-TARGET-MIB, SNMP-NOTIFICATION-MIB, SNMP-FRAMEWORK-MIB, SNMPv2-MIB, SNMP-COMMUNITY-MIB, SNMP-USER-BASED-SM-MIB, SNMP-VIEW-BASED-ACM-MIB, and SNMP-MPD-MIB.
* SNMPv1,v2c,v3 multi-lingual agent support, including MD5 and SHA authentication as well as DES and AES(128, 196, 256) privacy.
* IPv4/IPv6 UDP and TCP support.
* Code generation from MIB specifications is provided through AgenPro 2 which is a language and API independent template based code generator with round-trip generation facilities.

Friday, September 09, 2005

ClockLink.com


Clock Link provides fashionable clocks that you can easily embed in your web page. All you need to do is simply paste the tag on your web page. Our clock will display the city name of your choice if you choose. You can also choose a time zone for your clock so it will show the correct time. Decorate your website with our clocks.


I have used this clock in my blogger as well. Take a look at the right side, Pakistan Standard Time. Neat.....

Thursday, September 08, 2005

Changing network configuration on Windows from Java

Use freely available jRegistryKey API (http://www.bayequities.com/tech/Products/jreg_key.shtml ) or any other API to manipulate windows registry as follows:

1. Open registry on the HKEY_LOCAL_MACHINE

2. Find the subKey = SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\"netcard# "

"netcard# " usually is "1" but you can control any subkey and find specific netwrok Adapters

Refer to "MSDN Registry Entries for Network Adapter Cards"

3. Get data for the value "ServiceName"

4. Find the subKey = SYSTEM\CurrentControlSet\Services\"ServiceName"\Parameters\TcpIp"

5. Set data for the value "IpAddress" to change IP address

6. Set data for the value "SubnetMask" to change subnet mask

7. Set data for the value "DefaultGateway" to change default gateway

8. Reboot your PC.

Disclaimer: I haven't yet tested changing the network configuration, change above reigstry keys at your own risk!

Using urdu fonts in Java

Other day someone asked me how to use Urdu fonts in Java. So for a sample java program that uses urdu font, you need to do following:

1. Download Nafees Nastaleeq Urdu font from CRULP.

2. Copy the font in C:\WINDOWS\Fonts folder

3. Create following java program. It should display "Usman" in Urdu.


import java.awt.*;
import javax.swing.*;

public class BasicDraw {
public static void main(String[] args) {
new BasicDraw();
}
BasicDraw() {
// Create a frame
JFrame frame = new JFrame();

// Add a component with a custom paint method
frame.getContentPane().add(new MyComponent());

// Display the frame
int frameWidth = 200;
int frameHeight = 200;
frame.setSize(frameWidth, frameHeight);
frame.setVisible(true);
}

class MyComponent extends JComponent {
// This method is called whenever the contents needs to be painted
public void paint(Graphics g) {
int style = Font.PLAIN;
int size = 24;
Font font = null;
font = new Font("Nafees Nastaleeq", style, size);
String text = "\u0639\u062b\u0645\u0627\u0646";
g.setFont(font);

// Draw a string such that its base line is at x, y
int x = 80;
int y = 40;
g.drawString(text, x, y);
}
}
}


4. The resulting image should look like:

Monday, September 05, 2005

Visiting lectures at Quaid-e-Azam University

Started September 2nd, 2005, I am delievering visiting lectures at Quaid-e-Azam University, Islamabad, Pakistan for the subject of Object Oriented Programming to the students of M.Sc.

I have delievered visiting lectures for the same subject (graduate level) at Punjab College of Information Technology (aff. with Mohammad Ali Jinnah University) and at College of Information Technology (aff. with Allama Iqbal Open University) before joining my current job (2003-2004).

Other subjects at my credentials are Intro. to Database Management Systems and E-Commerce.

Friday, August 19, 2005

Experience with open source office productivity softwares

I have recently switched over to following two greate open source tools:

Sun OpenOffice 1.9.122 (open source replacement for MS Office)
Mozilla Thunderbird (email client)

So far my experience with both of these softwares is quite good.

Besides the above two, following are other open source softwares I am using on my MS Windows platform:

Gaim 1.4.0 (Instant Messaging Tool for Yahoo, MSN and many more)
ASpell (Spell checker)
Mozilla Firefox (Internet browser)
7-Zip (Compression tool handles zip, rar and many more compression algorithms)

Following great softwares are also on my PC (not open source but free):

FlashGet (Download manager)
SmartCVS (although I have purchased professioanl license, but its available for free as foundation version)
Acrobat Reader 7.0
K-Lite Codec Pack (useful collection of mostly used codecs)

Enjoy,

Uzi

Wednesday, August 10, 2005

EnterpriseDB at LinuxWorld

Following photos are of EnterpriseDB desk at LinuxWorld .... what does the thrid one implies? :-)


Shahzad


Scott


The Award...



Kewl......

--Uzi

Thursday, August 04, 2005

Whitespace programming language

Whitespace Programming language, a new language out there with only three tokens: space, tab and line feed.

The language itself is an imperative, stack based language. Each command consists of a series of tokens, beginning with the Instruction Modification Parameter (IMP). These are listed in the table below.

IMP Meaning
[Space] Stack Manipulation
[Tab][Space] Arithmetic
[Tab][Tab] Heap access
[LF] Flow Control
[Tab][LF] I/O



Here is a sample ws program from their tutorial:

Annotated Example


Here is an annotated example of a program which counts from 1 to 10, outputting
the current value as it goes.

[Space][Space][Space][Tab][LF] Put a 1 on the stack

[LF][Space][Space][Space][Tab][Space][Space]
[Space][Space][Tab][Tab][LF]
Set a Label at this point


[Space][LF][Space]Duplicate the top stack item

[Tab][LF][Space][Tab]Output the current value

[Space][Space][Space][Tab][Space][Tab][Space][LF]
Put 10 (newline) on the stack...

[Tab][LF][Space][Space]...and output the newline


[Space][Space][Space][Tab][LF]Put a 1 on the stack

[Tab][Space][Space][Space]Addition. This increments our current value.

[Space][LF][Space]Duplicate that value so we can test it

[Space][Space][Space][Tab][Space][Tab][Tab][LF]
Push 11 onto the stack


[Tab][Space][Space][Tab]Subtraction. So if we've reached the end, we have a zero on the stack.

[LF][Tab][Space][Space][Tab][Space][Space]
[Space][Tab][Space][Tab][LF]If we have a zero, jump to the end


[LF][Space][LF][Space][Tab][Space]
[Space][Space][Space][Tab][Tab][LF]
Jump to the start


[LF][Space][Space][Space][Tab][Space]
[Space][Space][Tab][Space][Tab][LF]
Set the end label


[Space][LF][LF]Discard our accumulator, to be tidy

[LF][LF][LF]Finish


What could be simpler? The source code for this program is available
here. Have fun!


Tuesday, August 02, 2005

EnterpriseDB selected as Best Database Solution at LinuxWorld San Francisco 2005 Finalists

EnterpriseDB is selected as one of the "Best Database Solution" at LinuxWorld San Francisco 2005 Finalists.

This is really an honor for me as an employee of EnterpriseDB and Lead on EDB-Installer to see our product listed in Linux World's Best Database Solution finalists.

Cool.... :-)

Faster MS Office Outlook

Here is the recipe for a faster outlook.

Turn off MS Word as editor from Tools->Options->Mail Format->Uncheck Use Microsoft Office Word ....

"Compose in this Message format" should be Plain Text.


Consequences
MS Word is off loaded from memory, making outlook much faster. Good thing....

No spelling check .... very very bad!

Here is the (free) solution for spell check not only in "MS-Word free Outlook" but in any other windows application.

Download and install FreeSpell which is based on ASpell.

Freespell does the trick, select any text in any application, hit the Freespell key combination (by default WindowsKey+Z), Aspell comes into play and you have your mistake free text replaced.

The only drawback of FreeSpell is that it can not be minimize to system tray. So, download another (free) utility that can make any windows application iconify to System Tray, its called TrayIt!. No installation required, just run the downloaded executable, press CTRL, minimize your desired application and there it goes into system tray ... Neat isn't it :-).

Now I have cleaner, faster Outlook, and usable spell checker .....

Enjoy!

Tuesday, July 26, 2005

Java Examples from The Java Developers Almanac 1.4

Java Examples from The Java Developers Almanac 1.4
The best resource to obtain quick, short, useful java code snippets. I simply adore this site.

Linux: Determine your distro

Using cat /etc/issue command should let you know your linux distribution.

Here is output of this command on my system:

[usman@isb-usman ~]$ cat /etc/issue
Fedora Core release 4 (Stentz)
Kernel \r on an \m

Wednesday, July 20, 2005

Redhat Gnome 2 Menu categories

Wednesday, July 13, 2005

What is faster - LinkedList of ArrayList? (Author: Dr. Heinz M. Kabutz)

What is faster - LinkedList of ArrayList?

As programmers, we often try to eke the last ounce of performance out of our collections. An interesting statement is this: "ArrayList is faster than LinkedList, except when you remove an element from the middle of the list." I have heard this on more than one occasion, and a few months ago, decided to try out how true that statement really was. Here is some code that I wrote during last week's Java 5 Tiger course:

import java.util.*;

public class ListTest {
private static final int NUM_ELEMENTS = 100 * 1000;
public static void main(String[] args) {
List ar = new ArrayList();
for (int i = 0; i < NUM_ELEMENTS; i++) {
ar.add(i);
}
testListBeginning(ar);
testListBeginning(new LinkedList(ar));
testListMiddle(ar);
testListMiddle(new LinkedList(ar));
testListEnd(ar);
testListEnd(new LinkedList(ar));
}
public static void testListBeginning(List list) {
long time = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
list.add(0, new Object());
list.remove(0);
}
time = System.currentTimeMillis() - time;
System.out.println("beginning " +
list.getClass().getSimpleName() + " took " + time);
}
public static void testListMiddle(List list) {
long time = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
list.add(NUM_ELEMENTS / 2, new Object());
list.remove(NUM_ELEMENTS / 2);
}
time = System.currentTimeMillis() - time;
System.out.println("middle " +
list.getClass().getSimpleName() + " took " + time);
}
public static void testListEnd(List list) {
long time = System.currentTimeMillis();
for (int i = 0; i < 10000000; i++) {
list.add(new Object());
list.remove(NUM_ELEMENTS);
}
time = System.currentTimeMillis() - time;
System.out.println("end " +
list.getClass().getSimpleName() + " took " + time);
}
}


One small little addition in Java 5 is the method getSimpleName() defined inside Class. I do not know how many times I have needed such a method and have had to write it.

The output is obvious, but surprising nevertheless in the extent of the differences:

beginning ArrayList took 4346
beginning LinkedList took 0
middle ArrayList took 2104
middle LinkedList took 26728
end ArrayList took 731
end LinkedList took 1242


Finding the element in the middle of the LinkedList takes so much longer that the benefits of just changing the pointer are lost. So, LinkedList is worse than ArrayList for removing elements in the middle, except perhaps if you are already there (although I have not tested that).

So, when should you use LinkedList? For a long list that works as a FIFO queue, the LinkedList should be faster than the ArrayList. However, even faster is the ArrayBlockingQueue or the CircularArrayList that I wrote a few years ago. The answer is probably "never".

Kind regards

Heinz

Read it all here...

Monday, July 11, 2005

C-JDBC - Clustered JDBC

C-JDBC - Clustered JDBC: "C-JDBC is a free open source database cluster middleware that allows any Java application (standalone application, servlet or EJB container, ...) to transparently access a cluster of databases through JDBC(tm). The database is distributed and replicated among several nodes and C-JDBC balances the queries among these nodes. C-JDBC handles node failures and provides support for checkpointing and hot recovery."

JBoss EJB 3.0 Beta 1

JBoss EJB 3.0 Beta 1

The JBoss Group has announced the availability of EJB 3.0 Beta 1. 'This release models as closely as possible to the upcoming Public Draft of the EJB 3.0 specification. The spec was a fast moving target the past few weeks, so we still need to cross the T's and dot the i's as far as spec compliance goes. We plan on doing another release sometime in July to complete some of the minor stuff we are missing. Special thanks goes especially to Emmanuel Bernard, Bill DeCoste, and of course Gavin 'guys! guys!' King.'

Full Story:

(Source: java.net)

Saturday, July 09, 2005

alphaWorks : Remote System Management Tool : Overview

alphaWorks : Remote System Management Tool : Overview: "Remote System Management Tool

An integrated environment for remote system management, including file systems, users, and processes on any UNIX or Windows server.

What is Remote System Management Tool?

Remote Server Management Tool is an Eclipse plug-in that provides an integrated graphical user interface (GUI) environment and enables testers to manage multiple remote servers simultaneously. The tool is designed as a management tool for those who would otherwise telnet to more than one server to manage the servers and who must look at different docs and man pages to find commands for different platforms in order to create or manage users and groups and to initiate and monitor processes. This tool handles these operations on remote servers by using a user-friendly GUI; in addition, it displays configuration of the test server (number of processors, RAM, etc.). The activities that can be managed by this tool on the remote and local server are divided as follows:

* Process Management: This utility lists the process running on UNIX and Windows® servers. One can start and stop processes. Along with process listing, the utility also provides details of the resources used by the process.

* User Management: This utility facilitates creation of users and groups on UNIX servers; it also provides options for listing, creating, deleting, and modifying the attributes of users and groups.

* File Management: This utility acts as a windows explorer for any selected server, irrespective of its operating system. One can create, edit, delete, and copy files and directories on local or remote servers. Testers can tail the remote files.

How does it work?
This Eclipse plug-in was written with the Standard Widget Toolkit (SWT). The tool has a perspective named Remote System Management; the perspective consists of test servers and a console view. The remote test servers are mounted in the Test Servers view for management of their resources (process, file system, and users or groups).

At the back end, this Eclipse plug-in uses the Software Test Automation Framework (STAF). STAF is an open-source framework that masks the operating system-specific details and provides common services and APIs in order to manage system resources. The APIs are provided for a majority of the languages. Along with the built-in services, STAF also supports external services. The Remote Server Management Tool comes with two STAF external services: one for user management and another for proving system details.

Software Testing Automation Framework (STAF)

Software Testing Automation Framework (STAF):
The Software Testing Automation Framework (STAF) is an open source, multi-platform, multi-language framework designed around the idea of reusable components, called services (such as process invocation, resource management, logging, and monitoring). STAF removes the tedium of building an automation infrastructure, thus enabling you to focus on building your automation solution.

STAX is an execution engine which can help you thoroughly automate the distribution, execution, and results analysis of your testcases. STAX builds on top of three existing technologies, STAF, XML, and Python, to place great automation power in the hands of testers. STAX also provides a powerful GUI monitoring application which allows you to interact with and monitor the progress of your jobs.

Other STAF services are also provided to help you to create an end-to-end automation solution. Other STAF services include: Event, EventManager, Cron, Email, HTTP, NamedCounter, FSExt (File System EXTension), and Timer.

Open Source Release For Sun's App Server

Open Source Release For Sun's App Server
By Jim Wagner

Sun Microsystems (Quote, Chart) is quietly releasing the source code to the upcoming Java System Application Server, Platform Edition 9, under the GlassFish project, named after a semi-transparent aquarium fish.

The company is expected to release the source code for its Java-based application server under a new open source license as it kicks off its JavaOne conference in San Francisco today.

Read more here...

Software Engineer

The following quote is taken from Rapid J2EE Development: An Adaptive Foundation for Enterprise Applications By Alan Monnox which I am studying nowadays.

The title software engineer is worthy of further elaboration. IT professionals have a propensity for putting all manner of titles on business cards, from systems analyst and enterprise architect to quality specialist and IT consultant. The true software professional, however, is an extremely versatile individual who is fully capable of fulfilling many, but not necessarily all, of the predefined roles on a project. It is to this type of individual that I apply the term software engineer. Putting aside for a moment the technical description of the role and the associated computer scientist tag, a software engineer is someone who not only knows his or her profession but knows it well. He or she can effectively contribute in all project phases, whether analysis, design, implementation, or testing. Moreover, a software engineer continually looks for new ideas to improve what he or she does and how it is done. In short, a software engineer understands that self-improvement and continuous learning are fundamental activities for an IT professional.

Friday, July 08, 2005

Fedora Core 4 Tips & Tricks

Fedora Core 4 Tips & Tricks. Wish to take your Fedora Core 4 experience to next level, try the tips presented in this link. They offer all those things which by default are not part of official Fedora Core 4 but they should be!

I setup successfully XMMS MP3 plugin, Xine DVD player, NTFS Module and Flash plugin (which I require most).

I am enjoying it since Fedora Core 2.

Great stuff ...

Pakistan Times | Top Story: Major Internet disruption in Pakistan continues for 4th consecutive day

Monday, June 27, 2005

Beyond the obvious

Beyond the obvious ..... respect! ..... the man that groom me professionaly, give me chance to prove myself ....... I have utmost respect for him .....

Sunday, June 26, 2005

Gaim 1.3.1

Gaim

Gaim is a multi-protocol instant messaging (IM) client for Linux, BSD, MacOS X, and Windows. It is compatible with AIM and ICQ (Oscar protocol), MSN Messenger, Yahoo!, IRC, Jabber, Gadu-Gadu, SILC, GroupWise Messenger, and Zephyr networks.

Gaim users can log in to multiple accounts on multiple IM networks simultaneously. This means that you can be chatting with friends on AOL Instant Messenger, talking to a friend on Yahoo Messenger, and sitting in an IRC channel all at the same time.

Gaim supports many features of the various networks, such as file transfer, away messages, typing notification, and MSN window closing notification. It also goes beyond that and provides many unique features. A few popular features are Buddy Pounces, which give the ability to notify you, send a message, play a sound, or run a program when a specific buddy goes away, signs online, or returns from idle; and plugins, consisting of text replacement, a buddy ticker, extended message notification, iconify on away, spell checking, tabbed conversations, and more.

Gaim runs on a number of platforms, including Windows, Linux, and Qtopia (Sharp Zaurus and iPaq).

Gaim integrates well with GNOME 2 and KDE 3.1's system tray, as well as Windows's own system tray. This allows you to work with Gaim without requiring the buddy list window to be up at all times.

Google Suggest - Beta

Google Suggest - Beta As you type, Google will offer suggestions. Use the arrow keys to navigate the results. Learn more

7-Zip (Opensource file archiver)

7-Zip
7-Zip is a file archiver with high compression ratio.

7-Zip is free software distributed under the GNU LGPL.

The main features of 7-Zip:

* High compression ratio in new 7z format with LZMA compression
* 7-Zip is free software distributed under the GNU LGPL
* Supported formats: 7z, ZIP, CAB, RAR, ARJ, GZIP, BZIP2, Z, TAR, CPIO, RPM and DEB
* For ZIP and GZIP formats 7-Zip provides compression ratio that is 2-10 % better than ratio provided by PKZip and WinZip
* Self-extracting capability for 7z format
* Integration with Windows Shell
* Powerful File Manager
* Powerful command line version
* Plugin for FAR Manager
* Localizations for 55 languages

Anonymizer: free web proxy, CGI proxy list, free anonymizers and the list of web anonymizers list

MyJavaServer - Free Java hosting service

MyJavaServer. The free java hosting service. I have utilized this when it used to be known as mycgiserver.com. I must say, you ought to try it, it will only take your time and skill, no money whatsoever. I my early days of testing java online, I created following site jMaster ... those golden old university days......

Friday, June 24, 2005

[SmartCVS]

[SmartCVS] Perhaps the best CVS tool that I have used ever. Worth every penny I spend on it! ($70)

Thursday, June 23, 2005

Avoiding Java Runtime exec method space problem

Typical way of executing an external process in java is using java.lang.Runtime class' exec method.

Its most comman usage is
getRuntime().exec("c:\\somefolder\\somecommand.exe");

Assume there is a space in the folder, amazingly the above form will work, for instance
getRuntime().exec("c:\\some folder\\somecommand.exe");

But this form will fail if we have two or more consective spaces, for instance
getRuntime().exec("c:\\some  folder\\somecommand.exe");
It will raise java.io.IOException.

Exception in thread "main" java.io.IOException: CreateProcess: C:\some folder\somecommand.exe error=2
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
...


It seems that StringTokenizer used by exec(String) method is minimizing more that one white space to single space.

The workaround is to create single element array of String holding command and pass it to exec method.

String[] command = new String[1]; //for providing arguments, create multiple elements

command[0] = "c:\\some  folder\\somecommand.exe";
getRuntime().exec(command);

and this time it works like a charm.

Keep coding in java .... :-)

Affan's Blog: Sharks ... what about 'em? (Part 1)

Affan's Blog: Sharks ... what about 'em? (Part 1) Here is an interesting article about "sharks" ....

Fact 1: Shark is our company's official logo
Fact 2: Affan is a very good n old friend of mine. He was also my university fellow.
Fact 3: He happens to be VP in our company :-)

Enjoy,

Fedora Core 4 experience

Today I finally managed to install Fedore Core 4 on my office laptop. When I first logged in, every thing seems same as it was in Fedore Core 3 (except the new default theme Clearlooks), the top panel, the bottom panel and the default background. However, upon closer inspection I have found out that they have introduce two new menus besides Applications; Places and Desktop.

Desktop now contains Preferences and System settings sub-menus and it allows you to lock the screen and logout as well.

Places contains shortcuts to Home, Desktop, Computer, Connect to Server..., and Search for Files. Out of these the "Connect to Server..." is preety useful. It allows you to connect to SSH, FTP, Windows Share, Web Dev etc. from one single dialog box.

They have also bundled several useful tools in Fedora Core 4, the one I like best is Native Eclipse 3.1.

They are getting better day by day ... and convincing me more and more to minimize the usage of Windoze and increase the usage of Linux in daily course of business.

Monday, June 20, 2005

DivX 6

DivX 6 Play Bundle

It is now considered to be rival of DVD since it now has capability of menus etc.

Saturday, June 18, 2005

Articles published on developer.com

Friday, June 17, 2005

Ju Rao's Homepage: Free Computer Books

Ju Rao's Homepage: Free Computer Books

The best resource of publicly, freely and legally available ebooks on net. I learned a lot from the ebooks refered from this resource.

It does not hosts the books, it provides the links to the original books where they are hosted.

FireTune: Speedup, tweak, optimize and tune Firefox easily - faster browsing, faster surfing - faster connection for Mozilla Firefox

FireTune: Speedup, tweak, optimize and tune Firefox easily - faster browsing, faster surfing - faster connection for Mozilla Firefox

Yes, it works ..... pages are opening up much faster than before. I pick settings Faster Computer/Faster Connection.

Best of all, its free!

Xtra-Google - The Best of Google on one searchable page

Xtra-Google - The Best of Google on one searchable page

Find this page while searching, a definite for googlers :). This page is not associated with Google Inc.

Tuesday, June 14, 2005

Fedora Project, sponsored by Red Hat

Fedora Project, sponsored by Red Hat Fedora Core 4 is now available. Once downloaded and installed I'll post my user experience with this new version of Fedora Core.

Monday, June 13, 2005

Don't hate the hacker, hate the code

Whoever said that, I totally agree with it. Writing code that doesn't break is an ethical responsiblity of every coder.

I think to achive this, a coder has to think like a code breaker .... and how to think like a code breaker .... well you should be able to break code of others .... and ultimately yours own!

Orkut..More annoyance than comfort

Orkut .... Orkut proves that .NET is crashing when it is being loaded .... enormously ....

Thursday, June 09, 2005

Interesting Java program


This is perhaps the most interesting java behavior that I have encountered. Try to guess the output before actually compiling it and running it.

public class Guess {
public static void main(String args[]) {
for(int i=0;i<=args.length;i++){
System.out.println(args[i]);
}
}

Run this program as follows:
>java Guess *

If you think that program will produce * as output, then you are wrong my brother, you need to try it out yourself :)

--Uzi

Wrapper over runas utility

Runas is a useful Windows utility that allows to run programs as different users. But this utility can not be executed from batch files (password cannot be piped). Hence I comeup with my own program which is a wrapper over runas and it is scriptable.

This is achived by utilizing another C++ class SendKeys, which I downloaded from http://www.codeproject.com/cpp/sendkeys_cpp_Article.asp . This is a useful piece of code that allows to "send keys" to another active application.

Here is the code sample how I achieve this:

CSendKeys sk;
//create runas process
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );

si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );

if( !CreateProcess( NULL, // No module name (use command line).
(LPTSTR)(LPCTSTR)runas , // Command line. runas is like "c:\\windows\\system32\\runas.exe /env /user:user command"
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
CREATE_NEW_CONSOLE,// Openup process in a new console
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ) // Pointer to PROCESS_INFORMATION structure. ) {
cerr << "CreateProcess failed:" <<>
return -1;
}
WaitForInputIdle(pi.hProcess,INFINITE);
//activate it using sk

sk.AppActivate((LPCTSTR)runasPath);

//pass password (I pick it up from command line)
pass = pass + "{ENTER}";
sk.SendKeys(pass);

// Wait until child process exits. (make it an argument?)
WaitForSingleObject( pi.hProcess, INFINITE );

// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );

This program can be called (from a .bat file, for example) RunAsAnotherUser username password command.

Cheerz,

--Uzi

First Post, finally

This is the first post I am making on blogger....I hope this will grow as time passes...