leto@freecity.cn

Programming Languages

Jake's Free House For Fun.

Preface

Well, I'm pretty sure this title to me is much smaller than it is to most of you. This page contains knowledges I learned and links of homeworks of those book I finished.


Learning computer languages could be head scratching.

C & C++

Essential C++

记得当初是某位实验室的学长推荐给我的。其实我最初用来接触 C++ 的书是谭 浩强的某本《C++ 程序设计》之类,在学必修的面向对象程序设计之前还校选了一 门同类的课,那个时候用的就是小强的。作为入门我觉得是很不错的,毕竟是国 人写的,很多思维方式以及遣词造句都比较东方思维,看起来容易理解。然而作 为教材我觉得是不够的,最基本来说书本的排版都有点差,代码风格等等,和后 来看到的这些书和之前的原版的 K&R 的《The C Programming Language》相比都 有比较大的差距。后来正是上面向对象程序舍就的时候又买了 Bruce Eckel 的 《Thinking In C++》,书比较天马行空加那时候懒,没看完。再后来就是进实 验室被推荐这本了,就想 Lippman 感慨的,天哪!这本书竟然是如此之薄。正 像我学别的语言一样,先课后习题再项目,希望自己能够勉励自己早日完成。

Lisp

Emacs Lisp

如果你习惯了在 Windows 下用鼠标对系统指指点点的时候,为了用一个编辑器 去学一门语言的感觉其实是很怪异的,然而当你去看看使用 XML 作为主流配置 文件之前那些 Unix 系统下软件的配置文件时,眼花缭乱至于应该能够理解强大 的可定制性确实需要强大的配置语言的支持……

我不确定这本书是否正是我正在看的,因为买不到或者说买不起我正在看的这个 的英文原版,我只能选择面对屏幕。

(去确认了下,果然是同一本哈哈,等咱有了钱就买一本吧。)

目前的进展同样也是缓慢,看到循环的时候又兴趣索然了,开始自我怀疑…… 不 过不管怎样,毕竟已经写过一个超简单的 muse 的 srctag 扩展,在理解别人的 配置文件的用意方面也有长足进展,暂时目标是,还没想好。

JavaScript & ActionScript

jQuery

flex

Java

Ivor Horton's Beginning Java 2, JDK 5 Edition

学 Java 的历程颇为奇特,修了一门学校的 Java 程序设计,楼 sir 的上课风 格确实让我不容易睡觉,然而也不容易让我去理解真正的东西。当然自己懒才是 主要因素,往往听他讲完一个东西之后便哦一下然后去做别的事情,通常别的事 情无非是灌水加电影。教训:学语言要动手。到后来要考试了,才发现真正的东 西还没看,一直都是拿着 Java 的书复习 Java 从 C 继承过来的最基本的东西。 于是放弃考试。

本以为很快就要把这东南亚小国放在一边了,却在后来的暑假短学期来了个遭遇 战,本来的项目变成了一个更像软件民工短期培训班的东西。理解了一些简单的 东西概念之后这玩意便只剩下复制粘贴了。这时候的经验让我深深地感受到了黄 金锤子的威力1,我碰到的第二个所谓项目不过是暑假这东西的延续,为了对 页面表单的东西进行验证我甚至用起了隐藏输入框,就因为不会 session 还懒 得去学些基本的 JavaScript……

大三下的时候又因为有个类别学分不是很够去重修了楼 sir 的那门 Java 课, 借着此机会顺便学习了 Swing,再度感受到 Java 代码的长和 Eclipse 在这方 面的好用。后来做了个很简易的东西,就不放这里献丑了,嘿嘿。

Struts2 in action

Perl

Slashdot 上对 Perl 的评价

Dim Perl As String. WriteOnly

Learning Perl

就像我在做作业前写的,羊陀书太厚,于是买了这本作为入门。学这个有点像为 了学而学的样子,它并非我日常生活必须的(至少目前是这样),也不像 PHP, 我没有用它来做什么惊天动地的事情的打算,更主要的恐怕只不过是因为简历上 这么写了自己事实上却不会的感觉实在太差。

