Friday, December 15, 2006

Create password protection for web folder using .access

Two files need to be create: .htaccess and .htpasswd

I want to protect a folder call "test" (/usr/www/test)
user name: goodwill
password: hackit

Create a file called .htaccess, put it in /usr/www/test/ with these content

AuthName "Restricted area"
AuthType Basic
AuthUserFile /Usr/.htpasswd
AuthGroupFile /dev/null
require valid-user

Create a file called .htpasswd that contents user name and encripted password ( using htaccess generator: ), then put this file in /usr/

EX: goodwill:.l6wTNxfoHj6U (encripted hackit)

Browse to you site to see if it work

Enable .htaccess in Mac

It took me a while to figure out why .htaccess is not working on my local web server.
By default, Appach disable .htaccess file in Mac, user who wants to use htaccess should manually modify the httpd.conf file

Here's how to do it (2 main steps)

1. Go to /private/etc/httpd/, then sudo vi httpd.conf, find the line contains "AllowOverride None", replace it with "AllowOverride all". Save the file.

2. Go to /etc/httpd/users/, there you will see all the conf files for all users, edit each of them follow above process. Then restart the web server. And you all set and run.

The sudo command is necessary if you want to have superior privilege to modify a file. Basically what sudo will do, according to wikimeida: "allows users to run programs with the security privileges of another user (normally the system's superuser) in a secure manner", a password must be provided.

Friday, December 01, 2006

Memory usage

The Active monitor from apple is a bit confusing, especially on the memory statistic.

So what are all these terms means?

Wired memory
This information can’t be cached to disk, so it must stay in RAM. The amount depends on what applications you are using.

Active memory
This information is currently in RAM and actively being used.

Inactive memory
This information is no longer being used and has been cached to disk, but it will remain in RAM until another application needs the space. Leaving this information in RAM is to your advantage if you (or a client of your computer) come back to it later.

Free memory
This memory is not being used.

More info can be found in:
Memory usage


To Copy file from local machine to remote machine:

scp filename user@remoteMachine:/path/to/destination/dir

To copy file from remote machine to local machine

scp userName@remoteMachine:/path/to/filename fileName (the rename the file on local machine)


I want to write a summary for OOP for a long while; however just can not find a time slopt and sit down to think and write about it. As of I just finished my two exams yesterday, I think it is a good time to drop some lines about OOP now.

Features and Characteristics:
Class --> In oop, class is define the abstract characteristic of a thing. (Such as attributes and behaviors). Example, A class of dog can define a method hasFur () for property, bark()
Object --> An instance of a class. Example: Lassie is an instance of class Dog.
Method --> The abilities of the object, sO Lassie being a dog, it can bark()
Message passing --> An object send data to another object or invoke another object
Inheritance --> A class has subclass, and the subclass inheritance its parent class’s attributes and behavior.
Encapsulation --> Hiding detail of how particular class works from object. Fox example, every dog has a bark() method, but we don't necessary need to know how bark() is work. Encapsulation is archive by specify which class may use the member of tech object. Therefore the object is expose to any classes a certain interface.
Abstraction --> simplify complex reality by modeling class appropriate to the problem. Such as an Abstract class Animal, which contain general properties and behavior of animal
Polymorphisms -->Behavior that varies depend on the class in which behavior is invok. Two or more difference class react differently on the same message.

What are the advantage of oop?
* Model real world by associating data to the methods operate on them.
* Control access by apply public, private, protect, prevent access to memeber variable
* Easy to segregate various parts of a program
* Hiding disparate parts of a project from one another
* Inheritance , code reuse--> lead to fast development

Pointer and Reference

Consider these couple functions:
void foo (Fruit* bar);—pass the address of the object to the function. More efficience then pass an entire obejct to the function. The pionter must be dereference before it can be used or Using (->) operator to access memebers.
void foo (Fruit & bar);—similar to point, it works with the object directly, using (.) operator to access the fmembers.
void foo (const Fruit &* bar);—this prevent foo from modified bar by using const variable

One more main difference between pointer and reference:
Passing by pointer could actually pass with NULL pointer; however, reference is guaranteed to be a reference to a valid object.

Keyword: static and extern

There are 2 use of static keyword:
1. At the external level, it specifies the scope of the variable is limited to the file it is defined in it, it cannot be reference from another file
2. Inside a function definition, it means the variable should be allocated at a fixed location in memory, such that it retains its value beteen function calls.

The extern keyword allow you to declare what the variable are, but it does not create varibles or allocate memory for them.

