Removing numbers from a string

•July 17, 2008 • Leave a Comment

select translate(<column>,
         'ABCDEFGHIJKLMNOPQRSTUVWXY0123456789',
         'ABCDEFGHIJKLMNOPQRSTUVWXYZ') from dual;

My favourite song ever

•May 28, 2008 • Leave a Comment

Kak Ramlah

Ketentuan by Ramlah Ram

Tak semudah kau sangka
Melepaskan kau pergi
Continue reading ‘My favourite song ever’

Our new house is in progress

•May 11, 2008 • Leave a Comment

Just went back from visiting and checking our house progress. So far so good, can’t wait to see the finishing

PHP Parse Error: syntax error, unexpected $end on wordpress

•May 8, 2008 • 1 Comment

You might encounter this error

Parse error: syntax error, unexpected $end in C:\Program Files\Apache Group\Apache2\htdocs\wordpress\wp-content\themes\hemingway\functions.php on line 647

when installing new themes for WordPress. I did encounter this when i have

  • Apache 2.0.63
  • PHP 5.2.6

running on my server.

Continue reading ‘PHP Parse Error: syntax error, unexpected $end on wordpress’

Extracting tar file using JAVA

•May 7, 2008 • Leave a Comment

At last i found a library to untar / tar files using JAVA. Here i provide an example how to use the library. Some of the codes have been taken from other users in forums to enhance the code.

import com.ice.tar.TarInputStream;
import java.io.File;
import java.util.zip.GZIPInputStream;
import com.ice.tar.TarEntry;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.*;
//————–
public void execute() {
TarInputStream tin = null;
try {
tin = new TarInputStream(new GZIPInputStream(new
FileInputStream(new File(tf.getTarFileName()))));
TarEntry tarEntry = tin.getNextEntry();
while (tarEntry != null) {
File destPath = new File( +
File.separatorChar +
tarEntry.getName());

if (!tarEntry.isDirectory()) {
// start of new code
String pathStr = destPath.getPath();
int idx = pathStr.lastIndexOf(File.separatorChar);
if (idx > 0) {
File destDir = new File(pathStr.substring(0, idx));
destDir.mkdirs();
}
// end of new code
FileOutputStream fout = new FileOutputStream(destPath);
tin.copyEntryContents(fout);
fout.close();
}
else {
destPath.mkdir();
}
tarEntry = tin.getNextEntry();
}
tin.close();
}
catch (IOException ex) {
ex.printStackTrace();
}
}

Uncompressing a File in the GZIP Format

•May 7, 2008 • Leave a Comment

Basically JDK1.4 has provided a library call java.util.zip for compressing and uncompressing gzip files.

try {
// Open the compressed file
String inFilename = “infile.gz”;
GZIPInputStream in = new GZIPInputStream(new FileInputStream(inFilename));

// Open the output file
String outFilename = “outfile”;
OutputStream out = new FileOutputStream(outFilename);

// Transfer bytes from the compressed file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}

// Close the file and stream
in.close();
out.close();
} catch (IOException e) {
}

Creating a daily backup MySQL database in Windows

•April 4, 2008 • Leave a Comment

You may using Windows as your database server, but don’t know how to backup it, and some of you may use tools. You can actually do it by running this command

“C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump.exe” –host=localhost -uroot -ppassword –opt mydatabase > “C:\helmy\backup\%date:~10,4%_%date:~4,2%_%date:~7,2%_backup.sql”

It will create a file 2008_04_04_backup.sql

If you want to schedule it, put it on a backup_db.bat and ask Windows Task Scheduler to run it

Getting Yesterdays or Tomorrows day with shell date command

•March 7, 2008 • Leave a Comment

Don’t know how to get yesterdays date in linux


$ date –date=’2 year ago’ # past
$ date –date=’3 years’ # go into future
$ date –date=’2 days’ # future
$ date –date=’1 month ago’ # past
$ date –date=’2 months’ # future

Use it in your shell script

Create functions to join and split strings in SQL

•March 2, 2008 • Leave a Comment

Please refer to this article , it is to complex for me to explain back
http://articles.techrepublic.com.com/5100-9592-5259821.html

Another way of manipulating large amount of data in oracle (Remove duplicate)

•January 30, 2008 • Leave a Comment

Below example explains, 1 way to remove duplicate data. tmp_data table contains 6millions of record, but with duplicate. Table tmp_duplicate contains all duplicates data that exists in tmp_data.

create or replace procedure delete_duplicate is

cursor c is select sn from tmp_data a where a.sn in (select sn from tmp_duplicate);

type c1_type is table of c%rowtype;

l_c1 c1_type;

begin

open c;

loop

fetch c bulk collect into l_c1 LIMIT 1000;

for i in 1 .. l_c1.count

loop

–Expecting to do the delete

dbms_output.put_line(‘Delete this ‘ || l_c1(i).sn);

end loop;

dbms_output.put_line(‘———————-’);

exit when c%notfound;

end loop;

close c;

end delete_duplicate;