Wednesday, December 29, 2010

Ubuntu 10.04 laptop experience

In short, it's great OS for home use. However, it's lack of driver or software support for lastest external peripheral. In other word, software written by hardware vendor are mostly for Windows but not for Linux. For example, Creative or Asus external soundcard/headphone that comes with software and driver are only for Windows. This is why I want to keep Windows XP and run Ubuntu along side using Wubi.

Below is the list of point where you might want to consider using Ubuntu 10.04 as part of day-2-day, especially you're a Windows XP user.

1. It boots/shutdown faster than Window Xp - My wifi start connected almost instantly after log in and I can start surfing right away. While XP needs to wait for all the service to load up (antivirus, firewall, intel wifi, etc). The same goes for shutting down.

2. Chrome (Chromium), Firefox, Adobe Flash player is in the Ubuntu software center. Therefore, there's no need to search around in the Internet for software. This also raised a good point on the software center feature where you have less chance to download malicious software that harm your computer. However, in XP, there is always a need to search on the Internet for software.

3. Media plays well. VLC media player works well for both video (plus subtitle) and audio. Rhythmbox also plays well for audio but not my preferred choice. Anyway, I still like Winamp in Windows because of the interface and feature (the classic one, simple and easy). Unfortunately, they don't create a version for Ubuntu.

4. Office application comes free and works well too. Open office(for word/office document), Tomboy (for taking note, works better if setting the shortcut for open and edit note), Goldendict (dictionary software that works much better than the Ubuntu default, however dictionary file does not come free), Abiword (for simple text edit with spell check). They all comes free and easy to find in software center.

5. File sharing client (Vuse) for download is my preferred choice for managing torrent download. If you're using Vuse in Windows and probably you can do the same in Ubuntu. There are slight user interface changed between the two but they all perform the same.

