Labels

Monday, December 5, 2011

To check if Firefox is 32-bit or 64-bit:
1.) Start Firefox
2.) Open a shell and run the 'ps' command:
  ps -aux | grep firefox
3.) Search the output for 'firefox-bin' which points to the path of the Firefox executable e.g.:
  /usr/lib/firefox-3.6.10/firefox-bin
4.) Pass the absolute path of the 'firefox-bin' file to the 'file' command e.g.:
  file /usr/lib/firefox-3.6.10/firefox-bin

5.) Check the output of the 'file' command, if you see the string 'ELF 32-bit' you'll need the 32-bit Squish package, otherwise the 64-bit package.

Tuesday, November 22, 2011

How to change user's home directory and user name, and delete user and all files in Ubuntu

1. To change the user's home directory
sudo usermod -d /path/of/new/home -m username

will copy all files from user's home directory to /path/to/new/home and will also update the system file that stores the location of user's home directory (/etc/passwd).


2. to change the username (used as username in the system) and the user’s real name (usually is a displayed name).

sudo usermod -c "Real Name" -l New_Username Old_Username


3. Deleting a User from an Ubuntu Linux System

3.1 An existing user may be deleted using the same User settings dialog used to add a user as outlined above. Select the System desktop menu and choose Users and Groups from the Administration sub-menu to launch the User settings dialog.

Select the user to be deleted and click on Delete. A confirmation dialog will appear. If you wish to proceed click on Delete in the confirmation dialog to commit the change.

Note that the deletion process will remove the account but leave the user's home directory intact. This will need to be deleted manually if it, and any files therein, are no longer required.


3.2 A user account may also be deleted from command-line using the deluser utility:

sudo deluser john


3.3 It is also possible to remove the user's home directory as part of the deletion process:

sudo deluser --remove-home john

Alternatively all files owned by the user, including those in the user's home directory may be removed as follows:

sudo deluser --remove-all-files john

The files in the user's home directory can also be backed up to another location before the directory is deleted using --backup-to command-line option together with the path to the backup directory:

sudo deluser --backup-to /oldusers/backups/john --remove-home john

Ubuntu: How to Change the Computer Name

gksudo gedit /etc/hostname

1.When prompted, enter the administrator password and click the OK button.
2. The hostname file will open, displaying the current computer name. Replace the current computer name with the desired new name.
3. Click Save. 6. Close all open windows and restart your system.
After your system has restarted, it will have the new computer name.

From:
http://www.tech-recipes.com/rx/2732/ubuntu_how_to_change_computer_name/

Wednesday, November 16, 2011

Command--pwd and cd

Or print working directory using pwd command

[prompt]$ pwd

/home/dliu

cd Command

cd ..  or s go back one directory, .. directory corresponds to the parent directory

cd or cd ~   go back to home directory

cd /             moves to root

cd -  go back to one directory previously used like backward in windows explore     

Tuesday, November 15, 2011

Where is the Trash box

~/.local/share/Trash
The trash can icon on the desktop contains files and folders which you have deleted using the File Manager or an application run from the desktop. It doesn't keep the deleted file from a terminal.

Monday, November 14, 2011

Compare two different versions of a source file

original link: http://justinram.wordpress.com/2006/04/26/windows-subversion-tortoisesvn-compare-two-versions-of-a-file/
Today I needed to compare two different versions of a source file. One in the main trunk folder and the other in a previously tagged version folder. This is easily done in TortoiseSVN, snippet from the TortoiseSVN manual:
Compare two revisions of a file
If you want to compare two revisions in a file’s history, for example revisions 100 and 200 of the same file, just use TortoiseSVN => Show Log to list the revision history for that file. Pick the two revisions you want to compare then use Context Menu => Compare Revisions.
If you want to compare the same file in two different trees, for example the trunk and a branch, you can use the repository browser to open up both trees, select the file in both places, then use Context Menu => Compare Revisions.
If you want to compare two trees to see what has changed, for example the trunk and a tagged release, you can use TortoiseSVN => Revision Graph Select the two nodes to compare, then use Context Menu => Compare HEAD Revisions. This will show a list of changed files, and you can then select individual files to view the changes in detail. Alternatively use Context Menu => Unified Diff of HEAD Revisions to see a summary of all differences, with minimal context.
The process of comparing two trees is really nicely done, you get a list of all the files which have been changed between the two trees. You can then drill into this list and see the changes made to individual files.

