Just For Fun

李亚普诺夫斯基的混乱天堂

Archive for the ‘techniclick’ Category

Plan to modify Emacs org-mode

leave a comment »

Emacs org-mode is a nice tool for me to write notes. For me the most attractive feature is that I can write LaTex equations and export to html files.

However, the html file with equations look ugly, because the equation images are not properly aligned. I can’t tolerate a beautiful LaTex equation makes such an ugly webpage:
ugly_html

There is another light markup tool called jemdoc written in python, which also supports LaTex equations in html, but BEAUTIFULLY aligned. So I plan to study the codes for jemdoc, and immigrate the nice equation alignment to Emacs org-mode. I know a little bit python, and nothing on elisp, so I hope it won’t be too hard and take too much time.

Here is the idea in jemdoc:
1. Use a variable called “baseline”, whose value is the hight of equation $0123456789xxxXXxX$.
2. After generating each equation image, record the “height”.
3. offset = height – baseline + 1
4. In the generated html code for the equation image, set: style=”vertical-align: -height px”

If someone implement this idea before me, please let me know. I’ll be glad to try it.

Advertisements

Written by Jerry

June 10, 2010 at 3:58 pm

Posted in techniclick

Python under Win is really a pain!

leave a comment »

For English users, please ignore the next paragraph and jump to the process part directly.

想用python实现几个图论的小算法,发现了networkx和pygraphviz两个库,在archlinux下很容易地就用easy_install安装了这两个库,并且很顺利地运行了http://networkx.lanl.gov/gallery.html下面的一些测试程序。昨晚想在笔记本的xp上演示一下,于是找对应的windows版,本以为也可以用easy_install轻松装好,没想到问题一大堆,折腾的过程就不说了,就说一下怎么解决的吧,看了这个过程就知道在win下开发python有多麻烦了。

process: python2.6(enthought)+networkx(1.0 rc1)+pygraphviz(0.99.1) under windows xp sp3

When you proceed, please first try to install without my modification, because some bugs might have been fixed when you see this post.

1. Have python2.6 and mingw32 installed. I’m using enthought, which is the company that sponsors scipy. The academic version is FREE. For beginners like me, creating python tool chain from scratch (download python, scipy, numpy, matplotlib … separately) is really a frustrating process.

2. Install the “setuptools”(0.6c11.1) here http://pypi.python.org/pypi/setuptools#files, so that you can use easy_install. You can skip this step if you want to install networkx manually.

3. Install “networkx”(1.0rc1) using the command: “easy_install networkx”

4. Install “graphviz”(2.26.3) (yes, pygraphviz is just a python interface to graphviz, so you need to install graphviz first). You can’t install pygraphviz using easy_install, because it depends on graphviz, and the easy_install too can’t find the path of graphviz. So you need to download and install “graphviz” from here: http://www.graphviz.org/Download_windows.php

5. Install pygraphviz from source:

5.1 Download pygraphviz(0.99.1) from this link http://networkx.lanl.gov/pygraphviz/download.html, and extract it.

5.2 Modify “setup.py”

library_path='c:/Program Files/Graphviz2.26.3/lib/release/lib'
include_path='c:/Program Files/Graphviz2.26.3/include/graphviz'

5.3 Modify “c:\python26\lib\distutils\unixcompiler.py”, (for me it was line 282):

change
compiler = os.path.basename(sysconfig.get_config_var("CC"))
to
compiler = "gcc"

Otherwise there would be an error “TypeError: ‘NoneType’ object is unsubscriptable”, see this link “http://code.google.com/p/netcdf4-python/issues/detail?id=8”. I change it back after finishing installing pygraphviz for safety (I am a beginner).

5.4 Run command “python setup.py install” under the pygraphviz source directory. Now you should be able to install it.

6. Now the installation is done, but if you try to run the sample code such as edge_colormap, you might get an error: “close_fds is not supported on Windows platforms, balabala”. This was a bug of pygraphviz, I found it here and here. So I followed the links and modified line 1146 of site-packages/pygraphviz/agraph.py to

close_fds=False)

7. Now you should be able to run the test codes without error and begin to do your own work. Actually, my python crashes when I run the test codes “circular_tree” and “lanl_routes”. I don’t know why and really don’t want to spend time fixing it.

I hope those issues will be fixed soon so nobody have to follow this painful process. Working with python under windows is really a pain.

Written by Jerry

February 12, 2010 at 12:45 am

Posted in techniclick

加密

leave a comment »

今天跟Evg同学聊了一会儿会儿,学了一点关于pgp encryption,public key, private key的东西,花10分钟记下来。n年前考所谓的计算机3级网络技术时就把这些名词背得烂熟,却始终没搞明白到底是怎么回事,而Evg同学画个草图,5分钟就讲得明明白白,可见国内的考试认证是多么的没用。

1. public key(公钥) 和 private key(私钥)
A和B想在网络上安全的交流。A首先运行一个小程序,输入一个密码,小程序生成一对key,分别是公钥和私钥(也就是两串字符,比如公钥是Pubk_A,私钥是Prik_A,当然实际比这要长)。其中私钥是用A的密码加密过的,只有A知道;而公钥是A要公开给大家的,B,C,D都知道。

公钥和私钥有这样一个特点:如果你把信息用公钥加密,那只有这个对应的私钥能解开。

现在如果B要发消息”hello”给A,B先在自己的电脑上用A的公钥来加密这个消息,然后通过网络发给A。因为这个加密的消息只有通过A的私钥才能解密,所以即使是别人(比如C)在消息传播的途中截获了消息,他也没法解密,因为他只有A的公钥,而公钥是不能解密消息的。

