Tuesday 30 November 2010

Java Regex...

Parsing Using Java Regex:

import java.util.regex.*;

public class SampleRegex
{
public static void main(String[] params)
{
Pattern pattern = Pattern.compile("(.*):(.*)");
Matcher matcher = pattern.matcher(params[0]);
if(matcher.matches())
{
System.out.print("Key:");
System.out.println(matcher.group(1));
System.out.print("Value:");
System.out.println(matcher.group(2));
}
else
System.out.print("No match");
}
}

Further reading links:
1. http://www.developer.com/article.php/1460561
2. http://download.oracle.com/javase/tutorial/essential/regex/

Friday 26 November 2010

do While Loop PL/SQL Oracle...

There is nothing like do while loop in PL/SQL. But you can do the following:

SQL> declare
2 n_num number := 1;
3 begin
4 loop
5 dbms_output.put(n_num||', ');
6 n_num := n_num + 1;
7 exit when n_num > 5;
8 end loop;
9 dbms_output.put_line('Final: '||n_num);
10 end;
11 /

For details visit: http://www.dba-oracle.com/concepts/pl_sql_repeat_until_loop.htm

Matching Date in Sed: A Filename comparison example....

$ echo "01_hello_world_filename_22-07-2010.csv" | sed 's/^\([0-9]\{2\}\)\(_hello_world_filename_\)\(0[1-9]\|[12][0-9]\|3[01]\)-\(0[1-9]\|1[012]\)-\(19\|20\)[0-9]\{2\}.Csv$/Matched/ig'

Output: Matched

Wednesday 24 November 2010

SED : Tutorial 2

Deleting Everything after first H
echo "Fawad 123 Hello How are you" | sed s/H.*//
Output: Fawad 123

Double Substitution
$ echo "Fawad is a friend of Nazir" | sed 's/Fawad/Midhat/g;s/Nazir/Fawad/g'
Output: Midhat is a friend of Fawad

Matching Exact Patterns using [ and ].
$ echo "Aaminah is a name" | sed s/[aA][aA]/BB/g
Output: BBminah is a name

REF: http://www.grymoire.com/Unix/Regular.html

Regular Expression Matches
[] The characters "[]"
[0] The character "0"
[0-9] Any number
[^0-9] Any character other than a number
[-0-9] Any number or a "-"
[0-9-] Any number or a "-"
[^-0-9] Any character except a number or a "-"
[]0-9] Any number or a "]"
[0-9]] Any number followed by a "]"
[0-9-z] Any number,
or any character between "9" and "z".
[0-9\-a\]] Any number, or
a "-", a "a", or a "]"

Matching a specific number of sets with \{ and \}
Regular Expression Matches
_
* Any line with an asterisk
\* Any line with an asterisk
\\ Any line with a backslash
^* Any line starting with an asterisk
^A* Any line
^A\* Any line starting with an "A*"
^AA* Any line if it starts with one "A"
^AA*B Any line with one or more "A"'s followed by a "B"
^A\{4,8\}B Any line starting with 4, 5, 6, 7 or 8 "A"'s
followed by a "B"
^A\{4,\}B Any line starting with 4 or more "A"'s
followed by a "B"
^A\{4\}B Any line starting with "AAAAB"
\{4,8\} Any line with "{4,8}"
A{4,8} Any line with "A{4,8}"

Matching words with \< and \>

Searching for a word isn't quite as simple as it at first appears. The string "the" will match the word "other". You can put spaces before and after the letters and use this regular expression: " the ". However, this does not match words at the beginning or end of the line. And it does not match the case where there is a punctuation mark after the word.
There is an easy solution. The characters "\<" and "\>" are similar to the "^" and "$" anchors, as they don't occupy a position of a character. They do "anchor" the expression between to only match if it is on a word boundary. The pattern to search for the word "the" would be "\<[tT]he\>". The character before the "t" must be either a new line character, or anything except a letter, number, or underscore. The character after the "e" must also be a character other than a number, letter, or underscore or it could be the end of line character.

Backreferences - Remembering patterns with \(, \) and \1