Checked out revision number in Tortoise SVN?

Right-click on the working directory in windows explorer, and select "Properties", not the "Properties" inside the menu of "tortoiseSVN". You will see the Properties dialog, which will have a tab called "Subversion". Click on it, and you will see the version number, and other info.

Monday, October 17, 2011

用topcoder准备cs 面试

http://www.mitbbs.com/article_t/JobHunting/31969293.html

发信人: yangcheng (牛魔王), 信区: JobHunting
标 题: 用topcoder准备cs 面试
发信站: BBS 未名空间站 (Mon Oct 17 13:26:01 2011, 美东)

这一段时间面试下来觉得topcoder对coding面试的帮助很大。昨天回帖提到topcoder后
,收到一些站内信询什么是topcoder,怎么用,
我也不是大牛(topcoder绿色,算刚刚入门)。希望抛砖引玉,


topcoder 是一个公司, 网址http://www.topcoder.com/ ,有很多商业开发。当然对面试帮助最大的我觉得是它的算法竞赛还有很多人写tutorial

google recruiter的email里面都会包括topcoder tutorial的地址:)

tutorial 地址:
http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=

其中很多经典比如binary search http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=binarySearch.

除了tutorial 还可以免费注册会员,在arena中参加他们的online contest(10天左右
一次), 更方便的则是大量的练习题。

这里有一个很详细的arena quickstart
http://blog.theroyweb.com/topcoder-quickstart-tutorial


topcoder的好处有
1 提供大量的test case,有助于发现代码中的bug。看其他资源往往没有如此多的test
case。很可能过了一两个简单case就以为代码对了。

2 可以看其他人的code,实在想不出来可以知道怎么解答

3 题目分难度,其他online judge 比如acm.zju.edu.cn 中难以判断题目的难度。
topcoder上 div2 level 1的题目应该要能秒杀。 div2 level 2/div 1 level1 的题目
大概是面试题目的级别的。 div2 level3 / div2 level2 算面试的难题了

不足:
1 可以使用语言的标准库,面试时候往往是不行的。
2 为了速度,很多人代码的可读性不好,
3 同样为了速度,当题目的数据量不大的时候,多数人采取的解法是最容易code的暴力
。同样的题目拿来面试显然不能暴力

How to Share folders with your Ubuntu Virtual Machine (guest)

How to Share folders with your Ubuntu Virtual Machine (guest)
http://www.howtogeek.com/howto/ubuntu/how-to-share-folders-with-your-ubuntu-virtual-machine-guest/

The only problem: I cannot share the folders which is not at the same disk as VM is.

Thursday, October 13, 2011

CSS--1

What is CSS?

 CSS stands for Cascading Style Sheets

•Styles define how to display HTML elements

•Styles were added to HTML 4.0 to solve a problem

•External Style Sheets can save a lot of work

•External Style Sheets are stored in CSS files

CSS Syntax

A CSS rule has two main parts: a selector, and one or more declarations:


The selector is normally the HTML element you want to style.

Each declaration consists of a property and a value. The property is the style.

A CSS comment like this:   /*This is a comment*/

The id Selector

The id selector defined with a "#" is used to specify a style for a unique element with id attribute i.e. id="para1".

<html>
<head>
<style type="text/css">
#para1
{
text-align:center;
color:red;
}
</style>
</head>

<body>
<p id="para1">Hello World!</p>
<p>This paragraph is not affected by the style.</p>
</body>
</html>

Tips: Do NOT start an ID name with a number! It will not work in Mozilla/Firefox.

The class Selector

The class selector is used to specify a style for a group of elements. Unlike the id selector, the class selector is most often used on several elements.

This allows you to set a particular style for many HTML elements with the same class.

The class selector uses the HTML class attribute, and is defined with a "."

Example
<html>
<head>
<style type="text/css">
.center
{
text-align:center;
}
</style>
</head>

<body>
<h1 class="center">Center-aligned heading</h1>
<p class="center">Center-aligned paragraph.</p>
</body>
</html>

You can also specify that only specific HTML elements should be affected by a class.

In the example below, all p elements with class="center" will be center-aligned:

Example
<html>
<head>
<style type="text/css">
p.center
{
text-align:center;
}
</style>
</head>

<body>
<h1 class="center">This heading will not be affected</h1>
<p class="center">This paragraph will be center-aligned.</p>
</body>
</html>

*     Do NOT start a class name with a number! This is only supported in Internet Explorer



