Liuw's Thinkpad

想要赢就先学会输,想要成功就先学会失败

Archive for January, 2012

惨痛教训一则

without comments

这几天都在装机器,开发机、测试机、测试服务器,费了不少时间。

代码原来就是在测试机上的,所以先git clone到开发机上来,然后把测试机重新格掉了,然后再clone回去。

然后发现我新写的代码都不见了,这才想起来那些代码都只是git stash掉,没有真正commit,所以clone的时候是没有备份的。

老老实实重新写了,又费了一个半小时。

吃一堑长一智。以后一定注意。

Written by liuw

January 29th, 2012 at 5:27 pm

Posted in UNIX-like

Tagged with , ,

一个简单的AHK脚本

without comments

#IfWinActive ahk_class Emacs
Capslock::Control
Control::Capslock
#IfWinActive

假如当前的ahk_class是Emacs,那么交换Ctrl和Caps,否则不交换。

Written by liuw

January 22nd, 2012 at 4:21 pm

Posted in 分享

Tagged with , , ,

Emacs里面的MiniMap

without comments

Sublime Text的MiniMap比较有特色,正在想是不是能为Emacs也搞一个类似的东西,没想到已经有了。(不知道MiniMap是啥的,请移步Sublime Text的网站)

http://www.emacswiki.org/emacs/MiniMap

Emacs MiniMap的tricky之处在于,它并没有实现什么新的GUI控件,而是直接新开一个buffer,把font face缩小一下,达到MiniMap的类似效果。想出这法子的哥们可真行。

不过这也意味着MiniMap在字符界面是下不可用的——不过这谁又在乎呢,毕竟Sublime Text连CUI的版本都没有。在Emacs里面用这么小的代价实现相似的功能,一方面是Emacs这货实现是强大,另外一方面是写这东西的哥们实在也挺有想法的。

不过目前看来这个MiniMap功能是有了,但是体验不算特别好。用vertical split开的window在C-x 1之后就不见了,这可是很不爽的。依我的想法来看,能不能想办法让minimap window比较特殊一点,于是自己fork了一个别人已经做了修改的版本hack了一下。目前我主要hack了三个小地方:

1. 为delete-other-windows做了advice,总是保留MiniMap window;
2. 修正了make-overlay的一个错误参数,不改的话为空文件生成的overlay是不对的;
3. 只为图形界面的Emacs创建MiniMap,毕竟用了font face,在字符界面下意义不大。

随便改了一下,感兴趣的就拿走。

https://github.com/liuw/emacs-minimap

MiniMap的实现也不算特别稳定,有时会让Emacs死掉的。但是我没有那个水平,也懒得去debug了——说实话我还是用CUI的Emacs比较多点,看这东西单纯是觉得新奇而已。废话少说了,上图。

MiniMap效果图

Written by liuw

January 15th, 2012 at 6:15 pm

Posted in 分享

Tagged with , ,

Can’t help writing this down: is it really so hard to find a buzheteng Linux distro?

without comments

It’s SUNDAY! Time for ranting!

It may seem weired that I rant in English — anyway I’m not a native English speaker and the best rant always comes from one’s mother tongue. BUT there is no Chinese input method on this system, so I have to writing this down in English.

You can bet I’m on Linux now, yes, you’re right. I’m playing with Fedora 16 in a live USB key. The default desktop is Gnome 3 — another disaster for a long time Gnome 2 user. It seems that the Unity-like UI is getting more and more popular. Well, I can adapt myself to new UI. However, PLEASE do better design. The new UI is driving both ordinary users and developers (who use Linux as developing platform) away IMHO.

For new users / Linux noobs: Configuration ability is very weak — look at those few icons in the control panel. What’s worse, the default style of the desktop sucks — large portion of my screen is occupied by useless window frame and menu (take firefox as an example). I wish I could tweak font size to make it not so ugly, but I just can’t find a tool to do that. This will eventually lead to comments like “Linux is ugly and difficult to use”.

For developers: How can I tweak this system? I need my menu back! Those visual effects are good, but they don’t add up productivity. Grouping appications is a good move, but the big icons scattering all over the screen makes me feel bad. Searching applications? That works on the basis that your application shows up in the groups. In a word, they are not helping at all. My observation is that few of my friend (low level) developers will use either Unity or Gnome 3.

Well, some other suggestions include switching to Arch or Gentoo. But I’m not very into those two distros. My principle is “buzheteng”. I would rather focus on my job. I’m really tired of writing configurations line by line with my bare hands. I need a out-of-the-box distro.

How about switching to other desktop environment? KDE? No, I had very bad experience long time ago which effectively shadows me nowadays. LXDE and XFCE? They are just too light-weighted, I need full featured desktop.

Linux desktop is evolving, that’s good. I’m just too out-dated to catch up with its pace. I can not appreciate the new changes due to my out-dated tastes. I’m considering buying a Macbook now, seriously.

UPDATED:
To my surprise, KDE works much better than Gnome 3 for me. The UI is smoother than I expected. But (well, there is always a “but”) the concept of “activity” is driving me mad (What? I need to switch “desktop icons” activity to view my icons? Then switch back to “desktop” activity to see my applications?). Grouping applications is one thing, grouping activities is another. I don’t like the idea of switching among different activities just to separate what you’re doing, I would rather use different workspaces to achieve the same goal.

Written by liuw

January 8th, 2012 at 4:29 pm

Posted in 戏言

Tagged with , , ,

Emacs中的Rectangle

without comments

记一下Emacs里面的rectangle相关的操作。

Emacs的rectangle概念,就是你mark的起点和终点之间围起来的区域。由于rectangle没有专门的模式去select,所以在显示方面,transient-mark-mode不能只高亮这个rectangle。像在Vim里面,可以用C-v启用Visual mode blockwise,看起来会漂亮点。不过,看不看得清楚并不影响操作。

在Emacs中输入C-h a,然后输入rectangle就可以得到一些相关的函数。

比较有用的是对rectangle的delete、kill、yank操作。

然后还有replace-rectangle、string-insert-rectangle、string-rectangle。

shortcut就不写了,我是M-x党。

Written by liuw

January 7th, 2012 at 6:32 pm

Posted in UNIX-like

Tagged with ,

Oops debug小经验

without comments

常在河边走哪能不湿脚,写程序没有遇到bug那是不可能的。内核菜鸟写代码,出个kernel oops那更是家常便饭。

从我目前遇到的各种oops来看,debug首先要检验能否稳定重现bug。

若不能稳定重现(触发条件不一,Oops信息不一),那么恭喜了,基本是出现竞态了。这种问题可大可小,当然最后的问题肯定是在自己的代码里面的(前提是其他模块都是稳定的)。这个时候当然是得先把code path都走一遍,检查是不是逻辑有问题;之后就是检查各种锁了。

若能稳定重现,那么相对好办点。慢慢用printk定位到出问题的语句就可以了。objdump反汇编一下,配合oops里面的stack trace信息看看大概是哪个语句出问题了,不过个人觉得帮助不大。更加高级点的工具我基本不会用,囧。

最NB的debug工具还是printk,因为它在任何上下文都是健壮的,这是一个多么伟大的特性啊!(囧)

什么?没有stack trace?你没有开内核的debug功能?当我啥都没说吧。

Written by liuw

January 6th, 2012 at 3:37 pm

Posted in Programming

Tagged with , ,