Another pattern that requires a special mechanism is searching for repeated words. The expression "[a-z][a-z]" will match any two lower case letters. If you wanted to search for lines that had two adjoining identical letters, the above pattern wouldn't help. You need a way of remembering what you found, and seeing if the same pattern occurred again. You can mark part of a pattern using "\(" and "\)". You can recall the remembered pattern with "\" followed by a single digit. Therefore, to search for two identical letters, use "\([a-z]\)\1". You can have 9 different remembered patterns. Each occurrence of "\(" starts a new pattern. The regular expression that would match a 5 letter palindrome, (e.g. "radar"), would be
\([a-z]\)\([a-z]\)[a-z]\2\1

Examples:
1. Remember a pattern
$ echo "Aaminah Aaminah is a name" | sed 's/\(A[a-z]*\) \1/\1/g'
Output: Aaminah is a name

2. Eliminate the repeating characters.
$ echo "mmmmy nnname iis ffawad." | sed 's/\([a-z]\)\{1,3\}\1/\1/g'
Output: my name is fawad.

3. Keep first word and delete the rest.

$ echo "mmmmy nnname iis ffawad." | sed 's/\([a-z]*\).*/\1/'
Output: mmmmy

3. Printing the Last name & replacing the first name with last.
$ echo "Mr. Fawad Nazir" | sed 's/\([Ff]awad\) \([Nn]azir\)/\2 \1/'
Output: Mr. Nazir Fawad
$ echo "Mr. Fawad Nazir" | sed 's/\([Ff]awad\) \([Nn]azir\)/\2/'
Output: Mr. Nazir

3. Subtituting exact match words:
$ echo "ad Fawad ad Nazad ad" | sed 's/ ad/ xx /g'
Output: ad Fawad xx Nazad xx
$ echo "ad Fawad ad Nazad ad" | sed 's/ ad / xx /g'
Output: ad Fawad xx Nazad ad
$ echo "ad Fawad ad Nazad ad" | sed 's/ad/ xx /g'
Output: xx Faw xx xx Naz xx xx
$ echo "ad Fawad ad Nazad ad" | sed 's// xx /g'
Output: ad Fawad ad Nazad ad
$ echo "ad Fawad ad Nazad ad" | sed 's/\/ xx /g'
Output: xx Fawad xx Nazad xx
$ echo "ad Fawad ad Nazad ad" | sed 's/\/xx/g'
Output: xx Fawad xx Nazad xx


END of Tutorial 2.

Tuesday 23 November 2010

PL/SQL Script to Compare All Rows in Two Tables...

I have written the following script to compare all rows in two tables using three hashes. Its is quite useful. It can be extended to compare all tables in two databases...

DEFINE V_TABLE_1 = 'TABLE_ONE_NAME';
DEFINE V_TABLE_2 = 'TABLE_TWO_NAME';

SET SERVEROUTPUT ON
/
DECLARE

COLUMN_STRING VARCHAR(1000):='''START''';
HASH_TABLE_1 NUMBER;
HASH_TABLE_2 NUMBER;

BEGIN

FOR MINT IN
(
SELECT COLUMN_NAME FROM USER_TAB_COLUMNS where table_name = '&V_TABLE_1'
)
LOOP
COLUMN_STRING := COLUMN_STRING ||'||'|| MINT.COLUMN_NAME;
END LOOP;

SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE(COLUMN_STRING,1,POWER(2,16)-1)) INTO HASH_TABLE_1 FROM &V_TABLE_1;
DBMS_OUTPUT.PUT_LINE('SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE('||COLUMN_STRING||',1,POWER(2,16)-1)) INTO HASH_TABLE_1 FROM &V_TABLE_1');
DBMS_OUTPUT.PUT_LINE('Hash Table 1-1 :'||HASH_TABLE_1);

SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE(COLUMN_STRING,1,POWER(2,16)-1)) INTO HASH_TABLE_2 FROM &V_TABLE_2;
DBMS_OUTPUT.PUT_LINE('SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE('||COLUMN_STRING||',1,POWER(2,16)-1)) INTO HASH_TABLE_2 FROM &V_TABLE_2');
DBMS_OUTPUT.PUT_LINE('Hash Table 2-1 :'||HASH_TABLE_2);

IF HASH_TABLE_1 = HASH_TABLE_2 THEN
DBMS_OUTPUT.PUT_LINE('TABLES MATCH');
ELSE
DBMS_OUTPUT.PUT_LINE('TABLES DO NOT MATCH');
END IF;

SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE(COLUMN_STRING,1,POWER(2,18)-1)) INTO HASH_TABLE_1 FROM &V_TABLE_1;
DBMS_OUTPUT.PUT_LINE('SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE('||COLUMN_STRING||',1,POWER(2,18)-1)) INTO HASH_TABLE_1 FROM &V_TABLE_1');
DBMS_OUTPUT.PUT_LINE('Hash Table 1-2 :'||HASH_TABLE_1);

SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE(COLUMN_STRING,1,POWER(2,18)-1)) INTO HASH_TABLE_2 FROM &V_TABLE_2;
DBMS_OUTPUT.PUT_LINE('SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE('||COLUMN_STRING||',1,POWER(2,18)-1)) INTO HASH_TABLE_2 FROM &V_TABLE_2');
DBMS_OUTPUT.PUT_LINE('Hash Table 2-2 :'||HASH_TABLE_2);

IF HASH_TABLE_1 = HASH_TABLE_2 THEN
DBMS_OUTPUT.PUT_LINE('TABLES MATCH');
ELSE
DBMS_OUTPUT.PUT_LINE('TABLES DO NOT MATCH');
END IF;

SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE(COLUMN_STRING,1,POWER(2,20)-1)) INTO HASH_TABLE_1 FROM &V_TABLE_1;
DBMS_OUTPUT.PUT_LINE('SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE('||COLUMN_STRING||',1,POWER(2,20)-1)) INTO HASH_TABLE_1 FROM &V_TABLE_1');
DBMS_OUTPUT.PUT_LINE('Hash Table 1-3 :'||HASH_TABLE_1);

SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE(COLUMN_STRING,1,POWER(2,20)-1)) INTO HASH_TABLE_2 FROM &V_TABLE_2;
DBMS_OUTPUT.PUT_LINE('SELECT SUM(DBMS_UTILITY.GET_HASH_VALUE('||COLUMN_STRING||',1,POWER(2,20)-1)) INTO HASH_TABLE_2 FROM &V_TABLE_2');
DBMS_OUTPUT.PUT_LINE('Hash Table 2-3 :'||HASH_TABLE_2);

IF HASH_TABLE_1 = HASH_TABLE_2 THEN
DBMS_OUTPUT.PUT_LINE('TABLES MATCH');
ELSE
DBMS_OUTPUT.PUT_LINE('TABLES DO NOT MATCH');
END IF;

END;
/

Oracle: Materialized View

One of the most useful replication and data warehousing features in Oracle is materialized views. The data in a materialized view is updated by either a complete or incremental refresh. An incremental or fast refresh uses a log table to keep track of changes on the master table.

Create a Materialized View:
---------------------------

CREATE MATERIALIZED VIEW "SCHEMA_NAME"."MV_NAME" ("Column_1", "Column_2", "Column_3", "Column_4", "Column_5", "Column_6") ORGANIZATION HEAP PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING TABLESPACE "USERS" BUILD IMMEDIATE USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 REFRESH COMPLETE ON DEMAND START WITH sysdate+0 NEXT sysdate+2/24 USING DEFAULT LOCAL ROLLBACK SEGMENT USING ENFORCED CONSTRAINTS DISABLE QUERY REWRITE
AS
SELECT Column_1 ,
Column_2 ,
Column_3 ,
Column_4 ,
Column_5 ,
Column_6
FROM Table_name

Query Metadata for MV's:
------------------------
SELECT mview_name, refresh_mode, refresh_method,
last_refresh_type, last_refresh_date
FROM user_mviews;

More Information: http://www.dba-oracle.com/t_materialized_view_fast_refresh_performance.htm

SED : Tutorial 1

REF: http://www.grymoire.com/Unix/Sed.html

$echo day | sed s/day/night/
Output: night

$echo Sunday | sed 's/day/night/'
Output: Sunnight

slash/underscore/colon as a delimiter
---------------

$echo "/home/fawad/sed" | sed 's/\/home\/fawad\/sed/\/home\/nazir\/fawad/'
Output: /home/nazir/fawad

$echo "/home/fawad/sed" | sed 's_/home/fawad/sed_/home/nazir/fawad_'
Output: /home/nazir/fawad

$echo "/home/fawad/sed" | sed 's:/home/fawad/sed:/home/nazir/fawad:'
Output: /home/nazir/fawad