Three Ways to Insert CSS

There are three ways of inserting a style sheet:

  • External style sheet
  • Internal style sheet
  • Inline style



External Style Sheet


An external style sheet is ideal when the style is applied to many pages. With an external style sheet, you can change the look of an entire Web site by changing one file. Each page must link to the style sheet using the <link> tag. The <link> tag goes inside the head section:

< head>
< link rel="stylesheet" type="text/css" href="mystyle.css" />
< /head>

An external style sheet can be written in any text editor. The file should not contain any html tags. Your style sheet should be saved with a .css extension. An example of a style sheet file is shown below:

hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("images/back40.gif");}

Do not leave spaces between the property value and the units! "margin-left:20 px" (instead of "margin-left:20px") will work in IE, but not in Firefox or Opera.



Internal Style Sheet


An internal style sheet should be used when a single document has a unique style. You define internal styles in the head section of an HTML page, by using the <style> tag, like this:

< head>
< style type="text/css">
hr {color:sienna;}
p {margin-left:20px;}
body {background-image:url("images/back40.gif");}
< /style>
< /head>





Inline Styles


An inline style loses many of the advantages of style sheets by mixing content with presentation. Use this method sparingly!

To use inline styles you use the style attribute in the relevant tag. The style attribute can contain any CSS property. The example shows how to change the color and the left margin of a paragraph:

< p style="color:sienna;margin-left:20px">This is a paragraph.</p>



Cascading order

Number 4 has the highest priority:

  1. Browser default
  2. External style sheet
  3. Internal style sheet (in the head section)
  4. Inline style (inside an HTML element)

Note: If the link to the external style sheet is placed after the internal style sheet in HTML <head>, the external style sheet will override the internal style sheet! 

DOCTYPE

A doctype declaration refers to the rules for the markup language, so that the browsers render the content correctly.

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/XHTML11/DTD/XHTML11.dtd">

HTML Development Tools

  • Firefox
    • As of this writing, Firefox still has the best developer plugins available, though Google Chrome is quickly catching up. Chrome ships with a pretty impressive Firebug-like set of developer tools.
    • An invaluable plugin for Firefox that allows you to, among other things
      1. view and manipulate the HTML, CSS, and DOM of your page in real time
      2. debug javascript
      3. enter and execute javascript in a console on the fly in the context of the current page
      4. inspect all the HTTP requests and responses made by the current page in real time - a life-saver for AJAX work.
    • Integrates W3C validation with the view source window.
    • Validates internal server pages that are not accessible by the public W3C web service.
    • Might require the installation of the libstdc++5 and/or libxul-dev packages on some Linux platforms. See special instructions on http://users.skynet.be/mgueury/mozilla/faq.html.
    • In the plugin's options, set the algorithm to SGML Parser not HTML Tidy.

Wednesday, October 12, 2011

Style and Link

1.   Style


The HTML <font> Tag Should NOT be used

The <font> tag is deprecated in HTML 4, and removed from HTML5.

Styling HTML with CSS

CSS was introduced together with HTML 4, to provide a better way to style HTML elements.

CSS can be added to HTML in the following ways:

  • in separate style sheet files (CSS files), The preferred way.
  • in the style element in the HTML head section
  • in the style attribute in single HTML elements

2.   HTML Link Syntax


  • Links are specified in HTML using the <a> tag.

The <a> tag can be used in two ways:

To create a link to another document, by using the href attribute

To create a bookmark inside a document, by using the name attribute

  • The HTML code for a link is simple. It looks like this:

< a href="url">Link text</a>

The href attribute specifies the destination of a link.

Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML element.

  • HTML Links - The name attribute to create a bookmark inside an HTML document

The name attribute specifies the name of an anchor.

Note: The upcoming HTML5 standard suggest using the id attribute instead of the name attribute for specifying the name of an anchor. Using the id attribute actually works also for HTML4 in all modern browsers.

Bookmarks are not displayed in any special way. They are invisible to the reader.

Example

A named anchor inside an HTML document:

<a name="tips">Useful Tips Section</a>

Create a link to the "Useful Tips Section" inside the same document:

<a href="#tips">Visit the Useful Tips Section</a>

Or, create a link to the "Useful Tips Section" from another page:

<a href="http://www.w3schools.com/html_links.htm#tips">

 Visit the Useful Tips Section</a>

Basic Notes - Useful Tips

