—— Where exceptions happen.

显示标签为“programming”的博文。显示所有博文
显示标签为“programming”的博文。显示所有博文

2008年12月24日星期三

给GreaseMonkey脚本添加自动更新

上个月我给自己的GreaseMonkey脚本写了一段自动更新的代码,不过我实在受不了在user.js文件之间复制代码片段(一股代码腐败的不祥气息),就算为了自利利人,我把这个封装好的对象放在一个单独js文件里,上传到Google Code上了,现在如果你写GreaseMonkey脚本,添加自动更新的简洁方案如下:

1. 给你的userscript脚本注释段添加如下代码:
// @require http://userscript-autoupdate-helper.googlecode.com/svn/trunk/autoupdatehelper.js
// @version <版本号>
/* @reason
<更新说明>
@end*/

(@require后面就是上传到google code里的自动更新用代码,里面定义了一个Updater对象,用法见下。<更新说明>会在客户端脚本发现版本号小于userscript.org服务器端版本号时在弹出对话框中显示)

2. 在脚本开头部分添加类似下面的代码片段:
var thisScript = {
name: "Delicious自动保存", //脚本名称,请自行修改
id: "35778", //脚本在userscripts.org的id,请自行修改
version:"1.4" // 当前脚本版本号,请自行修改
}
var updater = new Updater(thisScript); // 用thisScript对象创建一个更新器对象
updater.check(); //检查是否有更新


3. 可选的功能是另行设置更新频率(默认是10小时check一次),
在updater.check() 之前调用 updater.setHoursToCheck(t) 即可,
如updater.setHoursToCheck(24) ,则至少与上次检查时间相隔24小时才再次检查。

另外,在更新器对象创建之后,用户也可以右键GreaseMonkey图标,从“用户脚本命令”中选择手动更新脚本。

ps. 这个更新器目前是纯中文版本,所以也不写英文的发布声明了。看GreaseMonkey社区已经有自动更新用的代码片段在流传,不过直接复制粘贴大段代码我总觉得哪里不对 :-P

--
2008年12月25日 补注:
有人告诉我
“@require http://userscript-autoupdate-helper.googlecode.com/svn/trunk/autoupdatehelper.js 不行啊,直接复制倒可以”

在此补充说明一下:GreaseMonkey 0.8版增加的这个特性
@require 在安装脚本时生效,GM会自动下载 url 里指定的js文件到安装目录,直接在脚本里手工修改的话就会不行。对作者而言要先写好上传,然后安装,就能确认生效。 对脚本作者是麻烦一点,不过对用户是透明的。。。而用@require的好处可以简单的总结为:不仅快是生产力,清晰也是生产力。

2007年6月8日星期五

比较OCaml和Haskell的开发效率