Using & as the matched string
-----------------------
$echo "123 Fawad Nazir" | sed 's/F[a-z]*/(&)/'
Output: 123 (Fawad) Nazir

The values is saved in &. So now you can use it in different ways...

$echo "123 Fawad Nazir" | sed 's/F[a-z]*/(&) [&] _&_ *&*/'
Output: 123 (Fawad) [Fawad] _Fawad_ *Fawad* Nazir

Fun: Only Print a and nothing else
$echo "Fawad Nazir Is a Great Man hahahaha" | sed s/[^a]/\ /g
Output: a a a a a a a a a a

Sunday 21 November 2010

Download Forex Rates Using AWK...

AWK & SED are the best tools ever developed....

I am writing an application to do Forex Analysis in AWK & SED... using SydneyForex Web-site:

Simple: In order to get the rates for AUD/PKR...

$wget https://www.sydneyforex.com.au/RateHistory.aspx?id=1


$awk '/PAKISTAN/' pakfile.txt | awk '{split($2,a,">")} {split($3,b,"<")} {split($5,c,"<")} {split(c[1],d,">")} {print a[2], b[1]," ", d[2]}';

DONE....

Stay Tuned...

Tuesday 16 November 2010

Using Mail Server on Linux...

Send Email:

$mailx -s "Email Sibject" User_Name@Host_Name < Message_File_Name

Check new emails:
$mail

View all emails:
Goto Home Directoty $cd ~
Then, you should find a mbox folder
$view mbox

Saturday 13 November 2010

Setting Up a Web-Service Core Engine Based on Axis2…

Main Web Page of Axis2: http://ws.apache.org/axis2/

Now we will follow the installation guide:

http://ws.apache.org/axis2/1_1/installationguide.html

Downloading and installing ANT:
Download Page : http://ant.apache.org/bindownload.cgi
Installation Page : http://ant.apache.org/manual/index.html

Downloading and installing Maven:

http://maven.apache.org/

Download Page : http://maven.apache.org/download.html
Install guide : http://maven.apache.org/maven-1.x/start/install.html

Deploy axis2.war in the tomcat servlet engine.
Login for axis2 admin console:
username: admin
password: axis2

Installing and updating the kernel to Linux-2.6.16 (Ubuntu – IDE)

1. Install Ubuntu 5.10.

2. To setup the root password, reboot the machine and press ESc to go into grub mode.

To to the recovery mode of Linux and press enter.

You will get to # prompt.

Type #passwd root, enter new password and reboot #init 6.

3. Goto System -> Administrator -> Networking and enable the eth0 card for networking support.

4. Goto System ->Administrator -> Synaptic Package Manager

5. Goto Settings -> Repositories. Add Community Maintained (Universe) and press OK.

6. Press “Reload” to update the package list.

7. Goto Terminal: and run all the following commands:

$sudo apt-get update
$sudo apt-get install build-essential
$sudo apt-get install kernel-package
$sudo apt-get install gcc
$sudo apt-get install libncurses5
$sudo apt-get install libncurses5-dev
$sudo apt-get install libqt3-mt-dev

8. Now configure ftp server to transfer new linux 2.6.16 files.

9. I will go for vsftp. You can also configure ftpd, ws-ftpd or proftpd etc.

To install vsftpd:

$sudo apt-get install vsftpd, This will install vsftpd server and start it.

Now we need to make some modifications to the configuration file.

comment #anonymous_enable=YES

Uncomment local_enable=YES

Uncomment write_enable=YES

Save this file and restart vsftpd by running this command. $sudo /etc/init.d/vsftpd restart

10. Upload linux-2.6.16.tar using ftp.

11. copy linux-2.6.16.tar to /usr/src/ folder.

12. cd /usr/src

13. $sudo tar –bzip2 -xvf linux-2.6.12.tar.bz2

14. $sudo ln -s /usr/src/linux-2.6.12 /usr/src/linux

15. Run $sudo make menuconfig or $sudo make xconfig to configure your new kernel.

16. $sudo make-kpkg clean

17. $sudo make-kpkg -initrd –append-to-version=-custom kernel_image modules_image kernel_headers

18. $sudo dpkg -i kernel-image-2.6.16-custom_10.00.Custom_i386.deb
19. $sudo dpkg -i kernel-headers-2.6.16-custom_10.00.Custom_i386.deb

20. Reboot the system $sudo init 6.

