August 2008 Archives

Python物件說明的程式

From Dive Into Python:

def info(object, spacing=10, collapse=1):
"""Print methods and doc strings.

Takes module, class, list, dictionary, or string."""
methodList = [method for method in dir(object) if callable(getattr(object, method))]
processFunc = collapse and (lambda s: " ".join(s.split())) or (lambda s: s)
print "\n".join(["%s %s" %
(method.ljust(spacing),
processFunc(str(getattr(object, method).__doc__)))
for method in methodList])

if __name__ == "__main__":
print info.__doc__

與help function有相同功能,為help實作的範例。

From developerWorks 中国

尽管 Rich Internet Applications 和 Web 2.0 一直都很流行,但是目前新兴的技术不仅关注为 Web 应用程序提供类似桌面的体验,实际上还把它们带入到了桌面中。在 Adobe Integrated Runtime(AIR)的引领下,Web 应用程序开发人员可以利用现有的 HTML、CSS、JavaScript、Flash 和 Flex 知识构建功能强大的桌面应用程序。在本教程中,您将使用开源的 Aptana Studio IDE、Aptana 的 Adobe AIR 插件和开源的 JavaScript 框架 Ext。

COSCUP 2008

| No TrackBacks

coscup.gif
開源人年會在這兩天舉行,包括最近研究的Google App Engine,而ericsk介紹Google App Engine Oil,這提供一個GAE的Framework,研究看看。
另外也第一次看到同步在Second Life播出,整體這次COSCUP收穫頗多,期待下一次2009的來臨。

Aptana & Ext JS

ExtMobile.jpg
在月初的一個面談過程中,聽到這套AJAX的Library,Ext JS,包含了YUIGWT的功能,並延伸其他更多UI widgets。Ext JavaScript Library教學
同樣地,找看看有沒有plug-in for Eclipse IDE,在其Manual:Resources中,便介紹如何使用Aptana + Spket + ExtJS,其中Aptana這套plug-in除了可以整合AJAX開發,支援目前主要的Library外,還提供一個Web Server,Jaxer,算是Server-side JavaScript,只要將JavaScript加註,runat = "server",就由Server端先運算後再傳送給Client,這可讓手機等Thin Client,也能執行Rich Client Application。
此為放在Google App Engine上的Ext JS Grid範例

Google App Engine & Eclipse

appengine.gif
在好奇心下,申請Google App Engine,順便找一下是否能用Eclipse來開發。
Configuring Eclipse on Windows to Use With Google App Engine,有詳細的說明:
1.下載Python安裝,ActivePythonOffice python皆可。
2.安裝Eclipse。
3.依照說明安裝PyDev,並設定執行的參數。
4.開發helloworld範例
5.Upload helloworld範例,但必須先將app.yaml的application: helloworld改為application: XXXXX,XXXXX是Google App Engine申請的Application name,也是Hostname。
這是helloworld範例結果顯示所有資料
基本上Google App Engine算是一個Web Framework,提供Google account、DB、Memcache、版本管理及AP狀態等功能整合,部份功能還在開發中,所以App Gallery還沒有很多。但未來應該可以爭食虛擬主機的市場,只要提供更多種開發語言。

Yahoo應徵考題

1. What is difference between GET/POST?

GET method makes a long URL string include variables and values. But the sending content is limited and the value could be modified by the user. And the web server maybe response result from cache because this method send data by URL.
POST method can handle data with multiple types include non-ASCII character. Browser send date which enclose after HTTP header in the package, and web server receives the data by standard input stream (stdin) in POST method.

2. How do you keep state using Web forms?

To add input box into web form, then change the type field to be "hidden". When user enters data and hidden fields have kept the same values. But this method is not safely, user could modify hidden fields to send error state if it want to confuse the server-side programs.

3. Given a line of text $string, how do you use "regular expression" to strip all html tags from it?

#!/usr/bin/php
$handle = fopen("http://tw.yahoo.com/", "rb");
while (!feof($handle)) {
$string .= fread($handle, 8192);
}
fclose($handle);
echo preg_replace("/<[^>]*>/","",$string);
?>

4. Describe UNIX IPC's ?
Inter-Process Communication (IPC) is a set of solutions for the exchange of data among two or more threads in one or more processes. Generally, it includes signal, pipes and sockets. In System V R4, it realizes these mechanisms include semaphores, messages queues, and shared memory. Except for System V IPC, most forms of IPC are half-duplex whose data flow in only one direction.