6. Bluetooth support (bonus point). My bluetooth headphone works well with Ubuntu. It just the bluetooth USB dongle was unstable. I switched to Windows to test it out (This is why I want to keep XP) and same thing happened (Service not found, sometime worked sometime doesnt')

The list above are the features I used most for my day-2-day and I find Ubuntu 10.04 is easily to use and help me to perform my task. Beside that, I hope the vendor keeps release driver support for Window XP instead just Windows Vista/7, therefore I don't need to spend a dime to upgrade XP and still able to enjoy those computer peripheral (e.g. mp3 player, webcam, etc).

Wednesday, December 15, 2010

Ubuntu Netbook 10.10 on Samsung NF310 experience

Ubuntu Netbook 10.10 is slow on Samsung NF310 netbook. My advise is not to install it at this point of time until a better release or driver support (wifi not working on start). I have spent some time (including downloading the ISO) to get it install from USB stick using Wubi (install Ubuntu in windows 7 starter and skip the disk partition process) but faced a lot of problems.

First, Wubi keeps downloading the disk ISO file when installing although I already have the file. Later, I found out that the ISO file has to keep together with wubi in the same folder in order to skip the download.

After that, wubi skip the windows installation and only allow for live cd or full installation. Then, I found out is the USB stick that make it behave this way. So, I copied the files to the windows local disk and run it again.

Next, I forgot the desktop environment has to be Ubuntu Netbook. This caused Wubi keeps trying to download the desktop AMD 64bit version. A quick search on the internet, I found a guide from how-to geek website and follow the steps from there.

Finally, I got it installed but just to found out that:

1. The user interface experience is so slow. Switching menu and open application is slow. Wifi is not working until I need a LAN cable to get the latest driver update from internet (It's the same experience when I started out using Ubuntu version 8.04 and it's a nightmare). Then later, my keyboard is not working at all and I couldn't type anything (only my touchpad is working). Function keys are not working also and this including adjusting the screen brightness
2. The good side is, I like the new menu, side bar and the search application function. The menu and windows effects are nice but it was slow to really enjoy it.

Later, I got it uninstall from my machine and went back to windows 7 starter. Nevertheless, it's a good start from Ubuntu to have a Netbook version and probably they will have a great release before windows 7 starter support ends. Until then, my advise is to wait for another one or two release before try again.

Friday, December 10, 2010

Potential problem by storing number into varchar/string field

The analyst came out a specification document and wanted to store a list of master data into a permanent temporary table and then use it to generate a report. The temp table structure already there and used by others. Thus, no change on data type on each of the fields. In the end, the analyst end up has to store number into varchar field.

But there is an potential problem:

1. Numerical setting. The number store in the varchar field in this format 0.00; however there is possibility the server setting for decimal as 0,00 (in Europe). Therefore, when converting the varchar (which the number is stored) to numerical using TO_NUMBER (for calculation), the sql will failed due the system unable to recognize the decimal.

2. A non numerical value can be store in the same field, which leads potential problem/issue raised in future. (e.g. TO_NUMBER failed again)

In short,  store only number to number fields. If not, make sure NO non numerical data and number store in the same field. Or converter the non numerical to some numbers for representation. Example, blank string stored as 0.

Wednesday, November 24, 2010

Shift the condition to fields

The report needs to sum() fields in opposite condition. Example: sum(salary) where employee id > 500 and sum(salary) where employee id <=500. Below is how the example report looked like.

Department, Total salary where id > 500; Total salary where id <= 500
Account, 10000, 20000
IT, 20000, 10000

Usually, we would go for sub-query to solve the above problem such as (or putting the sub-query in the FROM clause and use a join):

SELECT emp.dept, (SELECT SUM(emp1.salary) FROM emp1 WHERE emp1.id > 500 AND emp1.dept = emp.dept), (SELECT SUM(emp2.salary) FROM emp2 WHERE emp2.id >= 500 AND emp2.dept = emp.dept)
FROM emp GROUP BY dept

Now, there is another way to generate the same result without using sub-query by using decode (matching character condition) or case (true or false condition)

SELECT emp.dept, SUM(CASE WHEN emp.id > 500 THEN emp.salary ELSE 0 END), SUM(CASE WHEN emp.id<=500 THEN emp.salary ELSE 0 END)
FROM emp GROUP BY dept

So, the sum will only do its work when the case condition is true and thus, eliminate the need sub-query. The performance are better using this way and reduce the cost for additional table access.

Off topic: Writing using cellphone and bluetooth

I just found out that I can blog by using my crappy cellphone with bluetooth. All I need just write the stuff in Notes app in cellphone and push the text to laptop using bluetooth. It worked marvelously and surely will help me to keep up the posting.

I was thinking of getting a PMP  (portable media player)  (so it comes with appropriate keyboard instead of my 12 keypad to do all my typing) to do my blogging and capture ideas wherever I am. So far the list I found are Archos 43, Ipod Touch, Creative Zen Touch 2.

Tech stuff changes all the time. I will see how far I can get with 12 keypad typing until I got fed up. :P

SQL: Identify day of the week

Select to_char(sysdate, 'DY', 'NLS_DATE_LANGUAGE = AMERICAN') from dual

Due to different server in different region has different setting for first day of the week, this can become tricky when we try to identify, lets say Wed, using numerical format. By nailing down the date languaga as American and format as DY, this way we can sure the result returned WED is surely Wednesday no matter where the server or what the setting is.

Monday, November 22, 2010

Off topic: Mencoder subtitle not working in Ubuntu

I was doing some video converting for my tiny little mp4 player and some of the subtitle worked, some do not. This got me curious because on the the video I'm looking forward to convert has a subtitle file that does not work in mencoder. I knew it was the character encoding on the file but I'm just too lazy to use some application just to convert the file although all are in English. Fortunately, I found a trick to get rid of the character encoding app by using the step below.

1. Create an empty file in the same folder of the subtitle.
2. Edit the "problematic" subtitle using gedit. Select all and copy.
3. Edit the empty file using gedit and paste the subtitle content.
4. Re-start the conversion again.

It worked.

I guess the same trick also work for other character conversion purposes minus the hassle to get a conversion app (e.g. iconv)

P.S. Subtitle overlapping at blank area? Try using -subpos to position the subtitle in the picture frame. This will get rid of the overlapping issue. It doesn't looked nice but at least the subtitle can be read.

Sunday, October 3, 2010

More SQL pieces

1. Sum over partition by columns - to have a column that sum all the value from field in the result.
Example:
ID Amount Total by ID
1   100         300
1   200         300
3   500         500

Select ID, Amount, Sum Over (Partition by ID) "Total by ID" from Table_Amt

Without this tip, usually we will go for sub query to generate the Total by ID. This trick has really help to cut down lines of codes in sub query with just couple of words.

2. NULLIF to avoid divide by zero error - This function will return NULL if the parameter passed in are matched with argument. Below is an example how it is done to avoid divide by zero error.
Example:
Select 100 / NULLIF(Amount, 0) from Table_Amt
Result: NULL if Amount is 0

However, there is a another way to do the same is by using decode.
Example:
Select Decode(Amount, 0, 0, 100/Amount) from Table_Amt.
Result: 0 if amount is 0.

Which one is better? Honestly, I think the decode is much better by returning 0 instead of NULL.

Sunday, September 12, 2010

Some oracle sql pieces

1. XMLElement - set long to higher value to avoid xml string to be truncated (e.g. set long 32767).
Last week in my training, I was doing an exercise involved using XMLElement to generate xml file using XMLElement. My XML string result is always truncated to certain length and after a long search on the internet, it seems that Long parameter need to be set higher in the session.

2. Ora-01821: date format not recognized - check whether the O is set to zero
It took me an hour to find out that the date format was set to DD-M0N-YYYY. First glance seems nothing wrong but after careful examine, the M0N is actually MzeroN. If you have the same oracle error, better check on the O whether they are set to zero. The correct format should be DD-MON-YYYY.

3. Generate rows using "connect by level"
For all these years in sql programming, I have never tried to generate rows using SQL. After some search on the internet, "connect by level" was actually used to generate calender table. Yup, making a calender out of nothing. Example of using "connect by level" on creating 10 rows from 1 to 10:
Select rownum from dual connect by lever <=10

Saturday, August 28, 2010

Sub Query

How to write a query when different logic is used for a single row? Use sub query. Example problem by using employees and deparment table in Oracle:

Objective
Sum the salary for each department for old and new staff

Field names and logics in the extraction
Department Name, if (hire_date after 01-Jan-1995 as new_staff) then sum of employee's salary else null, if (hire_date before 01-Jan-1995 as old_staff) then sum of employee's salary else null.

The first thing we notice is that we can't put the date 01-Jan-1995 condition in the where clause because the condition covers all hire date. So, the sub query comes in.

click on image for larger view

In other point of view, if department name can have duplicate OR new_staff and old_staff salary should not be in the same row, below is another sample sub query.

click on image for larger view

In conclusion, sub query is handy but sometimes it might get complex. In some slight different scenario (although they looked similar as above example), we may end up using almost complete different query.

Tuesday, August 17, 2010

Oracle Decode VS Case (Date result)

What's the difference between these 2 queries?
--#1---------------------------------------------------
SELECT TO_CHAR (DECODE (TRUNC (SYSDATE),
TO_DATE ('01012010', 'DDMMYYYY'), NULL,
TRUNC (SYSDATE)
),
'DD/MM/YYYYY'
)
FROM DUAL;

--#2---------------------------------------------------
SELECT TO_CHAR (CASE TRUNC (SYSDATE)
WHEN TO_DATE ('01012010', 'DDMMYYYY')
THEN NULL
ELSE TRUNC (SYSDATE)
END,
'DD/MM/YYYY'
)
FROM DUAL;

Both are SQL "grammar" are correct but one worked, one doesn't. The #1 query has failed with error "ORA-01722: invalid number" but second worked fine. I was scratching my head as both DECODE and CASE return the same value of TRUNC(SYSDATE), however DECODE has failed when convert to char.

Why?

Reformat the query to only DECODE and CASE gave me the result below:
--#1---------------------------------------------------
SELECT DECODE (TRUNC (SYSDATE),
TO_DATE ('01012010', 'DDMMYYYY'), NULL,
TRUNC (SYSDATE)
)
FROM DUAL;

Result: 17-AUG-10 (using TOAD statement execution)

--#2---------------------------------------------------
SELECT CASE TRUNC (SYSDATE)
WHEN TO_DATE ('01012010', 'DDMMYYYY')
THEN NULL
ELSE TRUNC (SYSDATE)
END
FROM DUAL;

Result: 8-17-10 (using TOAD statement execution)

From here, the to_char has failed due to unable to format the non-date result returned from decode (probably, according to my opinion). The question is:
  1. Is this a bug? Seriously, I think it is.
  2. Which is the correct result? The correct result should be #2 because the same result return if I run this query: select trunc(sysdate) from dual;
  3. How to fix the DECODE beside using CASE? Use TO_DATE function on top of DECODE.
SELECT TO_CHAR (TO_DATE (DECODE (TRUNC (SYSDATE), TO_DATE ('01012010', 'DDMMYYYY'), NULL, TRUNC (SYSDATE) ) ), 'DD/MM/YYYYY' ) FROM DUAL;

In conclusion, use case for better date result and readability.

Monday, August 9, 2010

SQL Best Practice Video

Although I'm a developer, I recommend the SQL videos below for those who interested in SQL best practice and performance tuning. It fun to watch the author present the real world problem in a interesting way. :D





Tuesday, July 27, 2010

How to identify good, experience senior colleague

If you are a junior or just join a company, I hope this article may help you to identify which senior/experience colleague you should be working with.
  1. When you talk about your work with them, they become energetic and have enthusiasm on the discussion. You can see sparkle in their eyes.
  2. When you ask something from them, example: better ways of coding, they can provide a lot of inputs, solutions and even recommendations. They willing to share their years of experience.
  3. Based on the 2 points above, they are easy approachable, which means they are very welcome on any question you ask. They are open and accept to different opinions.
  4. They apologize on their mistake because they knows human does make mistake and they know they're human. :)
  5. They take responsibility on your mistake, which make them a team player.
  6. They are great communicator. They will find out the root cause of the mistake instead of playing the blame game. They able to provide the solution to avoid the mistake from happening again.
  7. They will only give work that is within your responsibility. They are very clear what is the scope of your work. Furthermore, they keeping track and following up every work they have given to you.
Finally, a good experience senior colleague is just only a human. They may not have all the points I have listed above. However, if you find that a senior that not even fit one of the traits above, it is better you find another one to work with.

Wednesday, July 21, 2010

Tweet 21/07/2010

It's those hours again. Working on rotation from 1 am till 10 am and this going to last for a week. I just finished taking my breakfast and crawling back to bed soon.

Thursday, July 15, 2010

Minus will not work for 3 or more sets.

I was doing a table column comparison at work today using minus sql and somehow, the result returned is not as expected. Look at the sample query below:

select 'abc', '123', '!@#' from dual
minus
select '123', '!@#', 'abc' from dual
minus
select 'abc', '123', '!@#' from dual;

Well, the expected result for query above should be return row highlighted in BOLD (minus set should return row that is no match is found). However, the actual result is no rows returned. What happened?

To investigate, I separate the query as follows:

select 'abc', '123', '!@#' from dual
minus
select '123', '!@#', 'abc' from dual

The return result is: abc 123 !@#

Surprisingly, only the first record is returned but what about the second record? I have no idea. Nevertheless, this is where I believe why the second minus comparison return no row as the above result is then past into second minus comparison, which both are the same (my assumption).

So how do we solve the above scenario? Make the minus comparison exclusive to only 2 tables and union to join them together.

select 'abc', '123', '!@#' from dual
minus
select '123', '!@#', 'abc' from dual
union
select '123', '!@#', 'abc' from dual
minus
select 'abc', '123', '!@#' from dual


Result: 123 !@# abc
This time the result return correctly. 

Tuesday, July 6, 2010

I won a book from plsql challenge

It's a 50 USD O'Reilly Media ebook of my choice. Since I have the print version of "PL SQL Best Practice" and "PL SQL Pocket Reference", so I got myself a "Head First Data Analysis" from O'Reilly. (By the way, I'm changing to a new job next month and required some data analysis with PL SQL. This new book is a great addition to my new career.)

