28 February, 2008

Xml elements and attributes in the ExtJS table

Ext JS - JavaScript Library is pretty powerful JavaScript/AJAX framework for building of Rich Internet Applications.

I've used it in my last public web project: Ubuntu index.


ExtJS has set of useful UI controls, internal components and strong AJAX, XML and JSON support.

E.g. you can present this XML file:



items.xml <?xml version="1.0"?> <items> <item id="alien-arena"> <name>Alien Arena</name> </item> <item id="nexuiz"> <name>Nexuiz</name> </item> <item id="openarena"> <name>OpenArena</name> </item> </items>


as a table via this HTML + JavaScript code:



table.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>ExtJS Table Sample</title> <link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css"/> <script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext/ext-all.js"></script> </head> <body> <script type="text/javascript"> Ext.onReady(function() { var reader = new Ext.data.XmlReader({record: "item"}, [{name: "id", mapping:"@id"}, "name"]); var store = new Ext.data.Store({url: "items.xml", reader: reader}); var columnModel = new Ext.grid.ColumnModel([ {header: "Id", dataIndex: "id"}, {header: "Name", dataIndex: "name"}]); var table = new Ext.grid.GridPanel({ store: store, height: 200, cm: columnModel, renderTo: "table" }); store.load(); }); </script> <div id="table" style="width:300px; height:200px;"></div> </body> </html>



22 January, 2008

Linux reference

I found really useful documentation for Linux beginners.


"This Debian Reference (http://qref.sourceforge.net/) is intended to provide a broad overview of the Debian system as a post-installation user’s guide. It covers many aspects of system administration through shell-command examples. Basic tutorials, tips, and other information are provided for topics including fundamental concepts of the Debian system, system installation hints, Debian package management, the Linux kernel under Debian, system tuning, building a gateway, text editors, CVS, programming, and GnuPG for non-developers."


This book is devoted to Debian system but it is topical for some other Linux systems.

StarCraft (Brood War) under Linux (Wine)

I use this script to play network StarCraft under wine:

#!/bin/bash

#At first, run "wine setup.exe"

BROODWAR_HOME=/usr/games/broodwar

ipx_interface add -p eth0 802.2 0x39ab0222
cd $BROODWAR_HOME
xinit /usr/bin/wine starcraft.exe


I think it is the best game.

Flash-light from console

With this script I use my monitor as flash-light in the darkness.

#!/bin/bash

#Switch monitor (CRT or LCD) to flash-light mode.

echo -e "\\033[47;30m"
clear
read
echo -e "\\033[0m"
clear

16 January, 2008

Java processes viewer

There is a way how to retrieve information about all running JVMs.
Since Java 1.5 Sun provides sources of jvmstat classes for JVM monitoring.

I've created simple program that is used these classes.
It detects all running JVMs and prints their information.



JavaPS.java


import java.util.Set;
import sun.jvmstat.monitor.HostIdentifier;
import sun.jvmstat.monitor.MonitoredHost;
import sun.jvmstat.monitor.MonitoredVm;
import sun.jvmstat.monitor.StringMonitor;
import sun.jvmstat.monitor.VmIdentifier;

public class JavaPS {
private static final String[] vmProperties = new String[]{
"java.property.java.vm.name",
"java.property.java.vm.vendor",
"java.property.java.vm.version",
"java.property.java.home",
"java.property.java.class.path",
"java.rt.vmArgs",
"java.rt.vmFlags",
"sun.rt.javaCommand"};

public static void main(String[] args) {
Set jvms;
MonitoredHost monitoredHost;

try {
monitoredHost = MonitoredHost.getMonitoredHost(new HostIdentifier("localhost"));
jvms = monitoredHost.activeVms();
} catch (Exception e) {
e.printStackTrace();
return;
}

for (Object jvm : jvms) {
int jvmid = (Integer) jvm;
System.out.println("Process ID: \t" + String.valueOf(jvmid));
try {
VmIdentifier id = new VmIdentifier("//" + jvmid + "?mode=r");
MonitoredVm vm = monitoredHost.getMonitoredVm(id, 0);
for (String vmProperty : vmProperties) {
System.out.println(vmProperty + ": \t"
+ ((StringMonitor) vm.findByName(vmProperty)).stringValue());
}
System.out.println();
monitoredHost.detach(vm);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}


Aliases for virtual machine's properties have been taken from jdk1.5 sources (jdk-1_5_0-src-scsl.zip) from the file j2se\src\share\classes\sun\jvmstat\perfdata\resources\aliasmap.

Compile this code via command:
javac -classpath %JAVA_HOME%\lib\tools.jar JavaPS.java
and run:
java -classpath .;%JAVA_HOME%\lib\tools.jar JavaPS >JavaPS.txt

jvmstat package locates in tools.jar


Example of results output:


JavaPS.txt

Process ID: 2144
java.property.java.vm.name: Java HotSpot(TM) Client VM
java.property.java.vm.vendor: Sun Microsystems Inc.
java.property.java.vm.version: 1.6.0_03-b05
java.property.java.home: C:\Program Files\Java\jre1.6.0_03
java.property.java.class.path: .;E:\Devel\jdk1.5.0_09\lib\tools.jar
java.rt.vmArgs:
java.rt.vmFlags:
sun.rt.javaCommand: JavaPS

Process ID: 364
java.property.java.vm.name: Java HotSpot(TM) Client VM
java.property.java.vm.vendor: Sun Microsystems Inc.
java.property.java.vm.version: 1.6.0_03-b05
java.property.java.home: C:\Program Files\Java\jre1.6.0_03
java.property.java.class.path: SwingSet2.jar
java.rt.vmArgs:
java.rt.vmFlags:
sun.rt.javaCommand: SwingSet2.jar