Predirective in c++

So when writing code for c++, there so preprocessor directive are declare on top of the file, such as #include “file.h” ; #include . what are the main difference?

#include --> compiler will look are the standard library
#include “file.h” --> compiler will look at the local directory first and look at the standard library, in this case, this file is most likely written by the programmer for module

Java vs. C++

Design Goal:
Java: Rapid development, security and portabily
C++: More concern with performacne and backward compatibility

Java: Relatively slow because it compiled to byte-code and run on top of the VM
C++: Faster, it compiled to native machine code

Memory management:
Java: Garbage collection, that collect unuse memory periodically
C++: Programmer conttrolled memory management, pointer, and a preprocessor for full backward compatibility with C

Parameter passing:
Java: passing by reference
C+: passing by value

Java: All method are virtual, meainng the implementation of a method is selected according to the type of the object
C++: methods must be explicitly declared virtual.

Manager Unix space efficience

While I was working on my Operating System project, I encountered a “disk excee quota error”, below are some command I used to check my file:

du - ak | sort -rn | more—list and sort the size of all files within a directory
find . -atime +90 -print—find all files that are older than 90 days
find . -size +1000 -print—find all files that are greater than 500k
find . -name ‘*.tex’ -print—find all files with .tex extension

Subscribe GCalendar to ICarl

If you never tried to use Google Calendar, you better try it out. It is the best web-base calendar i ever seem. G-Cal has rich functionalities and very user friendly. You can resist to use it once you get start.
One function I just discovered about G-Calendar is that,you can subscribe it to your ICal in Mac. Cool right? I have thought about this idea long time ago. Now seems dreams has come true. So here is an article teach you how to subscribe it toyour ICal:

One problem with it though, is it only one way transfer (G-Cal to I-Cal), once your subscribe it to your I-Cal, all event from G-Cal is read-only. But anyway, even though it is only one way transfer, it is good enough for me. I know google is working hard to get it to be syn with I-Cal, so keep your eyes on it.

Bookcampe startup option

Boot camp almost killed my machine tonite.
I have Xp install on my mac book however the software was expired after I used it for 30 days. Every time I login, it asked me to ativate the product otherwise it will automatically log me out.
Here is my problem tonite,
In Max OSX, I setup boot camp to start up in Window Xp such that every time it will select window as it default operating system. The problem is, I forget i cannot activate my window xp, so every time i try to log on, it log me out automatically. Since I cannot log in, i cannot switch back the start up option to Mac OSX. I was stuck.....
Luckly, from apple support web site, i found out there’s an option I can use to choose which OS to start from when start up the machine. The “Option” key is the answer.
By pressing down the “Option” key from start up, a new page will show up ask which Disk want to start up with. From there i can pick Mac OS X.


MacBook Share resource

As many of you may know, in Intel Base MacBook we now can install Window Xp on mac natively using boot camp. My though is how you gonna share resource between your mac OS with Window Xp. Apparently they are on the same machine but can not run at the same time.
When we install Window xp on mac, we create a new new partition for it, during the installation, we have an option to choose to format the partition to FAT32 or NTFS. I have discuss this with some mac user about the difference. The conclusion is: With FAT32 format, we could have read write access to the partition in Mac OS, and with NTFS, we only have read pemission. The limitation in FAT32 though, it only can have maximum capacity of 32 GB for the partition. So pick you choice.
A better idea as one of the mac user told me is to put though share resource on an external hard drive. Yeah, that really solve the problem BY putting some investment in. Haha....

Remote desktop

That’s pretty cool. It has been a while time I try to figure out how to use remote access through internet today I finally get it work ~~~ tongue wink Connect my home desktop from my company and listen to music that are from my desktop harddrive.
Here my home network setting:
What I have:
Verizon DSL, Verizon cable modern, Netgear wireless router.
The setting:
Internet -->Verizon cable modern --> wireless router --> here it connects to my window box , my Mac powerbook, my roommate pc.
How to connect:
It would be must easier if only one router, but the problem I have is because I have two routers so data need to be forward in 2 steps.

First, In order to enable remote desktop, we need to forward the ports 3389 and 80 to the window box. Since i have two router, I need frist forward these two ports from my cable modern router to my wirless router. Then from my second router, foward the two ports (3389 and 80) to my window box, in my case, the ip address is
After foward these ports have foward to the destinate machine. I should be able to connect to my window box from the internet using the primary ip address (which can be found from the first router’s config page).