2 签名
现在B已经可以放心地把消息发给A了,但A还不放心:他不知道消息是不是来自B的,因为所有人都有A的公钥。于是B除了要对消息(用A的公钥)加密之外,还需要加上签名,过程如下:

B首先对要发的消息进行Hash,得到一串字符,比如”hho”。Hash算法有这样一个特点,对一个输入能够得到一个确定的输出,但是你拿到这个输出,却没法算出它的输入(比如无论谁对”hello”进行Hash,都可以得到”hho”;但是我告诉你我把一串字符进行Hash得到”hho”,你永远不知道这串字符是什么)。然后B用自己的私钥(比如Prik_B)对Hash的结果”hho”进行加密,得到一个签名。这个签名可以用B的公钥(A,C,D都知道)来解密。

然后B把这个签名连同刚才用A的公钥加密的消息一起发给A。A首先用自己的私钥Prik_A把消息解密,得到”hello”;然后对消息进行Hash,得到”hho”;然后用B的公钥Pubk_B(所有人都知道B的公钥)对签名解密,发现也得到了”hho”,一致,于是断定消息确实是从B发来的。

上面的过程已经非常安全了: 首先,如果别人(比如C),在网络传输中截获了B发出来的消息和签名,他只能对签名进行解密,得到消息的Hash的结果”hho”,而因为Hash是不可逆的,所以他得不到消息。 第二,如果C想给A发一条消息”fuck you”,想办法让A以为是B发的,这也是不可能的,因为C他不知道B的私钥;A拿着B的公钥对签名解密,会发现得到的签名和A对消息解密后再Hash的结果不一致。

3 公钥的分配
可以看出来上面的过程非常安全了,大家只要记住自己的密码,就可以得到自己的私钥(没人愿意直接记住256位的私钥吧);然后告诉大家自己的公钥,然后就可以安全的交流了(虽然很麻烦)。但如果最开始告诉别人公钥的时候被人做了手脚怎么办呢?于是存在公钥的分配问题。

解决这个问题需要首先存在一个所有人都信任的分配公钥的机构Z(肯定不是中国政府或者cctv),这个机构告诉大家自己的公钥Pubk_z(所有人百分之百确定这个公钥就是Z的),大家也都告诉Z自己的公钥(Z负责确认这些公钥属于各自的主人)。然后Z用上面那一套方法把所有人的公钥分配给大家。

当然如果A在街上遇到B,可以直接把自己的公钥告诉B,而不去麻烦Z。

4 结语和鸣谢
感谢知识面广阔的Evg同学给我如此通俗易懂的解释。感谢发明Public-key cryptography, digital signatures这套系统以及RSA/DSA算法,Hash算法,PGP程序的前辈。

Written by Jerry

May 5, 2009 at 9:07 pm

Posted in techniclick

Short note on alpine

leave a comment »

Apline
install: dpkg -i alpine.deb

configure: in ~/.pinerc
smtp-server=smtp.gmail.com:587/tls/user=name@gmail.com

#i tried ssl, but seems not work, may be I am wrong

incoming-folders=”IMAP” {imap.gmail.com/ssl/user=name@gmail.com},
“NickName” {pop.vt.edu/ssl/user=name2}
#pay attention: there should be a space after the optional label (“IMAP”)

Written by Jerry

February 11, 2008 at 9:21 pm

Posted in techniclick

Hack live-space-mover.py

leave a comment »

发现live space上有些文章wordpress上没有,因为只有几篇,手动粘过来肯定是最省事的,但是这样的话日期就变成今天的了(不知道wordpress能不能修改发文日期)。后来在网上找到了live-space-mover这个python写的脚本,作者是weiwei很多人用它都成功了。下下来运行了一下,出错,按照帮助反复试各种参数,修改live space的设置;并且作者用的是winxp,python版本是2.5,而我是debian下的python2.4,不确定是不是平台和版本造成的查异,于是又是装2.5又是重启,都还是不行(重启在win下运行时发现python在linux下要快)。折腾了几个小时,受不了了,放弃,出去转了一圈吃了晚饭。回来本不想浪费时间再弄,但是又咽不下这口气,于是又试了一下。这次灵感爆发,首先发现调用时,地址的参数应该加双引号,像这样:

python live-space-mover.py -s “http://bullogger.spaces.live.com”

然后要把live space设置成日期在标题前,并且日期时间的格式是

12/30/2008 1:30 PM

最后要把源代码里面获取时间的部分中的 temp = soup.find(attrs={“class”:”footerLinks”})改成

temp = soup.find(attrs={“class”:”footer”})

这样就能够得到导出的wordpress格式的xml文件,在wordpress里面导入就可以了,导入时选择wordpress格式。

Written by Jerry

January 9, 2008 at 12:53 am

Posted in techniclick

最近一些野狐禅

leave a comment »

比较两个日期相差多少天
echo $(($((`date –date=”2008-01-08″ +%s`-`date –date=”1984-01-02″ +%s`))/60/60/24))

console下ctrl-r可以查找以前输入的命令 这么有用的命令居然现在才知道

安装HP1020打印机的驱动 foo2zjs,按照网页提示安装。
还需要apt-get安装cupsys, cupsys-bsd等等一套东西
配置在http://localhost:631

apropos 命令可以通过keyword查到相应的命令,对我这样的半吊子可能有用。

网上查的mount命令可以通过 -o iocharset=cp936, umask=0222来使普通用户有读的权限,并且可以显示中文。但我昨天试了之后中文还是乱码,比较纳闷,不过不怎么影响使用,就算了。还有就是umask的数字和chmod应该是补码的关系。还有就是我的移动硬盘的3个分区对应的设备应该是/dev/sda1 /dev/sda5 /dev/sda6

Written by Jerry

January 8, 2008 at 6:51 pm

Posted in techniclick