现在我已经看完前八章了,从文件句柄到正则表达式,我越看下去越发现自己沉 迷于它与系统的结合程度和简易程度。那个神奇的变量 $_,那三个一开始让我 吓一跳的代表模式匹配结果的名字($` $& $'),和那个 Larry 的千金命 名的钻石操作符,相比 Java 的长篇累牍,Perl 的简便让我变得甚至不想打字……

哈哈,扯的扯的,事实上还是在学习中,关于 cgi-bin 方面的应用也即将准备 学习,希望顺利。

Working with Modules

首先当然是 CPAN(Perl 综合典藏网,Comprehensive Perl Archive Network)的地 址:http://www.cpan.org 。包罗万象,有 Perl 的源代码,各种平台的安装程 序、范例程序、说明文档、扩展模块以及 Perl 相关的存档信息。就我目前的菜 菜水平而言,只是去找些别人的代码中用到但是我没装的模块,所以这里顺便介 绍一下。安装模块很容易,看 README 就知道了~

Modifying Files From Command Line

Larry Wall 觉得写一个 Perl 脚本,给它权限然后执行还是太麻烦了,于是就 有了这么一个东西:

perl -p -i.bak -w -e 's/^\*\* /* /g' source/*.muse
熟悉 awk 与 sed 的命令行牛人们应该对上面这玩意感到很熟悉,只是少了重定 向和相应的参数而已,那个关键的 s/// 还是相同的,我自己也正在看这些方面 的书,为了应对一些面试,希望顺利。下面从《Learning Perl》上抄袭些东西 方便日后找寻。2

-p 选项用来要求 Perl 帮你写程序,如此:

while (<>) {
    # Your code goes here.
    print;
}
如果觉得让 Perl 自己加 print 太冒失了,可以用 -n 选项,与上面相同,只 是没有 print。-i.bak 将 $^I 设置为 .bak。不想备份的话单单写上 -i。这个 参数与 sed(stream editor)的 -i 参数是一样的,如果不指定 -i 参数则将 会将结果输出到标准输出,所以也可以把 -i 去掉然后自己重定向到文件,不过 可能会出问题,我自己没试过,毕竟带着随时带着降落伞才是正确的做法。-w 开启警告,-e 则 用来指定:下面这些是代码哦。这些代码会放到 while 循环中,print 前。要 指定多段,那就多指定 -e,如此而已。

System Evironment Variables

foreach (sort keys %ENV) {
    print "$_  =  $ENV{$_}\n";
}

PHP

Reading drupal source code

开始学 PHP 并动手写 Blog 的时候就听说过这玩意了,猪刨作为一款 CMS(Content Management System)年代久远,看它的代码能学到很多东西,当 然这里不可避免地要从 官方文档 抄点东西。

Emacs 的使用者可能本身的 php-mode 设置与猪刨的代码风格不符合,但是又不 想仅仅为了猪刨改变自己的,那么下面这设置就能够帮到你(抄袭自猪刨官方)。

;; drupal's specific php-mode
(defun drupal-mode ()
  (interactive)
  (php-mode)
  (setq c-basic-offset 2)
  (setq indent-tabs-mode nil)
  (setq fill-column 78)
  (c-set-offset 'case-label 2)
  (c-set-offset 'arglist-close 0))

;; automate load drupal-mode for php files beneath drupal directory.
(add-to-list 'auto-mode-alist
             '("/drupal.*\\.\\(php\\|module\\|inc\\)$" . drupal-mode))

XML/HTML

(2009-3-5) 这又是一片充满了争议的土地,标准 vs. 执行简直是永恒的话题。现行最新标 准分别是 HTML 4.0XHTML 1.1,我一直坚持使用的是 XHTML 1.0 Strict。 有看法认为 XHTML 没有意义,因为实际上大部分的 Web 服务都没有保留它的专 用文件类型(MIME), xml+xhtml。Hell with it. 我才懒得管那么多,网页正 常显示,标准验证通过,乌拉!

A full featured table

套用 HTML Dog 的话说:

So you think you know how to make a table. Sure, you know the table, tr, td and th tags, you've even got the rowspan and colspan attributes in your pocket. You can make a really cute little plywood coffee table, but don't you want to know how to make one of those polished solid wood, glass top dining tables that can take the weight of an oversized elephant?

<table>
<!-- define the table columns and style them as desired.
 The only styles you can apply to columns are borders,
backgrounds, width and visibility.-->
        <colgroup>
                <col />
                <col span="" class="alternate" />
        </colgroup>
<!-- not so fancy in ie. -->
<caption>Locust mating habits</caption>
<thead>
<tr>
        <th>Header 1</th>
</tr>
</thead>
<tfoot>
<tr>
        <td>Footer 1</td>
</tr>
</tfoot>
<tbody>
<tr>
        <td>Cell 1</td>
</tr>
...
</tbody>
</table>

URL

% 在 URL 被用来转义,要获得 % 自身,使用 %25。

note from opera

最近在看 Opera Web 标准课程,内容很是翔实,例子也极丰富。

items should be noticed in <head></head>

<meta name="description" content="blah blah"/>
<meta name="keywords" content="Dogs,Alsatian,Breeding,Dog,Tips,Free,Pet"/>
<style type="text/css" media="print"></style>
<style type="text/css" media="screen"></style>
<link rel="stylesheet" type="text/css" media="screen" href="styles.css">

doctype

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Quirk Mode

所谓的怪异模式。如果文档类型没有指定的话,用的就是这个。在应用一些 JavaScript 实现的特效时可能导致问题。例如,jQeury的 slideDown() 和 slideUp()

xml
<?xml version="1.0" encoding="UTF-8"?>

并不是必须的。

不过值得庆幸的是,除非你真的以 XML 格式将 XHTML 文档发送给浏览器(参见 以上讲述 XHTML 部分的附注),并使用 UTF-8 字符编码以外的字符编码,且你 使用的服务器不发送确定字符编码的 HTTP 消息头,你是不需要使用 XML 声明 的。

blockquote

<blockquote cite="http://www.w3.org/TR/html401/"></blockquote>

<p>This did not end well for me. Oh well,
<q lang="fr">c'est la vie</q> as the French say.</p>

3rd list

<dl>
  <dt>术语</dt>
  <dd>术语的定义</dd>
  <dt>术语</dt>
  <dt>术语</dt>
  <dd>适用于以上两个术语的定义</dd>
  <dt>具有以下两个定义的术语</dt>
  <dd>术语的第一个定义</dd>
  <dd>术语的第二个定义</dd>
</dl>

img

Regex

Regular Expression

Flavors

in Java

java.util.regex

The metacharacters supported by this API are: ([{\^-$|]})?*+. There are two ways to force a metacharacter to be treated as an ordinary character:

predefined character classes:

Alternatively, a capital letter means the opposite:

Quantifiers

Greedy quantifiers are considered "greedy" because they force the matcher to read in, or eat, the entire input string prior to attempting the first match. If the first match attempt (the entire input string) fails, the matcher backs off the input string by one character and tries again, repeating the process until a match is found or there are no more characters left to back off from. Depending on the quantifier used in the expression, the last thing it will try matching against is 1 or 0 characters.

The reluctant quantifiers, however, take the opposite approach: They start at the beginning of the input string, then reluctantly eat one character at a time looking for a match. The last thing they try is the entire input string.

Finally, the possessive quantifiers always eat the entire input string, trying once (and only once) for a match. Unlike the greedy quantifiers, possessive quantifiers never back off, even if doing so would allow the overall match to succeed.

To illustrate, consider the input string xfooxxxxxxfoo.

    Enter your regex: .*foo  // greedy quantifier
    Enter input string to search: xfooxxxxxxfoo
    I found the text "xfooxxxxxxfoo" starting at index 0 and ending at index 13.

    Enter your regex: .*?foo  // reluctant quantifier
    Enter input string to search: xfooxxxxxxfoo
    I found the text "xfoo" starting at index 0 and ending at index 4.
    I found the text "xxxxxxfoo" starting at index 4 and ending at index 13.

    Enter your regex: .*+foo // possessive quantifier
    Enter input string to search: xfooxxxxxxfoo
    No match found.

The first example uses the greedy quantifier .* to find "anything", zero or more times, followed by the letters "f" "o" "o". Because the quantifier is greedy, the .* portion of the expression first eats the entire input string. At this point, the overall expression cannot succeed, because the last three letters ("f" "o" "o") have already been consumed. So the matcher slowly backs off one letter at a time until the rightmost occurrence of "foo" has been regurgitated, at which point the match succeeds and the search ends.

The second example, however, is reluctant, so it starts by first consuming "nothing". Because "foo" doesn't appear at the beginning of the string, it's forced to swallow the first letter (an "x"), which triggers the first match at 0 and 4. Our test harness continues the process until the input string is exhausted. It finds another match at 4 and 13.

The third example fails to find a match because the quantifier is possessive. In this case, the entire input string is consumed by .*+, leaving nothing left over to satisfy the "foo" at the end of the expression. Use a possessive quantifier for situations where you want to seize all of something without ever backing off; it will outperform the equivalent greedy quantifier in cases where the match is not immediately found.


1. 脚注其实是拿来让你自己去百度的……

2. 完整的文档请参考 perlrun 在线说明文档

工具配置笔记

学生习作

在外网的我的窝

友情链接们