Note: Always add a trailing slash to subfolder references. If you link like this: href="http://www.w3schools.com/html", you will generate two requests to the server, the server will first add a slash to the address, and then create a new request like this: href="http://www.w3schools.com/html/".

 Tip: Named anchors are often used to create "table of contents" at the beginning of a large document. Each chapter within the document is given a named anchor, and links to each of these anchors are put at the top of the document.

URL

URL - Uniform Resource Locator

When you click on a link in an HTML page, an underlying <a> tag points to an address on the world wide web. A Uniform Resource Locator (URL) is used to address a document (or other data) on the world wide web.
A web address, like this:http://www.w3schools.com/html/default.aspfollows these syntax rules:
scheme://host.domain:port/path/filename
Explanation:
  • scheme - defines the type of Internet service. The most common type is http
  • host - defines the domain host (the default host for http is www)
  • domain - defines the Internet domain name, like w3schools.com
  • :port - defines the port number at the host (the default port number for http is 80)
  • path - defines a path at the server (If omitted, the document must be stored at the root directory of the web site)
  • filename - defines the name of a document/resource

Common URL Schemes


SchemeShort for....Which pages will the scheme be used for...
httpHyperText Transfer ProtocolCommon web pages starts with http://. Not encrypted
httpsSecure HyperText Transfer ProtocolSecure web pages. All information exchanged are encrypted
ftpFile Transfer ProtocolFor downloading or uploading files to a website. Useful for domain maintenance
fileA file on your computer

W3C Markup Validation Service

http://validator.w3.org/

HTML 4.01 Quick List

HTML Basic Document
<html>
< head>
< title>Title of document goes here</title>
< /head>
< body>
Visible text goes here...
< /body>
</html>

Heading Elements

< h1>Largest Heading</h1>
<h2> . . . </h2>
< h3> . . . </h3>
< h4> . . . </h4>
< h5> . . . </h5>
<h6>Smallest Heading</h6>

Text Elements

< p>This is a paragraph</p>
< br /> (line break)
< hr /> (horizontal rule)
< pre>This text is preformatted</pre>

Logical Styles

< em>This text is emphasized</em>
< strong>This text is strong</strong>
< code>This is some computer code</code>

Physical Styles

< b>This text is bold</b>
< i>This text is italic</i>

Links

Ordinary link:< a href="http://www.example.com/">Link-text goes here</a>
Image-link:< a href="http://www.example.com/"><img src="URL" alt="Alternate Text" /></a>
Mailto link:< a href="mailto:webmaster@example.com">Send e-mail</a>
A named anchor:
< a name="tips">Tips Section</a>
< a href="#tips">Jump to the Tips Section</a>

Unordered list

< ul>
< li>Item</li>
< li>Item</li>
< /ul>

Ordered list

< ol>
< li>First item</li>
< li>Second item</li>
< /ol>

Definition list

< dl>
< dt>First term</dt>
< dd>Definition</dd>
< dt>Next term</dt>
< dd>Definition</dd>
< /dl>

Tables

<table border="1">
< tr>
<th>Tableheader</th>
<th>Tableheader</th>
< /tr>
< tr>
<td>sometext</td>
<td>sometext</td>
< /tr>
< /table>

Iframe

<iframe src="demo_iframe.htm"></iframe>

Frames

<frameset cols="25%,75%">
<frame src="page1.htm" />
<frame src="page2.htm" />
< /frameset>

Forms

< form action="http://www.example.com/test.asp" method="post/get">
<input type="text" name="email" size="40" maxlength="50" />
< input type="password" />
< input type="checkbox" checked="checked" />
< input type="radio" checked="checked" />
< input type="submit" value="Send" />
< input type="reset" />
< input type="hidden" />

< select>
< option>Apples</option>
< option selected="selected">Bananas</option>
< option>Cherries</option>
< /select>
<textarea name="comment" rows="60" cols="20"></textarea>

< /form>

Entities

& lt; is the same as <
& gt; is the same as >
& #169; is the same as ©

Other Elements

<!-- This is a comment -->
<blockquote>
Text quoted from a source.
< /blockquote>
<address>
Written by W3Schools.com<br />
< a href="mailto:us@example.org">Email us</a><br />
Address: Box 564, Disneyland<br />
Phone: +12 34 56 78
< /address>
Source : http://www.w3schools.com/html/html_quick.asp

Friday, October 7, 2011

set up QT with Visual Studio environment