Setting up a wireless Testbed…(Host-AP drivers)

S#1: Machine A Master Mode and Machine B Managed Mode.

Machine A:

$sudo iwconfig wlan0 mode Master
$sudo iwconfig wlan0 essid “Hello-1″

Set the Static IP Address: 10.10.5.2 Mask: 255.0.0.0

root@Ubuntu-01:/etc/network# iwconfig wlan0
Warning: Driver for device wlan0 has been compiled with version 19
of Wireless Extension, while this program supports up to version 18.
Some things may be broken…

wlan0 IEEE 802.11b ESSID:”Hello-1″
Mode:Master Access Point: 00:00:00:00:00:00 Bit Rate:11 Mb/s
Sensitivity=1/3
Retry min limit:8 RTS thr:off Fragment thr:off
Encryption key:off
Power Management:off
Link Quality:0 Signal level:0 Noise level:0
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:0 Invalid misc:0 Missed beacon:0

root@Ubuntu-01:/etc/network# ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 00:02:6F:34:0B:79
inet addr:10.10.5.2 Bcast:10.255.255.255 Mask:255.0.0.0
inet6 addr: fe80::202:6fff:fe34:b79/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:69 errors:0 dropped:1 overruns:0 frame:0
TX packets:63 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4970 (4.8 KiB) TX bytes:5220 (5.0 KiB)
Interrupt:3 Base address:0×3100

Machine B:

$sudo iwconfig wlan0 mode Managed

Set the Static IP Address: 10.10.5.3 Mask: 255.0.0.0

Important : Gateway wlan0
Connect to EssID : Hello-1

fawad@nicta123:~$ iwconfig wlan0
Warning: Driver for device wlan0 has been compiled with version 19
of Wireless Extension, while this program supports up to version 18.
Some things may be broken…

wlan0 IEEE 802.11b ESSID:”Hello-1″
Mode:Managed Frequency:2.422 GHz Access Point: 00:02:6F:34:0B:79
Bit Rate:2 Mb/s Sensitivity=1/3
Retry min limit:8 RTS thr:off Fragment thr:off
Power Management:off
Link Quality=56/70 Signal level=-19 dBm Noise level=-75 dBm
Rx invalid nwid:0 Rx invalid crypt:3 Rx invalid frag:0
Tx excessive retries:30 Invalid misc:12165 Missed beacon:0

fawad@nicta123:~$ ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 00:60:B3:29:92:EE
inet addr:10.10.5.3 Bcast:10.255.255.255 Mask:255.0.0.0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:8799 errors:0 dropped:0 overruns:0 frame:0
TX packets:12472 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:853532 (833.5 KiB) TX bytes:1505635 (1.4 MiB)
Interrupt:3 Base address:0xe100

Now try pingning from the both ends. I think they should work.

S#2: Both Machine A & B in Ad-Hoc Mode.

Now in this case we have to see that in order for the machines to work in Ad-Hoc mode they should have same essid and channel.

Now lets configure machine A:

$sudo iwconfig wlan0 mode Ad-Hoc
$sudo iwconfig wlan0 channel 3
$sudo iwconfig wlan0 essid “Home”

fawad@Ubuntu-01:~$ iwconfig wlan0
Warning: Driver for device wlan0 has been compiled with version 19
of Wireless Extension, while this program supports up to version 18.
Some things may be broken…

wlan0 IEEE 802.11b ESSID:”Home”
Mode:Ad-Hoc Frequency:2.422 GHz Cell: 02:60:1B:27:92:EE
Bit Rate:11 Mb/s Sensitivity=1/3
Retry min limit:8 RTS thr:off Fragment thr:off
Power Management:off
Link Quality=56/70 Signal level=-40 dBm Noise level=-96 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:22 Invalid misc:40 Missed beacon:0

fawad@Ubuntu-01:~$ ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 00:02:6F:34:0B:79
inet addr:10.10.5.2 Bcast:10.255.255.255 Mask:255.0.0.0
inet6 addr: fe80::202:6fff:fe34:b79/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:144 errors:0 dropped:2 overruns:0 frame:0
TX packets:163 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13304 (12.9 KiB) TX bytes:17560 (17.1 KiB)
Interrupt:3 Base address:0×3100

On Machine B:

$sudo iwconfig wlan0 mode Ad-Hoc
$sudo iwconfig wlan0 channel 3
$sudo iwconfig wlan0 essid “Home”