为了比较OCaml和Haskell,这位blogger在3个月内用这两种语言各自实现了一个编译器(从EasyLanguage到C#),结论是OCaml获胜,按作者的话:“OCaml is the practical Haskell.”
clipped from wagerlabs.com

Who let the dogs out?
May 26th, 2007

Why Ocaml? Why not Haskell? I'll list the pros and contras below, in no particular order. I'll write up a summary first, for those of you not interested in reading the whole post.

Tenerife Skunkworks


blog it

2007年6月7日星期四

计算机语言家族树

推荐编程nerd们珍藏这张图。语言的历史沿革,亲缘关系是一目了然,图里还藏着不少八卦.
clipped from www.digibarn.com
http://www.digibarn.com/collections/posters/tongues/tongues.jpg
blog it

Ocaml资源补遗:OCaml! My Caml!

一个介绍OCaml的Presentation,可能太短了,几个Ocaml资源站上都没有收这个的link。今天上午写了一个Eratosthenes筛法的OCaml程序,想搜索看看有没有更好的实现,结果看见了这个简介里的实现(关于筛法,它给了 Imperative approach和 Functional approach两种实现……但我还是比较喜欢我自己的两次尾递归方案,多出来的一次是因为没有用标准库的List.filter)
clipped from youngbloods.org
OCaml! my Caml!


A brief introduction to
Objective Categorical Abstract Machine Language


by Kats Rogo and Carl Youngblood


blog it

2007年5月29日星期二

中文编程语言和它的一条明路

今天在豆瓣小组上又看见一个“中文编程语言”——o语言,为什么要说“又”呢,因为我还看见过“易语言”(vb控件汉化版),“中蟒”(python的汉化版),或许在中文互联网的哪个旮旯里还藏着什么别的雄心勃勃要做“中国人自己的编程语言”之类的开发者。

说起来,中国人的民族自尊心从1911年以来就没有被彻底满足过,虽然眼看着似乎就要”大国崛起“,可国民心理还是揣着对自身民族文化的不信任和危机感,写几行程序都觉得有被西化的危险,中文最好,中文节省字数,中文优美,中文历史悠久,……中国人要用中文写程序。嗯,但汉字在计算机上没有象形文字的特殊待遇,也就是两个字节共32个bit的0/1序列,用16bit的ASCii字母和用32bit的Unicode字符对编译器而言并无区别。按着这条国产翻译字幕组的道路走下去是没希望没出路的。我且给中文编程语言指一条明路:

首先要认清,必须扬弃乔姆斯基那套形式语言的玩意,在这个框架下怎么搞,中文词汇都是字符流里的token,没有一点象形文字的特点。要搞就搞一套模仿象形文字的形式计算体系。计算符号要可以在二维空间中按特定规则组合,而不是一维的符号流。另外有必要证明这个二维的形式符号系统和图灵机等价,然后中文编程语言才有了自己的理论基础。一个Lambda演算就可以发展出一大堆Functional Language. 一个二维形式计算机不知道可以搞出多少”中国式编程语言“,到时候编程都是论帧,不是论行。这种语言的一段独立功能的代码由一些随意歪斜的线条和符号构成,其中依稀可辩一些来自中国字的偏旁部首,这就是一帧,是程序员在手写设备上”画“出来的。然后一帧帧能够连动,就构成一个程序,优势极大,这种语言基于图形间的拓扑关系,容错性大,图形直观,易于debug,模块关系一目了然,易于复用。嗯,这条路虽然艰险,却是编程语言中文化的一条光明大道啊,嘿嘿,kuso完毕

ps. 等我退休后,说不定真的会把这个弄出来的 :P

2007年5月16日星期三

How-to: Build OCaml native code with MSVC 2005

Most Ocaml books, tutorials and lectures would stress its performance. OCaml’s optimizing compiler generates high-performance native code, which I cost a whole afternoon to build.I installed Ocaml 3.09.3 release, and read the “Readme.windows.txt”. I found these evil lines:

" Visual C++ version 6 or later. We use Visual C++ 2003.
The free download Visual C++ 2005 Express Edition works under
Windows 2000, but not under Windows XP because of the "manifest"
annotations on DLLs, which are not yet supported by OCaml.
So, please stick with the 2003 edition for the time being. "
But... I've installed the free Visual C++ 2005 Express Edition. ╮(﹀_﹀")╭ One way is uninstalling the free MSVC 2005 Express edition, then emule/bt a pirate and out-of-date MSVC 2003. the other is trying to find some workaround. I chose the latter.
After a long try-err process, I successfully build OCaml into native win32 code with MSVC 2005 version. following is the detail step-by-step:

0. make sure you've installed Ocaml for the port based on the Microsoft toolchain. This guide isn't for Cygwin port.

1. get Visual C++ 2005 Express Edition from Microsoft.com, It's free. and get it's SP1 too.

2. get Microsoft Macro Assembler 8.0 (MASM) Package from Microsoft.com. It's free also.

3. get Microsoft Windows Server 2003 R2 Platform SDK from Microsoft.com. It's free but require you pass the "Windows Genuine Advantage" test.(if you hate this test. you can easily find the SDK ISO on emule...*\(▔▽▔)/*)

4. install 1,2.3.

5. set the PATH environment variable: add "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\bin" into the PATH. you may need alter the path as your tools' real install directory.

6. set the LIB environment variable as "D:\Microsoft Platform SDK for Windows Server 2003 R2\Lib;C:\Program Files\Microsoft Visual Studio 8\VC\lib\" you may need alter the path too.

7. Thus you ocamlopt your .ml file, thus all of them. And on the seventh step you ended your work which you had made; and you rested on the seventh step from all your work which you had made. :-P

ps. this How-to guide is writen in an obviously imperative style. Let us rewrite it in functional style:
let PATH = "$Visual Studio$\VC\bin; $Visual Studio$\Common7\IDE"
let LIB = "$Platform SDK$\lib; $Visual Studio$\VC\lib"

Functional style is really short and clear. :-)

OCaml resources

Chosen OCaml for my neural network simulation, these days I greedily collected OCaml resources all the Web just as a spider. Wish the following links help other OCaml-rookies.

Intro:
Ocaml on Wikipedia ;
Ocaml Homepage

Manual:
The Objective Caml system release 3.09 (newest ref)

Lecture:
Using, Understanding, and Unraveling: The OCaml Language; (2000, 2001)

Tutorial:
http://www.ocaml-tutorial.org/ (this site is resourceful and updated)
"Ocaml for scientist" (Chapter 1) (recommend)

Code:
OCaml official codebase: The Caml Hump
Codecodex's OCaml Category
. (this site is very interesting for fans of many kinds of language , not including Haskell :-p )

IDE:
OCaml Development Tools (an Eclipse plug-in. released 1.0 at May 10, 2007)

Benchmark:
OCaml vs. Java.(Take it for fun!)

News rss:
Maybe I should use pipes to make one rss for OCaml News….Hmmm

中文论坛:
Ocaml china, 一个不错的中文Ocaml论坛,虽然草创,文章和人气都不是很多。但格局和讨论氛围很好:)希望能进一步壮大。