周末去了坝上草原骑马

作者:半瓶墨水 链接:http://www.2maomao.com/blog/ba-shang-sucks/

周末去了坝上草原骑马
去花了半天
骑马花了半天
回来花了一天

日!
不去了!
再也不去了!
白给钱也不去了!

吃的烂到没边
嘴里都说欢迎你再来
但是每一个服务项目
都是一锤子买卖

代码发芽网高亮引擎更新了(版本:1.1dev_20090523)

作者:半瓶墨水 链接:http://www.2maomao.com/blog/code-fayaa-pygments-update-11de/

终于有时间把代码发芽网的高亮引擎Pygments到1.1dev_20090523版
支持的语言多了不少(已经支持164种编程语言了,包括asp.net),效果还不错

其他的更新包括:
. Firefox下右边滚动条时隐时现引起页面跳动的问题
. 编辑代码界面的改进(更高的编辑框等等)
. 添加了收藏按钮
(就是页面右边靠着顶栏的那个长长的小按钮,来自addthis.com),以前用十八帮的,不知为何会引起页面混乱
. 修正了在Chrome浏览器下“代码评论打分按钮”布局混乱的问题

新添加的编程语言支持
==================
* Antlr/Ragel, thanks to Ana Nelson
* (Ba)sh shell
* Erlang shell
* GLSL
* Prolog
* Evoque
* Modelica
* Rebol
* MXML
* Cython
* ABAP
* ASP.net (VB/C#)
* Vala

还包括一些bug fix,详见Pygments的Changelog

maximum command line parameter length? 命令行参数可以有多长?

作者:半瓶墨水 链接:http://www.2maomao.com/blog/maximum-command-line-parameter-length/

同事问了一个相关的问题,以前猜测是1024,验证了一下,居然是8196

Python语言: maximum command line parameter length? 命令行参数可以有多长?
#how long can a command line parameter have?
#
# Directly answer is 8196 on Window7(not sure about other platform)
#
#It’s easy to write a script to repro it:
#1. In one script, output the parameter it got, say script#1
#2. In another script, recursively execute script#1 and increase parameter step by step,
#   capture the output, see if you have the same with the parameter you give
#
# Usage: python test2.py
#        then you got the result
#        (if it's 10000, then adjust "end" variable below)
#
#— test.py —
import sys
print sys.argv[1]

#— test2.py —
import sys,os
param = 'a'
start = 0
end =  10000
while start < end: #binary search to speed up
    mid = (start + end) / 2
    param = 'a' * mid
    cmdline = 'test.py ' + param
    out = os.popen(cmdline).read().rstrip()
    if param == out:
        start = mid + 1
    else:
        end = mid - 1
    print len(param)
print "\nMax Command Line Length=", start

#What I got on Window7 is: 8153
#  considering cmd.exe starts with "C:\\Windows\\system32\\cmd.exe /c test.py "
#  then the maximum is about 8196

把Outlook联系人导出到Google联系人

作者:半瓶墨水 链接:http://www.2maomao.com/blog/import-outlook-contacts-book-to-google-contacts/

这两天在玩Google Phone,G1的机型,G2的系统,总体上用起来还不错,视频文件列表第一次打开比较慢

由于原来一直用Windows Mobile的,联系人都同步到Outlook,所以也没想到要导出来
现在暂用Phone了,又不想麻烦的一条条加联系人,就去搜了一下导出Outlook联系人的文章

结果发现有两种方式可以做到:
1. Windows Mobile手机跟m.google.com同步
 具体步骤参见笑来的blog:Windows Mobile手机与Google日历如何同步?

2. 直接Outlook Contacts导出到dos格式的csv,然后到http://google.com/contacts/上面去导入
 但是我在导出的时候遇到了问题 - 导出出来的中文是乱码

试了几次发现时Outlook Contacts导出到csv时的问题,可以这样绕过去:
 先导出到excel,然后从excel里面“另存为”csv格式就行了

Simple New Line Converter - CRLN DOS<=>UNIX,换行符替换工具脚本

作者:半瓶墨水 链接:http://www.2maomao.com/blog/simple-new-line-converter-crln-dosunix/

svn/hg下来的文件经常是unix换行符的,为了其他的脚本处理方便,我都统统转为dos的
以前东西少,手动就行了,gvim里面:set ff=dos就行,这次太多了,就写了个脚本

Python语言: Simple New Line Converter - CRLN DOS<=>UNIX,换行符替换工具脚本
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Simple New Line Converter for CR-LN of DOS & UNIX format
#  default convert known text files under current folder
#
# by 半瓶墨水 ( realfun at gmail dot com )
# http://2maomao.com/blog/
import os
import sys

newline = "\r\n"
if len(sys.argv) > 1 and sys.argv[1] == 'unix':
    newline = "\n"

#only convert files with the following extention
#NOTICE: spaces on HEAD/END are there on purpose!
exts = ' py html css js json txt php ini cpp h sql ini htm rb cmd bat '
fs = []
#for root, dirs, files in os.walk('d:/projects/py/django/fayaa'):
for root, dirs, files in os.walk('.'):
    for f in files:
        f = os.path.join(root, f)
        #print "==>" + f
        pos = f.rfind('.')
        if pos == -1:
            continue
        if exts.find(' ' + f[pos+1:] + ' ') != -1:
            fs.append(f)

for f in fs:
    o = open(f, "r")
    ls = o.readlines()
    o.close
    if len(ls):
        print ">>", f
        o = open(f, "wb")
        #NOTICE: here I did what I want, remove ".rstrip()" if you don't like it!
        ls = [l.rstrip() + newline for l in ls]
        for l in ls:
            o.write(l)
        o.close()