fawad@nicta123:~$ iwconfig wlan0
Warning: Driver for device wlan0 has been compiled with version 19
of Wireless Extension, while this program supports up to version 18.
Some things may be broken…

wlan0 IEEE 802.11b ESSID:”Home”
Mode:Ad-Hoc Frequency:2.422 GHz Cell: 02:60:1B:27:92:EE
Bit Rate:11 Mb/s Sensitivity=1/3
Retry min limit:8 RTS thr:off Fragment thr:off
Power Management:off
Link Quality=55/70 Signal level=-18 dBm Noise level=-73 dBm
Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
Tx excessive retries:52 Invalid misc:984 Missed beacon:0

fawad@nicta123:~$ ifconfig wlan0
wlan0 Link encap:Ethernet HWaddr 00:60:B3:29:92:EE
inet addr:10.10.5.3 Bcast:10.255.255.255 Mask:255.0.0.0
inet6 addr: fe80::260:b3ff:fe29:92ee/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:144 errors:0 dropped:0 overruns:0 frame:0
TX packets:271 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13300 (12.9 KiB) TX bytes:24228 (23.6 KiB)
Interrupt:3 Base address:0xe100

Now try pinging each of the hosts i guess they should work.

Linux Commands…

Web Page With All Linux Commands…

Command to find what all files are open: $lsof
Command to see what is done when a command is executed: $strace , e.g. $strace ls

Command to change the file system of a disk
$sudo mkfs.ext3 -cv -L usbdisk2 /dev/sdc1

dpkg – a medium-level package manager for Debian
————————————————

This is like an rpm for Red-hat linux.

Man Page: http://www.fifi.org/cgi-bin/man2html/usr/share/man/man8/dpkg.8.gz

To list packages related to the editor vi:
dpkg -l ‘*vi*’

To search the listing of packages yourself:
less /var/lib/dpkg/available

To remove an installed elvis package:
dpkg -r elvis

To install a package, you first need to find it in an archive or CDROM. The “available” file shows that the vim package is in section “editors”:
cd /cdrom/hamm/hamm/binary/editors dpkg -i vim_4.5-3.deb

How to load Kernel modules at boot time…

fawad@Ubuntu-01:~$ more /etc/modules
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with “#” are ignored.

lp
mousedev
psmouse

How to Blacklist a module…

fawad@Ubuntu-01:/etc/hotplug$ echo ‘blacklist orinoco’ | sudo tee -a
/etc/modprobe.d/my_blacklist
blacklist orinoco
fawad@Ubuntu-01:/etc/hotplug$ echo ‘blacklist orinoco_cs’ | sudo tee
-a /etc/modprobe.d/my_blacklist
blacklist orinoco_cs

Where orinoco_cs & orinoco are the modules names.

The above tutorial will blacklist the kernel modules at the starup. But you modules might be loaded which anything is hotplugged into your computer.

For that i could not actually come-up with a solution but i think the way is to intsert modules names in the file:

root@Ubuntu-01:/etc/network# more /etc/hotplug/blacklist

Friday 12 November 2010

JBoss Remote Debugging... LINUX.

Normally people modify the run.sh file and add the following line:

JAVA_OPTS=%JAVA_OPTS% -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

I would recommend not to modify the run.sh file, rather just uncomment
the following line in the run.conf file in the same folder:

# Sample JPDA settings for remote socket debuging
JAVA_OPTS="$JAVA_OPTS -Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"

SIMPLE :).

Tuesday 9 November 2010

Experience While Copying a 42GB file into a Seagate USB Hardrive in Ubuntu Linux…

First of all i will split the file into 10GB pieces. The file name is: enwiki-20070908-stub-meta-history.xml

fawad@crete:~/wiki$ split -b 4000m enwiki-20070908-stub-meta-history.xml

Now i will copy a piece by piece into my seagate external hardrive. I am copying this file from a remote server to my machine

root@fawad-laptop:/home/fawad# scp fawad@crete.ex.nii.ac.jp:/home/fawad/wiki/enwiki-20070908-stub-meta-history.xml /media/usb0/niidata/split/
fawad@crete.ex.nii.ac.jp’s password:
enwiki-20070908-stub-meta-history.xml 10% 4091MB 10.5MB/s 57:03 ETAFile size limit exceeded (core dumped)
This means only files less than 4GB are supported. So i again spilled the files to 4GB file each.