Take the PL SQL Challenge plsqlchallenge.com today and win some cool stuff. :D

Wednesday, May 19, 2010

Take the plsql challenge

Well, I didn't know that learning a programming language can have the chance to win prizes at the same time. Here's your chance.

plsqlchallenge.com

Don't forget the time is ticking while you're checking/debuging the question in your editor. :P

Tuesday, May 18, 2010

Content matters than technology

I was in the train this morning and I saw a guy with his Iphone. I had a peek to his Iphone to see what he's doing with it and he was searching for his songs. Meanwhile, in my hand, I had a Nintendo DS with a training video about writing (my writing need some improvement). It came to my thought that, the guy's song can be played in my device and vice versa. Subsequently, I remember there one saying in one of the programming book I have read, "content stays, technology moves on".

For example, my name will not change as often as technology. In other words, it can be stored in different types of database and using different types of programming languages. The name will stays until I die; but technology might change to a new level. This leads me thinking about my career, whether I should stick to a programming of particular technology or move to business/functional side. Well, business process wouldn't change as often as technology and it doesn't pay lesser than technical people. Perhaps it's the thought of doing a easier job and getting the same pay?

Imagine after 10 years, will the song and training video be different? It's a dumb question but I'm sure my Nintendo DS and the guy's Iphone will be obsolete.

