2011年12月9日星期五

argsort in Python

def argsort(mylist):
    return sorted(range(len(mylist)), key=mylist.__getitem__)

or
return [i for (v, i) in sorted((v, i) for (i, v) in enumerate(seq))]

Read more!

2011年6月8日星期三

how to create html from tex source file

With latex suite, such as miktex, tex file can be converted to pdf file.
However, if you want to create html file from tex, the tool tex2page is a ideal tool.
Tex2page is a built-in tool in package Racket, which can be downloaded from http://racket-lang.org/.
When the package is installed, tex2page can be used to generate html file from tex file easily.

>tex2page file.tex
or just
>tex2page file

a Tip: now there is a bug in tex2page, you have to add a new system variable "HOME" to make it work.
Read more!

2011年3月18日星期五

谈谈google Transliteration

In the past weeks, I spent much leisure time on this topic, google transliteration, which aims at translating what you input from a language to other in real time.
Obvious it is a good news for those who can not type their language whenever, for example, some body who are traveling or studying abroad.
Of course in these people , the Chinese and Indian take a big weight. That's why the google Hindi(as well as lots of similar language) comes true already.There is also a recent tool in gmail to type these language. http://mail.google.com/support/bin/answer.py?hl=en&ctx=mail&answer=139576. I suggest the project manager that takes in charge of the google transliteration must be Indian. For Chinese, we already have sogou yun and qq yun. But they are not so convenient because of the limited speed. In the google transliteration projects, the Chinese should under in testing now because in its website, there has been already the option for Chinese translation but lots of errors are seen. Any way we hope that the Chinese can be is supported by google transliteration sooner.
Read more!

2011年3月17日星期四

google云输入法在firefox中的插件

改编的一个addon上面的程序,使其支持中文,builtin的快捷键是 ctrl +y,自己用吧,不解释了。
下载地址
看来google快一统江湖了,sogou神马的也要加油呀。
Read more!

2011年3月16日星期三

google云输入法以及在chrome中的插件

google终于推出的了它的云输入法,速度比qq,sougou要快几个数量级。
古奥里面也给出了一个输入汉语的方法,http://www.guao.hk/posts/google-transliterate-api-updates.html。
不过那种传统的booklet的方式始终是不爽,其实chrome早已经有了相应的扩展https://chrome.google.com/extensions/detail/lfjbedgfelhffkellgmlpfkeeidclfhd
不过这个扩展不支持中文。
仔细研究了下这个扩展,发现它只是一个简单的api调用,把里面的rt13n.js文件,赋值tbns.lang的那一行直接改为 tbns.lang = "zh";
重启下chrome, everthing works well, 感谢google
Read more!

2011年3月8日星期二

google publish its API explorer today

google API explorer is online today.
https://code.google.com/apis/explorer/
7 api groups is ready to use, with online manu.
With a concise interface, it is quit efficient to test these functions on line.

Actually, Flickr has been publish its api explorer for quit a long time.
and It is accessible from the URL
http://www.flickr.com/services/api/explore/?method=mathodname
for example, the entry point of photo search methods is
http://www.flickr.com/services/api/explore/?method=flickr.photos.search
Read more!

Increase CTR

Increase CTR

Ad Placement



Remember the general principles for ad placement:
1. Higher placement is better than lower and left is better than right.
2. To wrap text around ad units, copy and paste the following code into the HTML of your website.

<div style="display:block;float:left;margin: 5px;">
Insert your AdSense code here
</div>

If you change “float:left” to “float:right”, then the ad unit will move to the right.
Read more!

2011年3月4日星期五

extract frame with FFMPEG


ffmpeg.exe -i sourcefile -r 0.1  -f image2 -s 240*180 foo-%03d.jpg 

extract 10frames per minute from the sourcefile, with the image size 240*180, and all of the file are saved as f00-%03d.jpg
Read more!

rename multi files with sed

It is a very useful pipe command that can rename multi files with the same pattern

rename:ls *old|sed 's/\(.*\)\.old/mv \1.old  \1.new/'|sh

Read more!

ZZ Python datetime / time conversions

just for reminder

#youku.py
from datetime import datetime
import time

#-------------------------------------------------
# conversions to strings
#-------------------------------------------------
# datetime object to string
dt_obj = datetime(2008, 11, 10, 17, 53, 59)
date_str = dt_obj.strftime("%Y-%m-%d %H:%M:%S")
print date_str

# time tuple to string
time_tuple = (2008, 11, 12, 13, 51, 18, 2, 317, 0)
date_str = time.strftime("%Y-%m-%d %H:%M:%S", time_tuple)
print date_str

#-------------------------------------------------
# conversions to datetime objects
#-------------------------------------------------
# time tuple to datetime object
time_tuple = (2008, 11, 12, 13, 51, 18, 2, 317, 0)
dt_obj = datetime(*time_tuple[0:6])
print repr(dt_obj)

# date string to datetime object
date_str = "2008-11-10 17:53:59"
dt_obj = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S")
print repr(dt_obj)

# timestamp to datetime object in local time
timestamp = 1226527167.595983
dt_obj = datetime.fromtimestamp(timestamp)
print repr(dt_obj)

# timestamp to datetime object in UTC
timestamp = 1226527167.595983
dt_obj = datetime.utcfromtimestamp(timestamp)
print repr(dt_obj)

#-------------------------------------------------
# conversions to time tuples
#-------------------------------------------------
# datetime object to time tuple
dt_obj = datetime(2008, 11, 10, 17, 53, 59)
time_tuple = dt_obj.timetuple()
print repr(time_tuple)

# string to time tuple
date_str = "2008-11-10 17:53:59"
time_tuple = time.strptime(date_str, "%Y-%m-%d %H:%M:%S")
print repr(time_tuple)

# timestamp to time tuple in UTC
timestamp = 1226527167.595983
time_tuple = time.gmtime(timestamp)
print repr(time_tuple)

# timestamp to time tuple in local time
timestamp = 1226527167.595983
time_tuple = time.localtime(timestamp)
print repr(time_tuple)

#-------------------------------------------------
# conversions to timestamps
#-------------------------------------------------
# time tuple in local time to timestamp
time_tuple = (2008, 11, 12, 13, 59, 27, 2, 317, 0)
timestamp = time.mktime(time_tuple)
print repr(timestamp)



Read more!