http://qtnode.net/wiki/Qt4_with_Visual_Studio#Setting_up_your_environment

how to set windows environment variable
http://www.itechtalk.com/thread3595.html

Environment Variables

In order to successfully use Qt three environment variables have to be setup: QTDIR, PATH and QMAKESPEC.
In order to compile Qt, the QTDIR has to be set to point at the directory containing the Qt distribution.
i.e. C:\Source\Qt\4.7.3\

To be able to invoke the Qt tools from the command line the PATH variable needs to be set. Simply include      %QTDIR%\bin  at the end of your PATH on windows.

In order to use qmake properly,  QMAKESPEC points at a directory holding file qmake.conf which     describes the target environment to qmake. i.e. C:\Source\Qt\4.7.3\mkspecs\win32-msvc2008 (for visual studio 2008).

QMAKESPEC

qmake requires a platform and compiler description file which contains many default values used to generate appropriate Makefiles. The standard Qt distribution comes with many of these files, located in the mkspecs subdirectory of the Qt installation.

The QMAKESPEC environment variable can contain any of the following:
  • A complete path to a directory containing a qmake.conf file. In this case qmake will open the qmake.conf file from within that directory. If the file does not exist, qmake will exit with an error.
  • The name of a platform-compiler combination. In this case, qmake will search in the directory specified by the mkspecs subdirectory of the data path specified when Qt was compiled (see QLibraryInfo::DataPath).


In summary, a cross-platform Qt project consists of the following files:
  • A .vcproj file containing Windows-specific settings and listing the files in the project.
  • A .pro file containing Unix and/or Mac OS X specific settings.
  • A .pri file (a qmake include file) listing the files in the project.
execute this command in your console:
qmake -tp vc -r xxxxxx.pro

Thursday, September 29, 2011

How to redirect to online webpage when click a link in Whatsthis rich text

If the text is rich text and the user clicks on a link, the widget also receives a QWhatsThisClickedEvent with the link's reference as QWhatsThisClickedEvent::href().
If a QWhatsThisClickedEvent is handled (i.e. QWidget::event() returns true), the help window remains visible. Call QWhatsThis::hideText() to hide it explicitly.
Reimplement QWidget::event() and catch QEvent::WhatsThisClicked. It can be done more or less in this way:

bool CSDQueuesWindow::eventFilter(QObject *obj, QEvent *ev)
{
  if(ev->type()==QEvent::WhatsThisClicked)
  {
   QWhatsThisClickedEvent* whatsclicked = static_cast<QWhatsThisClickedEvent*>(ev);
   QDesktopServices::openUrl(QUrl(whatsclicked->href())); // redirect to the linked bomgar webpages
   return true;
  }
  return QWidget::eventFilter(obj,ev); // call base class!
 
}

QAction class

Qt simplifies the programming of menus and toolbars through its action concept. An action is an item that can be added to any number of menus and toolbars. Creating menus and toolbars in Qt involves these steps:

• Create and set up the actions.

• Create menus and populate them with the actions.

• Create toolbars and populate them with the actions.



In the Spreadsheet application, actions are created in createActions():

void MainWindow::createActions()

{

newAction = new QAction(tr("&New"), this);

newAction->setIcon(QIcon(":/images/new.png"));

newAction->setShortcut(tr("Ctrl+N"));

newAction->setStatusTip(tr("Create a new spreadsheet file"));

connect(newAction, SIGNAL(triggered()), this, SLOT(newFile()));

}

The New action has an accelerator (New), a parent (the main window), an

icon (new.png), a shortcut key (Ctrl+N), and a status tip.We connect the action’s

triggered() signal to the main window’s private newFile() slot, which we will

implement in the next section. This connection ensures that when the user

chooses the File|New menu item, clicks the New toolbar button, or presses Ctrl+N,

the newFile() slot is called.

Monday, September 26, 2011

what's the difference between executing a program by simply typing it's name, vs. executing a program by typing a . (dot) ?

source, . (dot command)