前幾天談到跟微軟面試時學到的最保貴東西是怎樣才算是好的程式設計員, 昨天偶而在一個網頁上看道一編關於這話題的文章,真是獲益良多。
歸訥起來,有好修養的程式設計員應該做到下面的 32點:

    06、if 语句对出错的处理

Implement fatorial function

In Java:

public class factorial {
public static void main(String[] args){
int input = Integer.parseInt(args[0]);
int result= 1;
if(input == 0)
while(input !=0){
result = result * input;
input --;

Array vs. ArrayList

Below is some comparison between array and linklist:

Space utilization: Array is allocate in compile time, and the size of array is fixed while linklist is allocated in runtime, such that its size can be dynamic. Array could waste space since it is a fixed size.

Modification: It much easier to add/remove element in a linklist, however, when it is not easy to remove element in an array. Programmer can do that through shifting.

Accessing: Array is faster than linklist in term of accessing. Array using index to help maintain datastructure.

XML Schemas (XSD)

An xml schema define:
elements that appear in a document
attributes that can apprear in a document
define which elements are child elements
the order of child element
unmber of child elements
hether an element is empty or can include text
data types for elemt and attributes
default and fixed value for elements and attributes

Commond xml schema data types
xs: decimal
xs: integer
xs: boolean
xs: date
xs: time

XSD attributes
All attributes mus declare as simple types
Only complex element has attributes

Restriction are use to control acceptable values for XML elements or attributes. Restrictiions on XML elements are called facets.

XML Schema are extensible to future additions
Richer and more useful than DTDs
Written in XML --> manipulate schema with the XML DOM, transform your schema with XSLT
support datatype--> easier to describepermissible document content, valideate the correctness of data, define data facets, define data patterns, concert data between different data type
Support namespace

DTD (Data Type Definition)

The purpose of DTD is to define the legal building blocks of an XML documetn. It defines the documents structures with a list of legal elements.

DTD is an XML file:

Why DTD?
With dtd, each of xml file can carry a description of its own format with it
Independent groups of ppl can agree to use a common dtd for interchanging data
To verify that the data

Building Block
XML document are made up by: Elements, Tags, Attributes, Entities, PCDATA, CDATA

XML Basic

What is XML:
Stand for: Extensible Markup Language
It is designs for describe data using DTD (Document Type Definition) or XML Schema
User need to define his own tags

XML is free and extensible, it is a cross-platform , software and hardware independent tool for transmitting information
With XML, data can be store outside HTML document, it also can store inside a HTML document as "Data Island"
With XML, data can be exchanged between incompatible systems (ex: computer system and database) --> converting the data to XML can reduce this complexity and create data that can be read by many different types of application.
XML data storeed in plain text format, XML provides a software and hardware independent way of sharing data, data can be made avaible to other than only standard HTML browser.
XML can be used to create new languages (WML --> Wireless Markup Language)

All XML must have a closing tag
XML tag is case sensitive
All XML elements must be properly nested
All XML docuemnts must contain a single tag par to define a root element
Attribute values must always be quoted -->
With XML, white space is preserved
With XML, CR/LF is converted to LF

XML elements
XML documents can be extended to carry more informaiton
XML elements have relationships
Elements can have different content types

Element naming
Names can contain letters, numbers, and other characters
Names must not start with a number or punctuation character
Names must not start with the letters sml
Names can not contain spaces

About attributes
Attribute values must alwas be store in single or double quote
Better use element than attributes because:
1. Attribute can not contain multiple values
not easily expandable
are more difficult to manipulate by program code
value are not easy to test against a Document Type Definition—which use to define the legal elements of an XML document

XML Validation
A DTA defines the legal elements of an XML docuemnt
XML Schema is an XML base alternative to DTD
Error in XML documents wil stop the XML program -> the reason why HTML browsers are so big and incompatibe, is that they have their own ways ot figure out what a document should look like when they encounter an HTML error

Display XML
XML can be displayed with CSS
More sophisticately, it can be displayed with XSL

XML namespace: xmlns: xsl="namespaceURL"

XML Parser
Everything inside a CDATA section is ignore by the parser

To let XML parser understand foreign character, you should save your XML documents as Unicode

can be use to display XML data

Eclipse starts up problem

I encountered this problem after some massing up the environment variable on Win2000 platform.

The protential factor that causes this problem is because the system varible path has not been set correctly. In order for eclipse to work, the java bin directory in the path (system variable) must be put in the first place, for example:

C:\j2sdk1.4.2_08\bin;.;c:\Winnt\System32\Resource Kit;C:\Perl\bin\;C:\WINNT\system32;