Delphi Format function

function Format ( Const Formatting : string; Const Data : array of const ) : string;

Rich formatting of numbers and text into a string.

Const Formatting 参数是一个格式字符串,用于格式化 Const Data 数组里面的值。

Formatting 参数的指令格式以”%”开始,以 Type 结束,Type 表示一个具体的数据类型。中间是用来格式化 Type 类型的指令字符,是可选的。

%[Index:][-][Width][.Precision]Type

Type 的类型包括:

d = Decimal (integer),整型值;

u = Unsigned decimal,无符号整型值,如果它对应的值是负的,则返回时是一个2的32次方减去这个绝对值的数。

Format('this is %u',[-2]);===>this is 4294967294

f = Fixed,浮点数;

e = Scientific,科学记数法表示;

g = General,浮点型,会将值中多余无效的数去掉。

Format('this is %g',[02.200]);===>this is 2.2

n = Number (floating),浮点型,会将值转化为号码的形式(默认只表示到小数后两位)。

Format('this is %n',[4552.2176]);===>this is 4,552.22

m = Money,钱币类型;

p = Pointer,指针类型,返回的值是指针的地址,以十六进制表示;

s = String,对应字符串类型;

x = Hexadecimal,必须是一个整形值,以十六进制的形式返回;

格式化 Type 的指令:

[index:] 指示 Const Data 中参数显示的顺序:

Format('this is %1:d %0:d',[12,13]);===>this is 13 12

Format('%d %d %d %0:d %3:d', [1, 2, 3, 4]);===>1,2,3,1,4

[width] 指定将被格式化的值占的宽度,默认右对齐,[-] 指定向左对齐:

Format('this is %4d',[12]);===>this is __12 (__下划线是不存在的,只是为了显示这里空了两格)

Format('this is %-4d',[12]);===>this is 12__

[.Precision] 指定精度:

Format('this is %.7f',['1.1234]);===>this is 1.1234000

string.translate and string.maketrans

string.translate( s, table[, deletechars])

Delete all characters from s that are in deletechars (if present), and then translate the characters using table, which must be a 256-character string giving the translation for each character value, indexed by its ordinal.

string.maketrans(from, to)

Return a translation table suitable for passing to translate(), that will map each character in from into the character at the same position in to; from and to must have the same length.

string.translate() 可以根据一个映射表将字符串里的字符替换成映射表对应的字符,比如映射表里面设定 a 对应 1,b 对应 2,c 对应 3,那么 'abc'.translate 对应的字符串就是 '123'.

string.maketrans() 就是用来生成 translate() 所需要的映射表,参数是两个相等的字符串,根据两个字符串对应的字符位置作成一个字符映射表。

Email PLZ,No IM

Email:

  1. 不打扰人,对双方来说都更为高效;
  2. 大段文字讨论,不中断;
  3. 更为方便的文档存储管理。

IM:

正好与之相反。

Vim 多文件查询

多文件查询是指在多个文件内查询同一字段。命令 :vimgrep

:vim[grep][!] /{pattern}/[g][j] {file}

For example,递归当前目录及子目录,在所有 py 文件中查询 main,\C 区分大小写,\c 不区分大小写。

:vimgrep /\Cmain/ **/*.py

These commands all fill a list with the results of their search. “grep” and “vimgrep” fill the “quickfix list”, which can be opened with :cw or :copen, and is a list shared between ALL windows.via Find in files within Vim

GAE app.yaml version number

If you don’t change the version number in app.yaml,your changes will be made live immediately.When you are developing your application and are not formally in production,it is good practice to leave the version number unchanged when you upload new version.

一直都有个疑惑,在 GAE 上部署 App 新版本的时候,app.yaml 里面 version 该怎么设置,为求保险,之前都是依次递增。看到上面这一段明白了,如果不修改,那么会完全覆盖掉 GAE 上当前版本,新版本立即生效,这在进行实时开发的时候非常方便。如果在当前稳定版本的基础上测试新功能开发,最好修改 version number,这样对外跑一个稳定版本,测试版本可以单独跑,互不耽误。测试通过后可以在 versions 设置哪一个作为默认应用版本。

旧博客统计留念

 old blog count

根据雅虎统计,从 2008-04-02 开始,恰好两年时间。

My first Ajax script

<div id = "chatcontent">
    Loading…
</div>
<script>
    function updateMsg(){
        $.ajax( {
            url:"/messages",
            cache:false,
            success:function( html ){
                $("#chatcontent").html( html );
            }
        } );
        setTimeout( ‘updateMsg()’,1000 );
    }
    updateMsg();
</script>

Picky 改动记录二

从 hg 拿到 Picky 最新代码,改了一点点,部署成功。留个记录:

  1. writer.py line 211 添加 try..except,解决不能登录后台。这个好像是 Twitter Search 和 GAE memcache 的问题,好像 Twitter Search 默认只能搜索七天(?)内的 Tweets,这样如果之前在 Twitter 上有链接到博客,memcache 里的 mentions_twitter 不为空,但是时间长以后 mentions_twitter 获取不到 [ ‘results’ ],造成登录后台时候错误,KeyError: ‘results’。
  2. robots.txt 修改 sitemap.xml 为绝对地址,RobotsHandler 生成 robots.txt 的时候没有对 template_values 赋值;
  3. 删除两个主题 sidebar.html、article.html、footer.html 模板里的 Google Ads;
  4. header.html 追加 Google Webmaster Meta 验证;
  5. 更换 Favicon.

PS:刚部署完,就发现 Livid 追加了一个新功能,Tweets:Latest 20 Tweets by @livid,期待已久的功能,目前 hg 里代码还没有更新,回头再更新。准备偷师一下这个 Tweets 的实现,看能不能把腾讯微博的给添加进来。Oh NO,腾讯微博连 RSS 都不支持,WTF!

教训

由于校内更改了状态发布的代码,所以之前的 Fannt2r 失效。今天修改时候由于一个细节问题浪费了不少时间:

  1. 小心中间临时变量名。由于设置了一个函数变量 cookie,而中间又有 cookie 临时缓存,之前都是用 cookie 一个变量,导致变量的值被篡改。所以,中间临时变量名字不要跟函数变量一样,改为 cookie_buf;
  2. 细心耐心的去调试程序。

PS:Python 真的很有爱。

玉树不倒

国务院决定,为表达全国各族人民对青海玉树地震遇难同胞的深切哀悼,2010年4月21日举行全国哀悼活动,全国和驻外使领馆下半旗志哀,停止公共娱乐活动。

为玉树人民默哀。玉树不倒,青海常青。