This command, when invoked from the command-line, executes a script. Within a script, a source file-name loads the file file-name. Sourcing a file (dot-command) imports code into the script, appending to the script (same effect as the #include directive in a C program). The net result is the same as if the "sourced" lines of code were physically present in the body of the script. This is useful in situations when multiple scripts use a common data file or function library.
Running "runme" will create a new process which will go on its merry little way and not affect your shell.
Running ". runme" will allow the script "runme" to change your environment variables, change directories, and all sorts of other things that you might want it to do for you. It can only do this because it's being interpreted by the shell process that's already running for you. As a consequence, if you're running bash as your login shell, you can only use the "." notation with a bash script, not (for example) a binary on C shell script.

Friday, September 23, 2011

Design问题的学习总结

转:http://siyangxie.wordpress.com/2010/02/05/design%e9%97%ae%e9%a2%98%e7%9a%84%e5%ad%a6%e4%b9%a0%e6%80%bb%e7%bb%93/

Design问题的学习总结

1. 系统设计步骤:
首先是需求分析。这包括,理解系统是要做什么,有哪些用户,用户希望系统提供什么服务/功能。这些是最基本的,进一步的,可以分析一下系统的规模及相应对性能的要求,输入输出是什么(或者说怎么跟用户交互)。
其次就是分解系统为若干子系统,并且找系统中出涉及到的各个对象。在甄别对象的时候,需要牢记,对象要封装用一组共同的数据和特性。然后就是分析思考各个对象,对内应该封装哪些状态和性质,对外提供什么接口和行为。与此同时要考虑各个对象之间的关系和interaction,把每个对象拟人化。关系有composition, association, aggregation等等,在设计对象关系的时候,要多注意考虑code reuse和future extention. Interaction是麻烦的地方,因为一个interaction中,涉及到两个或者多个的对象,很难分清楚,到底谁是哪个对象提供的这个行为:"file.print(printer) or printer.print(file)?” 怎么办?一个是从语义行为的常理上分析,谁应该提供这个行为,一个是从软件设计的原则出发,例如力求避免紧耦合而使用一个manager.print(file, printer),我也觉得这个是很难说清楚的,只有靠多分析了。
接下来就是考虑有哪些可能变化的东西(现在或者未来),尽量把会变化的部分分离出来加以封装,并且时刻考虑,如何使得design更flexible,如何在未来添加新的code或者feature而不需要改动现在的code。这个时候,可以开始回忆熟悉的设计模式,考察有哪些设计模式可以应用,常用到的如decorator, bridge, strategy, factory, singleton, state, observer等等。
现在把类的框架搭好后,开始考虑动态的关系,即sequence diagram。我个人感觉就是系统提供的服务流程的描述。这里一个困扰我很久的问题是,如何把人机交互的GUI部分,跟GUI背后的各个类的工作,分离开设计。我现在就只能先假设不考虑具体的系统是怎么通过人机交互来提供服务的。
接下来就是考虑实现。一个重要且经常遇到的问题是,怎么管理数据和信息,信息本身可以会涉及到一个或者多个对象类。普遍的,系统都会提供信息搜索查询的服务,那么是用数据库?还是普通的数据结构(数组,map等)?哪些信息应该交给对象自己保存而不是让manager来保存?例如,在停车场设计的题目中,需要保存下“某Customer的车子Car停在位子Space上”的信息,这时候也要考虑,是否应该在space obj中记录停车的客户信息,是否应该在customer object中记录车位的信息?这时,如果考虑到,customer的代码,可能会被用到别的application中,因此不应该在customer对象中保存车位的信息。
2. 设计原则:
基本的OOD概念:封装,抽象,继承,多态
OOD五大原则:OCP(open closed), LSP(substitution), ISP(interface segregation), DIP(dependency inversion), SRP(single responsibility)
GOF设计三大原则:Program to interface; Favor composition over inheritance; Encapsulate what varies;
总体的目标是:promote flexibility and weak coupling; easy to maintain, easy to extend;

OO design--parking lot

转: http://www.mitbbs.com/article_t1/JobHunting/31956527_0_2.html
这种问题都起始于OO Design,那些Object,怎么关系啥的。帮人帮到底,送佛送到西,
讲讲通常情况下,这种design问题的答题方法(对于多数面试官适用,当然也有例外)



这种问题首先明确要干啥,也就是需求分析,不要上来就开搞。比如parking lot,设计
是parking lot的管理?还是charge system?还是啥其他相关问题。这个很重要,决定
了你的设计。

其次,要求几个具体user case。比如,parking lot,可能要求用户能walk-in and pa
rk;要求用户能提前预订;能cancel reservation。user caess也决定了你的design,
也体现了你良好的沟通能力。

然后就是Logical Model或者physical model的design。需要啥Objects(比如 Garage,
Lot, Customer, Car)。

然后他们的关系,比如Garage to Lot (1 - m)。在兽一下OO的继承关系(比如car有tru
ck, sedan, SUV啥的;Lot有大lot,小lot,残帕啥的)

然后根据user case,说明如何用你的model实现。比如reserve,从garage (比如singl
eton)找合适的 Lots,然后根据时间段,看能不能reserve。能的话,系统状态如何up
date;不能得话,如何给customer feedback。

这个可以延伸到很多问题,比如可以考察synchronization,如果只有一个lot,几个用
户同同时request,如何保障正确的行为,如何保障公平,等等。

也可以考算法,根据你的设计,随意挑一个component,比如选择合适的lot,如何高效
优质的实现你的算法。比如你可以用List一个一个找;也可以用其他数据结构,提高算
法质量。

也可以考Coding,从你的任意描述,抽象一个方法,让你写Code。比如如何实现方法Re
verse。定义API,写code。

也可以考business sense,比如在资源有限情况下,如何取舍(功能上,用户体验上,
等等)。

基本上,这种Open Question,想考啥,都可以考。所以你应该从基本OO Design开始,
把面试管引导到你擅长的方向。比如,你熟悉多线程,就多强调一下如何做同步控制;
如果你Design Pattern比较熟,就多丢一丢,比如Garage可以是个Singleton Pattern,
啥的。当然,要是你碰着傻X的面试官,一根经的非要你按照他的想法去设计,那就是你
的rp问题了。

Wednesday, September 14, 2011

ipad/iphone开发入门

Tutorials:



The tool you use to create Mac OS X applications is Xcode—Apple’s IDE (integrated development environment). “Creating Your Project” shows you how to create a new project and describes how an application launches.

Whereas Xcode is the application you use to create and manage the project, Cocoa is the name given to the collection of APIs that you use to develop programs for Mac OS X. You should typically use the highest level of abstraction available to accomplish whatever task you want to perform. To create a desktop application, you should use the Objective-C-based frameworks that provide the infrastructure you need to implement graphical, event-driven applications.

To use the Objective-C frameworks effectively, you need to follow a number of conventions and design patterns. Following the Model-View-Controller (or “MVC”) design pattern, the application uses a controller object to mediate between the user interface (view objects) and the underlying representation of a track (a model object).

·        “Understanding Fundamental Design Patterns” provides an overview of the design patterns you’ll use.

·        “Adding a View Controller” shows you how to customize a view controller class and create an instance of it.

You design the user interface graphically, using Xcode, rather than by writing code. The interface objects are stored in an archive called a nib file.



开发免费,到developer.apple.com请个账户就可以了.但只能在simulator上测试,搞到iphone/ipad上就要花$99了,另外两种方法:
1.
找一个有$99账户的人,让他加你team member
2. jailbreak

developer.apple.com
videosample codes是最快入门的.要说书吗,我推荐两本:
stephen kochan: programming in objective-c 2.0
erica sadun: cookbook



Thursday, September 8, 2011

Finding a duplicated integer in a given array, O(n) time and O(1) space

Finding a duplicated integer. Given a read-only array of n integers between
1 and n-1, design an O(n) time algorithm to find a duplicated integer. Use
only O(1) space. Hint: equivalent to finding a loop in a singly linked
structure.

http://en.wikipedia.org/wiki/Floyd%27s_cycle-finding_algorithm#Tortoise_and_hare


http://www.mitbbs.com/article_t1/JobHunting/31942529_0_1.html
IANGLE PUZZLE
By starting at the top of the triangle and moving to adjacent numbers on the
row below, the maximum total from top to bottom is 27..
5

9 6

4 6 8

0 7 1 5

I.e. 5 + 9 + 6 + 7 = 27.
Write a program in a language of your choice to find the maximum total from
top to bottom in triangle.txt, a text file containing a triangle with 100
rows.
download traiangle.txt in http://www.yodle.com/downloads/puzzles/triangle.txt

who can fix this problem? It is very difficult. Please post your answer

Project Euler Problem 18 & 67

work bottom-up, greedy

从倒数第二行开始。每个数字和下一行的两个数字相加。选较大的值存。然后再上一行
5
9 6
4 6 8
0 7 1 5

倒数第二行的4和下一行它能reach的两个值0和7相加。取较大的4+7=11。
倒数第二行的6和下一行它能reach的两个值7和1相加。取较大的6+7=13。

三角形变为

5
9 6
11 13 13

再变为

5
22 19

再变为

27

最大值