Moving to my own domain Monday, Jun 1 2009 

Hi..

After long time didn’t update my blog I decide to buy a domain name & move this blog to the new domain.

Please post comment at that new blog. (http://jimmod.com/blog/)

Thanks

Displaying row number (rownum) in MySQL Tuesday, Sep 9 2008 

I move the blog to my new domain, please visit : http://jimmod.com/blog/2008/09/displaying-row-number-rownum-in-mysql/ for latest update

Sometimes you need to do query with MySQL for reporting.
And you’ll need to display the row number/ranking in query result.

Example you have this table:

table : player
fields : playerid, name & score

For reporting purpose you need to query the top 10 (highest score).
The result should be : rank, memberid, name, score.
Example :
rank playerid name score
———————————–
1 A1029 Jimmy 100
2 A9830 Lia 98
3 B28d0 Lulu 90


10 B8789 Lele 50

Now you can easily query the top 10 by using ‘limit’ and ‘order by’, but how to automatically add row number in query result?

Here’s how you do it:

select @rownum:=@rownum+1 ‘rank’, p.* from player p, (SELECT @rownum:=0) r order by score desc limit 10;

Try it🙂

This will create a variable rownum, initialize with value 0 & increase it by 1 for every record
Technorati Tags: , , , , ,

Unknown winmail.dat attachment in email Tuesday, Jul 29 2008 

From my colleague I received an email but with unknown type : winmail.dat
He should send me office document.
I asked him to sent it again, he forwarded the email again but I still received winmail.dat in attachment.

After googling about this I found out that winmail.dat is generated by Outlook (I using thunderbird).
From About.com :

It’s Outlook’s fault, in a way. Or the recipient’s email client’s. If Outlook sends a message using the RTF format (which is not very common outside Outlook) for bold text and other text enhancements, it includes the formatting commands in the winmail.dat file. Receiving email clients that do not understand the code therein display it as a stale attachment. To make matters worse, Outlook may also pack other, regular file attachments in the winmail.dat file.

Fortunately, you can get rid of winmail.dat altogether by making sure Outlook does not even try to send mail using RTF.

And there’s also a way to disable this feature on Outlook. You can open it for more detail.
I would focus on how non-Outlook user can handle this format.
I know I can not ask all Outlook user who sent me attachment to turn off this feature.

So I search a program to open this content type “application/ms-tnef”.
I encounter this good console program : WMdecode
You just need to extract this. When running the program it’ll search winmail.dat in current folder and extract it.
The program working great although it just console application, no GUI.

Other tool I search is add on for Thunderbird.
I found : LookOut
This add on will automatically decode the winmail.dat
Also working great but it won’t decode winmail.dat in emails that you received before installing the add-on.
So I think it’ll only decode winmail.dat on new email received.

Cheers🙂

Java Application – Make sure only single/one instance running – with File Lock and ShutdownHook Monday, Jul 21 2008 

Often we want to make sure that only 1 instance our application running.
Because something terrible could happen when more than 1 instance running (for example the whole server would exploded and that would make you fired😉 )

Nevertheless what the reason, one of the way to make this happen is by creating a lock file as a sign that an instance is currently running.
So you application will have this flow:

  1. Check if the lock file exists.
  2. Try to delete the lock file to check if there’s really a running process lock the file.
  3. Get the file lock.
  4. If failed to get the lock file, show error that there’s already an instance running –> the end
  5. If successfully get the lock then go on with your application want to do.
  6. When application ended/closed release the lock and delete the file lock.

package test.jimmy.filelock;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.nio.channels.FileLock;

public class MyApp {

    private static File f;
    private static FileChannel channel;
    private static FileLock lock;

    public static void main(String[] args) {
        try {
            f = new File("RingOnRequest.lock");
            // Check if the lock exist
            if (f.exists()) {
                // if exist try to delete it
                f.delete();
            }
            // Try to get the lock
            channel = new RandomAccessFile(f, "rw").getChannel();
            lock = channel.tryLock();
            if(lock == null)
            {
                // File is lock by other application
                channel.close();
                throw new RuntimeException("Only 1 instance of MyApp can run.");
            }
            // Add shutdown hook to release lock when application shutdown
            ShutdownHook shutdownHook = new ShutdownHook();
            Runtime.getRuntime().addShutdownHook(shutdownHook);

            //Your application tasks here..
            System.out.println("Running");
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
        catch(IOException e)
        {
            throw new RuntimeException("Could not start process.", e);
        }

    }

    public static void unlockFile() {
        // release and delete file lock
        try {
            if(lock != null) {
                lock.release();
                channel.close();
                f.delete();
            }
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    static class ShutdownHook extends Thread {

        public void run() {
            unlockFile();
        }
    }

}

Technorati Tags: , , , , , ,

Lelucon dengan google tentang Roy Suryo & Penjelasan caranya Tuesday, Jun 3 2008 

Ternyata terdapat lelucon tentang Roy Suryo di google.
Mau coba ?🙂

  1. Buka halaman web http://www.google.co.id
  2. Ketikan pada textfield pencarian (tanpa kutip) : ‘Temukan Roy Suryo’
  3. Lalu klik pada tombol ‘Saya Lagi Beruntung’
  4. Maka hasilnya :

Lucu juga ya

Silahkan dicoba😉

*UPDATED*

Setelah saya perhatikan ternyata lelucon ini bukan dari google, ternyata ada orang iseng membuat webpage http://temukanroysuryo.co.cc/. Nah website tersebut dibuat mirip seperti layar hasil search Google, sehingga seakan-akan layar tersebut milik google. Padahal bila kita lihat pada address website tertulis http://temukanroysuryo.co.cc/.

Cara kerja tombol ‘Saya sedang Beruntung’ adalah langsung membuka website teratas dari hasil search Google. Dan website tsb saat ini merupakan website paling atas dalam search kalimat ‘Temukan Roy Suryo’, pembuat lelucon ini memanfaatkan fitur ‘Saya Sedang Beruntung’ google.

Menurut saya sang pembuat lelucon : iseng & kreatif😀

Microsoft + Yahoo = ? Tuesday, Feb 5 2008 

Microsoft planning to buy Yahoo for $44.6 billion. Until now Yahoo hasn’t give final answer it.
I’m wondering why do Microsoft want to buy Yahoo, is it for fighting Google?
Or Microsoft just want to kill one of his  rival.

Let’s see
IM : Microsoft has Windows Live Messenger, Yahoo has Yahoo Messenger.
Search Engine : Microsoft has Live Search, Yahoo has it’s own search engine.
Email : Microsoft has Windows Live Hotmail, Yahoo has Yahoo Mail.

Let’s wait for Yahoo’s final answer.
And how will Google respond about this🙂

Menganalisa Promo XL Bebas Rp. 0,1/detik untuk Jakarta Monday, Jan 21 2008 

Tanggal 18 Januari 2008 – 30 April 2008 XL mengadakan promo Rp. 0,1/detik.
Peperangan harga diantara operator GSM semakin menjadi-jadi, sayangnya para operator kerap menggunakan iklan-iklan yang dapat membuat masyarakat salah kira.
Saya membahas XL Bebas karena saya sendiri mantan pengguna XL Bebas dan banyak orang-orang yang dekat dengan saya menggunakannya, sehingga membuat saya tertarik untuk mengetahui biaya sebenarnya dari penggunaan kartu XL Bebas.

XL membuat promo Rp. 0,1/detik dengan tambahan bahwa promo ini hanya berlaku pada “menit tertentu”, dan detail mengenai hal ini dapat dilihat pada website XL.
Promo Rp 0.1/detik XL Bebas (Jakarta)

Gambar diatas diambil dari website XL, mengenai promo di Jakarta dan kota-kota lain (bisa lihat sendiri pada gambar).
Dengan bantuan Microsoft Excel (yang tentu saja produk Microsoft bukan Excelcomindo, walaupun namanya mirip :p – juga bukan produk hasil kerjasama Microsoft & Excelcomindo he3)

Perhitungan Biaya dalam Promo XL Bebas Rp 0,1/detik

Kesimpulan:

Dapat dilihat bahwa penggunaan kepada sesama XL jauh lebih murah dibandingkan menelpon ke operator lain.
Bila berencana menelepon sesama XL selama 1 Jam, lebih baik dilakukan 2 x 30 menit dibandingkan langsung 60 menit. Tetapi bila hanya <55 menit lebih baik langsung tanpa dibagi per 30 menit.

Menelepon ke operator lain tetap mahal dengan 20rb untuk 30 menit, tarif 25/detik masih terasa mahal sekali dibandingkan dengan tarif sesama XL.

NB: Perhitungan diatas tidak terjamin keakuratannya, silahkan coba hitung sendiri🙂. Saya tidak ‘affiliate’ dengan Excelcomindo ataupun Microsoft :p, dan semua informasi pada artikel ini dapat digunakan dengan tanggung jawab masing masing (masa tanggung jawabnya ke orang laen he3)

Mencoba paket data Xplore Monday, Dec 31 2007 

Setelah mendaftarkan diri pada paket mega data Xplore (250Mb : Rp. 99,000 + pajak) tentu yang membuat penasaran adalah kecepatannya.
Oleh karena itu maka saya langsung menuju http://www.speedtest.net/ untuk mengetest.
Test 1, koneksi ke server di Indonesia (Jakarta):

  • Ping : 323 ms
  • Download : 197 kb/s
  • Upload : 28 kb/s

Test 2, koneksi ke server di Singapore:

  • Ping : 772 ms
  • Download : 351 kb/s
  • Upload : 20 kb/s

Yang membingungkan kenapa test download ke Singapore (351 kbps) lebih cepat dari pada Jakarta (197 kbps) ?
Dan kenapa ping ke server Jakarta sangat lama (323 ms)?

Pengalaman pemakaian selama beberapa hari (dengan ponsel k800i sebagai modem) :

  • Browsing : kecepatan cukup cepat, dan nyaman. Walau tidak termasuk sangat cepat.
  • Download file : mencoba download file dari website luar, kecepatan : 20 – 25 kilobytes/s
  • Game online Counter Strike, wcg server indonesia (csx.vivagamers.com:2701x) : ping terlalu tinggi (>150) lag dan akhirnya di kick dari server.

Untuk hasil test download ke Singapore yang tinggi (351 kbps) mungkin karena XL bekerja sama dengan SingTel di Singapore.
Dari mencoba melakukan tracert ke yahoo.com, terlihat dari server Excelcomindo di Indonesia di lanjutkan ke server SingTel di Singapore.

Maka perlu di coba melakukan test ke negara lain.
Test 3, Server Australia (Sydney) :

  • Ping : 403 ms
  • Download : 379 kb/s
  • Upload : 19 kb/s

Hasil ini semakin membingungkan, kenapa test ke server di Indonesia juga lebih kecil dari ke Sydney?
Kalo begitu kita test ke server Indonesia di kota lain.

Test 4, Server Indonesia (Surabaya) :

  • Ping : 241 ms
  • Download : 379 kb/s
  • Upload : 47 kb/s

Lebih cepat dari Jakarta. Ada apa dengan server di Jakarta, atau speedtest.net kurang akurat dalam melakukan test kecepatan internet dari XL ini.
Mencoba lagi test ke Server Jakarta, hasilnya tetap sama (download dikisaran 19x kbps).

Saat ini baru test-test ini yang sudah dilakukan, mungkin kesempatan lain bisa di test di web lain atau dengan cara lain supaya bisa menyimpulkan kualitas paket data Xplore ini.

NetBeans 6 T-shirt Friday, Dec 28 2007 

NetBeans 6 T-shirt (front)NetBeans 6 T-shirt (back)

After waiting for 16 days finally the NetBeans T-shirt arrived.
They sent me this t-shirt because my participation in NetBeans Community Docs program although I only contribute 1 article (this) :p

Thanks to Sun and James Branam (NetBeans Community Docs Manager) for this cool t-shirt😉
It’s a great pleasure to be part of the NetBeans community & I would love to contribute more.

Using mock object with jmock 2 Wednesday, Dec 26 2007 

Okay, finally you decide it’s time to create a unit testing for your project (after a long ad hoc programming life :p).
When you create a sample unit testing, it’s all seem so simple.. you fascinate by the junit easiness, how it can do reflection and make it simple.

When you want to create a real unit testing for your project, you realize that a ‘real’ method is not like just adding 2 int argument and return a result. It’s more complex and using interface as parameter is common…
Now a thought cross your mind “do I have to create all stupid classes to implement all the interface I need?”, you starting to think that creating unit testing is really waste of time & you don’t want to do it anymore :p

It’s time mock object framework come to rescue… before you fall to the darkness of untested code🙂
There’re several mock object framework like jMock, easymock, etc

Here’s an example creatin HttpMethod mock-object with jMock 2 & JUnit 3

public class sampleJMockTest extends MockObjectTestCase {
  public void testCreateHTTPMethod() {
    final HttpMethod httpMethod = mock(HttpMethod.class);
    checking(new Expectations() {
    {
      allowing(httpMethod).getResponseBodyAsString();
      will(returnValue("sample response"));
    }
    });
    SomeObject someObject = new SomeObject();
    someObject.someMethod(httpMethod);
  }
}

This sample will create an instance of HttpMethod (which is an interface) and when this mock object’s ‘getResponseBodyAsString’ method called it’ll return “sample response”.
So now we can easily create all interface implementation we need.Of course there’re more in jMock than just this simple feature, check it more at jMock Cookbook

Next Page »

Follow

Get every new post delivered to your Inbox.