Another important thing to note is that i had to use root login to copy file to my external seagate USB hardrive.

Now once i have splited the files into 4GB chunks. Now use the following command to copy all the files from this folder to one of the folder in the seagate harddrive.

root@fawad-laptop:/home/fawad# scp -r fawad@crete.ex.nii.ac.jp:/home/fawad/wiki/wikidata/ /media/usb0/niidata/wikifawad@crete.ex.nii.ac.jp’s password:
.nfs0000000000d5005100000001 100% 435MB 10.6MB/s 00:41
xad 27% 1101MB 9.5MB/s 05:05 ETARead from remote host crete.ex.nii.ac.jp: Connection reset by peer
xad 100% 4000MB 9.8MB/s 06:49
xag 100% 1233MB 9.8MB/s 02:06
xac 38% 1522MB 10.6MB/s 03:53 ETAh
xac 43% 1734MB 11.1MB/s 03:25 ETA
xac 100% 4000MB 10.1MB/s 06:38
xaf 100% 4000MB 10.2MB/s 06:32
xae 100% 4000MB 10.5MB/s 06:22
xaa 100% 4000MB 9.9MB/s 06:46
xab 39% 1573MB 9.9MB/s 04:05 ETARead from remote host crete.ex.nii.ac.jp: Connection reset by peer
xab 100% 4000MB 9.6MB/s 06:57

Installing MySql on Ubuntu Linux

fawad@fawad-desktop:~$ sudo apt-get install mysql-server

fawad@fawad-desktop:~$ mysqladmin -u root password 123456

fawad@fawad-desktop:~$ mysql -u root -p

mysql> CREATE DATABASE realitymining;
Query OK, 1 row affected (0.00 sec)

Upgrade Ubuntu from Edgy to Feisty

http://www.ubuntugeek.com/upgrade-ubuntu-610-edgy-eft-to-ubuntu-704-feisty-fawn-2.html

Method 2 – Using apt-get

Edit your /etc/apt/sources.list as root. Change every occurrence of edgy to feisty.

Use any prefered editor. If you have a CD-ROM line in your file, then remove it.

sudo vi /etc/apt/sources.list

or

use the following Simple command

sudo sed -e ’s/\edgy/ feisty/g’ -i /etc/apt/sources.list

Now you need to update the source list using the following command

sudo apt-get update

Upgrade using the following command

sudo apt-get dist-upgrade

Double check your process was finished properly using the following commd

sudo apt-get -f install

sudo dpkg –configure -a

Now you need to Reboot your machine to take your new ubuntu 7.04 installation to effect all changes.

Testing Your Upgrade

You can check the ubuntu version installed using the following command

sudo lsb_release -a

Output Looks like below

Distributor ID: Ubuntu
Description: Ubuntu feisty (development branch)
Release: 7.04
Codename: feisty

or

Just type the following command in your terminal

cat /etc/issue

Output Lokks like below

Ubuntu feisty (development branch) \n \l

Graph Visualization File Format...

Few visualization formats.

1. dot

2. fdp

3. neato

4. graphml

5. gml

6. ygf

Friday 5 November 2010

Limiting the rows being displayed in Oracle...

Link: http://www.adp-gmbh.ch/ora/sql/rownum.html

ROWNUM in SQL



rownum is a pseudo column. It numbers the records in a result set. The first record that meets the where criteria in a select statement is given rownum=1, and every subsequent record meeting that same criteria increases rownum.
After issuing a select statement, one of the last steps that oracle does is to assign an increasing (starting with 1, increased by 1) number to each row returned. The value of this row number can always be queried with rownum in a select statement:
select
rownum, column_1, column_2
from
table_1, table_2
where
field_3 = 'some value'
It is important to realize that the first row's rownum is always 1. This implies that the following query won't return a single row:
select
column_1, column_2
from
table_1, table_2
where
field_3 = 'some value'
and rownum > 5
This is so because the first row would have to meet the following two mutually excluding criterias:
  • rownum is 1
  • rownum is 6 (rownum > 5)
In order to do this query in the (probably) intended spirit, a sub-query must be executed:
select
column_1, column_2
from (
select
rownum r_, column_1, column_2
from
table_1, table_2
where
field_3 = 'some value'
)
where r_ > 5

