| Subcribe via RSS

ASP returns “Operation must use an updateable query” error

November 26th, 2009 | No Comments | Posted in .NET

Well, I got this error from my ASP application. I spent 2 hours to fix the problem and it is very easy, just grant the permission of the database folder to Internet Guest account (IUSR_MACHINE).

Reference : http://support.microsoft.com/kb/175168

Tutorial : Ruby vs. Java

November 21st, 2009 | No Comments | Posted in Java, Ruby

Ruby Instance Variables

Example:

1
@foobar

A variable whose name begins with ‘@’ is an instance variable of self. An instance variable belongs to the object itself. Uninitialized instance variables have a value of

Java Instance Variables

Example:

1
2
A a = new A();
a.variable = 0; //<-- instance variable; a variable that belong to each object.

Instance Variables (Non-Static Fields) Technically speaking, objects store their individual states in “non-static fields”, that is, fields declared without the static keyword. Non-static fields are also known as instance variables because their values are unique to each instance of a class (to each object, in other words); the currentSpeed of one bicycle is independent from the currentSpeed of another.
Reference http://java.sun.com/docs/books/tutorial/java/nutsandbolts/variables.html

Ruby Class Variables

Example:

1
@@foobar

Java Class Variables
Example:

1
private static int variable = 0; // <-- class variable, the variable that belongs to the class

Class Variables (Static Fields) A class variable is any field declared with the static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. A field defining the number of gears for a particular kind of bicycle could be marked as static since conceptually the same number of gears will apply to all instances. The code static int numGears = 6; would create such a static field. Additionally, the keyword final could be added to indicate that the number of gears will never change.
Reference http://java.sun.com/docs/books/tutorial/java/nutsandbolts/variables.html

Ruby Global Variables

Example:

1
$foobar

A variable whose name begins with ‘$’ has a global scope; meaning it can be accessed from anywhere within the program during runtime.

Java Global Variables
Don’t have it. It is like a variable that has been declared outside all of the methods.

Ruby Constants
Example

1
FOOBAR

A variable whose name begins with an uppercase letter (A-Z) is a constant. A constant can be reassigned a value after its initialization, but doing so will generate a warning. Every class is a constant.

Trying to substitute the value of a constant or trying to access an uninitialized constant raises the NameError exception.

Java Constants

1
private final int variable = 0; // <-- final variable, the value of the variable cannot be changed.

Ruby on Rails: Disable database connection

November 21st, 2009 | 1 Comment | Posted in Rails

Well, I have just entered to the world of ruby. After walked through a demo application. I suddenly encountered a little problem. I created a demo application and it required to use database connection to mysql, or simply Active Record, which I don’t want to because it’s just a demo application. And every time I refresh my application, WebBrick will give me a error about database connection failed. Here’s how to shutdown the Active Record system

In environment.rb looking for the line

1
2
3
# Skip frameworks you're not going to use. To use Rails without a database,
# you must remove the Active Record framework.
#config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

Uncomment the line config.frameworks… to be

1
2
3
# Skip frameworks you're not going to use. To use Rails without a database,
# you must remove the Active Record framework.
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

Simply just that!.

Java : Why do want to new different objects from one class

November 21st, 2009 | No Comments | Posted in Java

I was asked this once. Why do we need to new object every time we want to use it.
Yes, my first answer is, we need different objects because we need to use them separately because they are on different locations in Heap memory. However, this is not actually the answer. So, why do we need to new object every time we want to use it.

For instance,

1
2
A a = new A();
A a1 = new A();

What’s the different between a and a1. They behave exactly the same, because they are A class. The reason is we would like to actually change their attributes or properties inside the class. This is very fundamental Object-oriented principle.

How to use java.util.Timer to repeat the task

November 17th, 2009 | No Comments | Posted in Java

This is how I do it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.util.Timer;

import java.util.TimerTask;

/**
 *
 * This class uses the java.util.Timer functionality
 * The class will repeat itself every second.
 *
 * @author Toy
 */


public class Main
{
    public static void main(String[] args) throws Exception
    {
        int delay = 5000; // delay for 5 sec.
        int period = 1000; // repeat every sec.

        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask()
            {
                public void run()
                {
                    System.out.println("done");
                }
            }, delay, period);
    }
}

How to filter only unread emails in Googlemail

November 10th, 2009 | No Comments | Posted in Knowledges

Well, I know that everybody knows this technique already. But I don’t know that before, I have just moved all of my email accounts to Google Mail. And It’s fab. However, when Google Mail downloaded my emails already.
They are marked as Unread. How do I filter all my emails and show only unread email?

This is how.
1. In the search text field. Enter

1
label:unread

1.2 or

1
is:unread

2. Click Search Mail.
3. Google Mail will show only unread email from all of your accounts. OMG I didn’t know that before.
4. Or we could play a little bit more with

1
label:myemail@mycompany.com & label:unread
Tags: , ,