Saturday, May 1, 2010

Char is not equal to String

Duh! Everybody knows that.

There was bug and it was caused by the above char not equal string(varchar2) logic. Why it is still happening since everybody knows that?

The variable constants was a string 'Employee' and the database field value that suppose to match this constant also show 'Employee'. However, the process logic if-condition has failed. Everybody was scratching head until spaces are found  ('Employee    ') in the database field value.

Ironic isn't it? Looks the same, feels the same but the program has failed because of spaces.

This lesson has brought us to identifiy the when to use the char and string (varchar2). Obviously, the table field shound't be stored as char if it's going to be checked every where in the progarm. As we know, some developer are not going to trim the value before writing the if-condition check.That will cause a lot of maintenance work to replace everyone of the them, where the field is used.

In short, identify the field behaviour and use to the correct data type. Use the wrong type and bugs will be crawling all over the place.

Sunday, April 18, 2010

19 hours

Maybe I come out a drama series called 19hours with a producer about a programmer working 19hours non-stop to get the migration project go live.

It will be a true story.

Yes, I've worked from 0900 till 0400. Is the clock running backwards? Nope.

What I can recall now on that moment was like, we in war. Phone kept ringing and people walking around faster than usual (minus the shouting and gun pointing). Things and instruction steps got messed up. The rehearsal we've gone through before the go-live and the real go-live itself was having too many environment changes.
  1. Our user privilege were not there. We can't update the setting unless we call the DBA for help. 
  2. New data or non related to migration causing interruption. Client can do whatever they want. (On migration go-live? Seriously, what are they thinking?)
  3. Plan/Instruction steps were jumble up. Due to point 2.