Substituting NULL in Oracle using NVL...

LINK: http://www.techonthenet.com/oracle/functions/nvl.php

Oracle/PLSQL: NVL Function


In Oracle/PLSQL, the NVL function lets you substitute a value when a null value is encountered.

The syntax for the NVL function is:

NVL( string1, replace_with )

string1 is the string to test for a null value.

replace_with is the value returned if string1 is null.


Applies To:

  • Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g

Example #1:

select NVL(supplier_city, 'n/a')
from suppliers;

The SQL statement above would return 'n/a' if the supplier_city field contained a null value. Otherwise, it would return the supplier_city value.


Example #2:

select supplier_id,
NVL(supplier_desc, supplier_name)
from suppliers;

This SQL statement would return the supplier_name field if the supplier_desc contained a null value. Otherwise, it would return the supplier_desc.


Example #3:

select NVL(commission, 0)
from sales;

This SQL statement would return 0 if the commission field contained a null value. Otherwise, it would return the commission field.


Frequently Asked Questions


Question: I tried to use the NVL function through VB to access Oracle DB.

To be precise,

select NVL(DIstinct (emp_name),'AAA'),................ from.................

I got an oracle error when I use distinct clause with NVL, but when I remove distinct it works fine.

Answer: It is possible to the use the DISTINCT clause with the NVL function. However, the DISTINCT must come before the use of the NVL function. For example:

select distinct NVL(emp_name, 'AAA')
from employees;

Hope this helps!


Question: Is it possible to use the NVL function with more than one column with the same function call? To be clear, if i need to apply this NVL function to more than one column like this:

NVL(column1;column2 ...... , here is the default value for all )

Answer: You will need to make separate NVL function calls for each column. For example:

select NVL(table_name, 'not found'), NVL(owner, 'not found')
from all_tables;

Monday 1 November 2010

Oracle/PLSQL: Lag Function

REF: http://www.techonthenet.com/oracle/functions/lag.php

In Oracle/PLSQL, the lag function is an analytic function that lets you query more than one row in a table at a time without having to join the table to itself. It returns values from a previous row in the table. To return a value from the next row, try using the lead function.

The syntax for the lag function is:

lag ( expression [, offset [, default] ] )
over ( [ query_partition_clause ] order_by_clause )

expression is an expression that can contain other built-in functions, but can not contain any analytic functions.

offset is optional. It is the physical offset from the current row in the table. If this parameter is omitted, the default is 1.

default is optional. It is the value that is returned if the offset goes out of the bounds of the table. If this parameter is omitted, the default is null.


Applies To:

  • Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g

For example:

Let's take a look at an example. If we had an orders table that contained the following data:

ORDER_DATE PRODUCT_ID QTY
25/09/2007 1000 20
26/09/2007 2000 15
27/09/2007 1000 8
28/09/2007 2000 12
29/09/2007 2000 2
30/09/2007 1000 4

And we ran the following SQL statement:

select product_id, order_date,
lag (order_date,1) over (ORDER BY order_date) AS prev_order_date
from orders;

It would return the following result:

PRODUCT_ID ORDER_DATE PREV_ORDER_DATE
1000 25/09/2007
2000 26/09/2007 25/09/2007
1000 27/09/2007 26/09/2007
2000 28/09/2007 27/09/2007
2000 29/09/2007 28/09/2007
1000 30/09/2007 29/09/2007

Since we used an offset of 1, the query returns the previous order_date.

If we had used an offset of 2 instead, it would have returned the order_date from 2 orders before. If we had used an offset of 3, it would have returned the order_date from 3 orders before....and so on.


If we wanted only the orders for a given product_id, we could run the following SQL statement:

select product_id, order_date,
lag (order_date,1) over (ORDER BY order_date) AS prev_order_date
from orders
where product_id = 2000;

It would return the following result:

PRODUCT_ID ORDER_DATE PREV_ORDER_DATE
2000 26/09/2007
2000 28/09/2007 26/09/2007
2000 29/09/2007 28/09/2007

In this example, it returned the previous order_date for product_id = 2000 and ignored all other orders.

Azure OpenAI Architecture Patterns & Deployment Patterns

Sharing some useful links that will help customers architect Azure OpenAI solution using the best practices: (1) Azure OpenAI Landing Zone r...