Saturday, April 11, 2009

Learning Scala 1 : A Hello World

Scala is a powerful and interesting language to learn. Personally, I like it as the next generation of my daily written Java programming language.

To getting started with Scala is easy. Get a Scala distribution from http://www.scala-lang.org and unzip it to, for say C:\scala-2.7.3.final and set C:\scala-2.7.3\bin into your PATH environment variable. It requires Java runtime environment version 1.5 or later installed on your machine, I am having Sun JDK 6 Update 13 installed on my Windows XP machine.

After the above setup, you can start Scala Interpreter by entering 'scala' in command prompt:-


C:\>scala


Alternatively, you can start the Scala Interpreter also by double clicking 'scala.bat' under the 'bin' folder. You should after the Scala Interpreter waiting for your command now:-


scala>


Now, let's type 3 + 5 into it:-


scala> 3 + 5
res0: Int = 8


The 'res0' is a generated name to refer to the calculated value. You can try to print it out by using println():-


scala> println(res0)
8


You can declare 'val' (value) or 'var' (variable) in Scala, 'val' works similar like 'final' in Java, which reassignment is not allowed. You can try reassign the 'res0' to something else and you should get an error:-


scala> res0 = 9
:5: error: reassignment to val
res0 = 9


Now, let's declare a value call 'myValue':-


scala> val myValue = "Hello World"
myValue: java.lang.String = Hello World


You can see that I do not declare any type for myValue, the Scala compiler is smart enough to infer the value type to String, optionally, you can write it in the following way:-


val myValue:String = "Hello World"


Now, let's print it out:-


scala> println(myValue)
Hello World


That's complete my 'Hello World' in Scala!. ;-)

Friday, March 27, 2009

ACE for Flex 3 with AIR Exam Cleared

After a week of intensive reading after working hours, finally I got it through today with 92%. The preparation process was tough for me as the scope seems to be very wide. I studied mainly using the official materials from Adobe, which include:

Adobe Flex 3 Developer Guide
Developing Adobe AIR Applications With Adobe Flex 3
BLAZEDS Developer Guide

I didn't study for ActionScript programming as I am coding it in my daily job. ;-)

Looking forward to have a great weekend, Cheers!

Friday, January 9, 2009

'Work In Progress' Animated GIF Generator

I am looking for an nice icon to indicate 'Work in Progress' GIF today and found a nice site which let you customize and generate 'Work in Progress' animated GIF:-

http://www.ajaxload.info

Customize indicator type, colors and transparency.








Generated GIF with 'Bar' indicator:

Monday, December 22, 2008

Solving Table Name Case Sensitive Problem of Mysql on Linux

Table name case sensitivity issue is a common problem to hit when you are trying to port an application to use Mysql on Linux. You can set the Mysql to always store table name in lower case by setting the startup parameter lower_case_table_names=1.

You can type the following to check if the parameter is set or not:-

mysqladmin -u root -p variables


If it is not set, you can set it by editing /etc/mysql/my.cnf:

sudo gedit /etc/mysql/my.cnf

In my.cnf, it should have portions like this:-

[mysqld]
#
# * Basic Settings
#

#
# * IMPORTANT
# If you make changes to these settings and your system uses apparmor, you may
# also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#

lower_case_table_names=1

user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/english
skip-external-locking


Then, restart the server:-

mysqladmin -u root -p shutdown
sudo mysqld

Thursday, December 18, 2008

Email, How Reliable is it?

Email is one of the most important application in Internet today beside Web. However, it has become a channel where hackers target to steal confidential information such as login info from user. One of the most popular trick is to masquerade and send a fake email, saying the user account is going to expire and ask the user to login with a fake hyperlink, which link to a fake page with similar design to the real login page.

From technical point of view, how easy to send a fake email? The answer to this question is : 'It's very simple'.

You do not need to write a C program, BackTrack 3 or any hacker tool. You can easily do it with high level language such as Java. It depends on how your email provider securing their SMTP server, but in my case, most of the companies that I have worked with is having their SMTP that you can easily send a fake mail.

At very basic level, these few lines of Java code using Spring Framework can masquerade as 'Your Boss' and send out an email to your colleague saying that he is fired:-

JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setHost("mail.yourcompany.com");
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
helper.setFrom("Boss <yourboss@yourcompany.com>");
helper.setTo("your_colleague@yourcompany.com");
helper.setSubject("You're Fired!");
helper.setText("I am very unhappy with your face, you're fired!!!");


You still will be able to find out which machine this email is sent from if you examine the email's properties. We joked with one of our colleague years ago with this. She was stunned and we quickly clarified with her before any bad thing happens next, it is sin. However, this shows that most people 'TRUST' email, and they believe it.

Do you believe your email?

A Little Information About Setting up Streamyx

Depending on the model of your router, here's some tips that can help you to setup your Streamyx connection:-
  • Use 'your_user_id@streamyx' as username
  • Set 'PPPoE' as connection type
  • Set VPI =0 and VCI=35
  • Default DNS servers : 202.188.1.5 and 202.188.0.133
  • New added DNS servers : 202.188.1.4 and 202.188.0.132

Monday, December 15, 2008

Enabling TraceMonkey in Firefox 3.1

TraceMonkey is the new Javascript Engine in Firefox 3.1 which is claimed to be 20-40 times faster than the order one. I have not tried out Firefox 3.1 myself yet and will wait for the official release.

Here's the steps to make sure TraceMonkey is enabled for both web content and XUL/chrome in Firefox 3.1:-

-Open a new tab and type "about:config"
-Enter "jit" in filter field
-Make sure both "javascript.options.jit.content" (for Web Content) and "javascript.options.jit.chrome" (for XUL/chrome) have the "true" value.