Now I'm here, back to the office 10 am in the morning (4 hours sleep). I hope the nightmare is over.

Update: I'm totally defeated when I heard one of my colleague only slept one hour. Not a good sign for the project and I hope this doesn't affect her health.

Friday, April 16, 2010

Password character gone overboard

Try use the "@" in for oracle user password. I got mine thru a password generator and it was fine when I log in using sql developer. Until I try to login sqlplus using command below:

sqlplus> username/password@server


Notice the @ after the password. If my password has a @ (and it was), the login will failed.

In short, don't use a @ for oracle password.

Tuesday, April 13, 2010

Bad health leads to bad programming.

I'm having a bad cough recently and very thing I think is negative. It's affecting my life and my work (maybe I couldn't think straight). Until I finally decided to go see a doctor and get my cough fixed, every thing seems much more positive afterwards. My work and relationship with family and work colleague seems to be improved.

I find that hard to believe. Supersititious? It's science.

Tuesday, April 6, 2010

Conventional bug issue

"The new customization will update this table. However, this has caused a new bug where the new value unable to fit to the field length or this new customization has affected other module".

What are we missing here? Where is the business logic validation? Why the customization are doing direct table insert/update?

I happened to meet one person who said the above and I took me an hour (better late than never) to realize their system is really screwed up.

Wednesday, March 24, 2010

Two types of communication

I had a chat with my wife this morning and started to reflect myself whether that I have communication issue. After some thinking, I came to this thought that communication has 2 types, in my opinion.

The first type I realized is the active approach. It's simple. I say what I wanted to someone in terms of information or needs. I like this approach as this allows me to be in control and be very clear what I'm doing. Even the coming next task, I will somehow have them in mind and brought them up in any possible chance for discussion/next action steps.

The second type is the passive approach. This type is someone has given me only a general idea and I need to go for them to pull out more information. Therefore their statement sometimes is vague and easy to fall into misunderstanding. This approach also makes their task easy as they words can be one line statement and I need to generate several pages of document just to based on that.

Furthermore, if I'm lucky, I get the precise information that I need. If not, the discussion will keep on going until the fog is clear. Don't forget that although I have the "stamina" to keep the discussion on going, but it may not applies to the other party. This will somehow leads the other party to think I'm have some problem on communication (perhaps I'm). But mind you, I have seen Project Manage spent hours just to get a point straight.