5. Write an algorithm to reverse the order of words within a string, i.e. given char *string = "The cow jumped over the moon" becomes "moon the over jumped cow The". Use as little memory space as possible, time is not a factor.

#include "stdio.h"
#include "string.h"

void ReverseWord(char *begin,char *end){
if ((begin==NULL) || (end==NULL)) return;
if (end < begin) return;
char *b = begin;
char *e = end;
char tmp;
while(b < e){
tmp = *b;
*b = *e;
*e = tmp;
b++;
e--;
}
}

int main(){
char str[] = "The cow jumped over the moon";
ReverseWord(str, str+(strlen(str)-1));
char *m,*n;
m = n = str;
while(*m!=0){
if (*m==' '){
ReverseWord(n,m - 1);
while((*m==' ')&&(*m!=0))
m++;
if (*m!=0){
n = m;
m++;
}
} else {
m++;
}
}
ReverseWord(n,m - 1);
printf("%s\n",str);
return 0;
}

6. In C, please write a program to print out an integer number 12345 without using printf?

fprintf(stdout, "%d\n", 12345);

7. Given an array in
PHP :
$ list = array('apple'=>300, 'orange'=>150, 'banana'=>100, 'mango'=>330)
Perl :
%list = ( 'apple'=>300, 'orange'=>150, 'banana'=>100, 'mango'=>330 ) ;
C++:
typdef map< string, int, less> array_type ;
array_type m;
m.insert(array_type::value_type("apple", 300));
m.insert(array_type::value_type("orange", 150));
m.insert(array_type::value_type("banana", 100));
m.insert(array_type::value_type("mango", 330));

Please choose one language above and write a program to sort the array by the order of key and value respectively with your own sorting algorithm.
Please don't use the sorting functions provided by language.

#!/usr/bin/php

$list = array('apple'=>300, 'orange'=>150, 'banana'=>100, 'mango'=>330);

print_r(selection_sort($list, 'key', True));
print_r(selection_sort($list, 'value'));

function compare($a, $b){
if (is_numeric($a)) {
return $a > $b;
} else {
return strcmp($a, $b) > 0;
}
}

function selection_sort($array, $orderby = 'value', $asc = True){
if (empty($array)) {
return array();
}

if ($orderby == 'key') { // keys are unique
$array_keys = array_keys($array);
$array_keys = selection_sort($array_keys,'',$asc);

foreach ($array_keys as $key) {
$result[$key] = $array[$key];
}

return $result;
}

$result = array();

foreach ($array as $v) {
$min = NULL;
$min_key;
$min_value;

foreach ($array as $key => $value) {
if ($min == NULL || compare($min, $value) == $asc) {
$min = $value;
$min_key = $key;
$min_value = $value;
}
}

if (!is_int($min_key)) {
$result[$min_key] = $min_value;
} else {
$result[] = $min_value;
}
unset($array[$min_key]);
}

return $result;
}
?>

8. What sort of things do you need to worry about from a security perspective when writing a web application?

(1) Who uses?
Who are the stakeholders, or users, of this application? If the application that is used in intranet must has Authority and Authentication mechanism. Otherwise, what can they do if user is in internet? So, this is first isolation issue before writing a web application.
(2) Sanitize browser input
All input from web browsers, such as user data from HTML forms and cookies, should be stripped of special characters and HTML tags. Input containing special characters such as ! and & could cause the web server to execute an operating system command or have other unexpected behavior, like SQL Injection. User input stored on the server, such as comments posted to a web discussion program, could contain malicious HTML tags and scripts. When another user views the input, that user's web browser could execute the HTML and scripts, like Cross-site scripting.
(3) Don't use "hidden" fields
A better way of preserving state information and settings is to store data in a file or database on the server then use an HTTP cookie or unique URL ID to reference the file. This is more difficult to program, but important data stays on your server.
(4) Use POST instead of GET
Even though POST information is generally not logged, like all other plain text information sent from a browser it can still be sniffed as it passes across the Internet. However, sniffing must be done in real time as information is sent across the Internet and requires the attacker to have physical access to the data lines between the web browser and web server. The risk of information being sniffed is far less than the risk of information being gathered from log files.
(5) Software Engineering
All of the above, they must follow methodology of software develop, etc. eXtreme Programming, Rapid Development... If don't develop the application in accordance with those rule, you will fall into fix and bugs whirlpool.

February 2012

Sun Mon Tue Wed Thu Fri Sat
      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      

Archives

Powered by Movable Type 4.34-en

About this Archive

This page is an archive of entries from August 2008 listed from newest to oldest.

June 2008 is the previous archive.

September 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.