In short, spend all the time I need to get things clear as crystal. Be the active person. It will save a lot of time and fustration down the road.

Update:  Today evening, I feel I have found my "mind freedom". I was a active approach communicator and I was expecting the same from others. This mind set has made me looked like an idiot because the fact is, that expectation is not going to happened. This mind block has been released and the burden of communication breakdown is let go. Althought it's tiring to hunt down every detail information (from those who involved), but it is much better to carry the doubt and uncertainty back home.

Last but no least, thanks to my wife for pointing that out for me.

Monday, March 8, 2010

Thought of moving out of (dis)comfort zone.

The culprit that causing me to have this thought is: senior programmer wrote code that's lame.

No matter how marvel that my code is, the bug comes from the library/standard that my code depends on, wrote by some senior programmer that does not test their work. It ends up blocking my code to work as expected.

I have gone tired and frustrated with this culture (i think it's quite common in the programming world) as the lower level staff have to pick up their senior's mistake and sort out the issue. Adding salt to the injury, code written by the senior wasn't easy to maintain or read, causing the effort to understand and correct the bug takes days to resolve.

One might ask, what are those senior are doing then? They have so many issues pending on them due to their untested work, they don't even have time to solve the bug that's concern to me but not for them. This lead to work and stress start to pile up, not to mention what's the next time bomb (serious bug waiting to be discovered) will be.

Maybe it's time to move on and out of area that I have familiar with for 8 years. Maybe it's time work some thing that's new to me. I thought of venturing into Business Analyst. Time will tell.

Update: Change title to possible of discomfort zone.

Sunday, February 21, 2010

Where is software transparency?

Me: "Err, what this table do? "
B: "This table stored the configuration for the XXX process."

Me: "Where can I find it on the user interface?"
B: "There is no interface for it."

Me: "How user is going to change it or know what are the current configuration setting for the XXX process?"
B: "They wouldn't know because we going to use script, created by us, to update the table."

Me thinks: "No wonder user is keep logging bug report issue as they have no idea what to expect without knowing what are the configuration."

Is this the real world of software development? In my opinion, this is kinda lame.

Friday, January 29, 2010

Monday, January 11, 2010

Why programming code can't be represent like word document?

I want to have my PL/SQL souce code to have different font, size, color, bold and italic. So far I can't do that in PL/SQL Developer and I'm not sure about other language can do that either.

Why?

If you're a IDE/source code editor programmer, put this feature into your enhancement list and I'm sure programmers will love this feature, starting from me.