2011年4月6日星期三

.vimrc sample

"文件类型识别
filetype plugin indent on
"关闭兼容模式
set nocompatible
"外部修改时自动读取
set autoread
"设置鼠标
set mouse=a
"设置历史
set history=400
"设置mapleader
let mapleader=","
let g:mapleader=","
let g:C_MapLeader=","

"设置Tlist
"let Tlist_Show_One_File=1
"let Tlist_Auto_Open=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Use_SingleClick=1
let Tlist_Auto_Highlight_Tag=1
let tlist_make_settings='make;m:makros;t:targets'
let tlist_qmake_settings='qmake;t:SystemVariables'

"显示行号
set number
"显示光标位置
set ruler
"增强命令行补全
set wildmenu
"设置命令行高度
set cmdheight=1
"减少刷新和重画
set lz
"设置退格键
set backspace=eol,start,indent
"设置跨行键
set whichwrap+=<,>,h,l
"搜索时忽略大小写
set ignorecase
"搜索时高亮关键字
set hlsearch
"设置magic
set magic
"关闭提示音
set noerrorbells
set novisualbell
set vb t_vb=
"自动匹配括号
set showmatch
set mat=2
"设置Tab键
set expandtab
set smarttab
set tabstop=4
set shiftwidth=4
"自动缩进与智能缩进
set autoindent
set smartindent
"换行不截断单词
set linebreak
"C风格缩进
set cindent
set guifont=terminus\ 10
"自动补全
set completeopt=longest,menu
set laststatus=2
"语法高亮
syntax enable
"设置颜色主题
set t_Co=256
colorscheme darkblue
"高亮当前行
set cursorline
if has("gui_running")
colorscheme slate
hi cursorline guibg=#333333
hi CursorColumn guibg=#333333
endif
"高亮菜单
hi Pmenu guibg=#333333
hi PmenuSel guibg=#555555 guifg=#ffffff
set autochdir
"生成Ctags
"map :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q:TlistUpdate
"map :!ctags -R -f ~/.vim/tags/python.ctags /usr/lib/python3.2/:TlistUpdate
set tags+=/home/feng/.vim/tags/gtk.ctags
set tags+=/home/feng/.vim/tags/python.ctags
if has("autocmd")
filetype plugin indent on
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType ruby set omnifunc=rubycomplete#Complete
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType ada set omnifunc=adacomplete#Complete
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType sql set omnifunc=sqlcomplete#Complete
endif

function! Smart_TabComplete()
let line = getline('.') " curline
let substr = strpart(line, -1, col('.')+1) " from start to cursor
let substr = matchstr(substr, "[^ \t]*$") " word till cursor
if (strlen(substr)==0) " nothing to match on empty string
return "\"
endif
let has_period = match(substr, '\.') != -1 " position of period, if any
let has_slash = match(substr, '\/') != -1 " position of slash, if any
if (!has_period && !has_slash)
return "\\" " existing text matching
elseif ( has_slash )
return "\\" " file matching
else
return "\\" " plugin matching
endif
endfunction

inoremap =Smart_TabComplete()

"Tlist
"noremap :Tlist
"inoremap :Tlist
nnoremap :Tlist
"快速保存
nmap w :w!
"快速重载.vimrc
"map s :source ~/.vimrc
"快速编辑.vimrc
map e :e! ~/.vimrc
"当.vimrc改变时,自动重载
autocmd! bufwritepost vimrc source ~/.vimrc
"Paste toggle - when pasting something in, don't indent.
set pastetoggle=
"去除空行
map :%s/\s*$//g:noh''
"Super paste
inoremap :set pastemui+mv'uV'v=:set nopaste
"切换Tab
map tn :tabnew %
map te :tabedit
map tc :tabclose
map tm :tabmove
"切换buffer
map bn :bnext
map bp :bprevious
if has("autocmd")
filetyp plugin indent on
autocmd FileType python setlocal et | setlocal sta | setlocal sw=4
autocmd FileType python compiler pyunit
autocmd FileType python setlocal makeprg=python\ %
endif
"快速运行
au FileType python map :w!:!python %
au FileType python map :w!:!python -m pdb %
"快速补全
au FileType python inoremap $r return
au FileType python inoremap $s self
au FileType python inoremap $c ####kla
au FileType python inoremap $i import
au FileType python inoremap $p print
au FileType python inoremap $d """"""O
" FencView
let g:fencview_autodetect=0

2011年2月20日星期日

wallproxy配置备注

环境:arch 2.6.37, python 2.7, wallproxy v038

安装参照了 http://code.google.com/p/wallproxy/wiki/wallproxyV038

使用时出现以下问题:

Exception happened during processing of request from ('127.0.0.1', 41862)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 582, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 639, in __init__
self.handle()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 337, in handle
self.handle_one_request()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 325, in handle_one_request
method()
File "proxy.py", line 196, in do_METHOD
retval, data = handler(proxy, self.path, self.command, self.headers, payload)
File "/opt/wallproxy/local/util.py", line 147, in proxyFetch
data = encrypt(params, server['key'],smode)
File "/opt/wallproxy/local/util.py", line 124, in encrypt
CryptoObj=Wcrypto.Wcrypto(smode)
File "/opt/wallproxy/local/Wcrypto.py", line 80, in __init__
self.initstr(smode)
File "/opt/wallproxy/local/Wcrypto.py", line 144, in initstr
if (keysize>0):return self.init(cipher,mode,keysize,True)
File "/opt/wallproxy/local/Wcrypto.py", line 130, in init
else:raise ImportError('Crypto.Cipher.'+cipher+'no found')
ImportError: Crypto.Cipher.AESno found


解决方法:删除wallproxy安装目录local下的Crypto与_OpenSSL目录(上述目录是提供Windows系统使用的)

2010年12月26日星期日

Handle Carriage Return in ADF OutputText


public class MyLinefeedConverter implements javax.faces.convert.Converter
{
public MyLinefeedConverter() {
}

public Object getAsObject(FacesContext context, UIComponent component, String value) {
return value;
}

public String getAsString(FacesContext context, UIComponent component, Object value) {
if (value==null) return "";
if (value instanceof String) return ((String)value).replace("\n", "");
return value.toString();
}
}

2010年12月21日星期二

PAC 文件示例

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//!!!注意:
// 1. 编辑脚本的时候一定要小心,一点点错误就会导致浏览器不能正常上网!!!
// 2. 注释符号是: /* 被注释掉的 */ 或两个斜杠//
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


function FindProxyForURL(url, host)
{
url = url.toLowerCase(); //这里把网址转成小写,所以下面填匹配地址时也要用小写。
host = host.toLowerCase(); //这里把网站主机域名转为小写。
proxy-gap="PROXY localhost:8000" //这里是GAPPPROXY的代理地址,还可以定义其它的代理,注意PROXY几个字要大写。

//经过代理的网站
if(shExpMatch(host, "*my.opera.com*")) return proxy-gap; //这里return后面的部分是使用的代理,前面"*my.opera.com*"就是使用代理的网站主机域名(也可以用ip+子网掩码),可以用通配符*。
else if(shExpMatch(host, "*.wikipedia.org*")) return proxy-gap; //另外一个用代理的站点
else if(shExpMatch(url, "*.*blog*.com/*")) return proxy-gap; //也可以匹配具体网页,注意前面要用url而不是host了。
else return "DIRECT"; //其它网站不用代理
}


在opera的菜单中选中 工具 - 首选项 - 网络 - 代理服务器,将pac文件的路径写在最下面的pac地址中,注意写法是 file://xxx 的形式

参考了:danei's blog

2010年6月28日星期一

Linux三两地

今天在ARCH上新装了gnome 2.30,原本是为了试用一下gnome-shell,结果效果不太令人满意,可能是Mutter还不够成熟的原因。
另外又折腾了一下flash的中文问题,将/etc/rc.conf的local设为"zh_CN.UTF-8"时,一切中文显示正常,但是当local="en_US.utf-8"时,flash发生丟字现象,网页等中文正常,用网上流传的"rm /etc/fonts/49-sansserif.conf"不起作用,最后在/etc/profile增加LC_CTYPE="zh_CN.UTF-8"解决问题。

2010年6月25日星期五

Flow ,Discrete & Process manufacturing in ERP

在ERP中,制造行为一般可分为以下几类:

  • 流水线(Flow manufacturing)
  • 离散制造(Discrete manufacturing)
  • 过程制造(Process manufacturing)
to be continued...

2010年3月30日星期二

ORACLE XE on Arch Linux

`yaourt -S oracle-xe` got ERROR: oracle-xe-univ-10.2.0.1-1.0.i386.rpm was not found in the build directory and is not a proper URL.

It seem that oracle-xe source was broken in PKGBUILD, fixed by three steps:

1. download oracle-xe-univ-10.2.0.1-1.0.i386.rpm from Oracle website.
2. `Python -m SimpleHTTPServer`.
3. changed the 'source' line in PKGBUILD as : source=(http://localhost:8000/oracle-xe-univ-10.2.0.1-1.0.i386.rpm)

2009年4月12日星期日

while i=`line`与while read i的区别


a)
while i=`line`
do
echo "i is set to $i"
done < my_file

b)
while read i
do
echo "i is set to $i"
done < my_file

there are a few differences. e.g., try inputting a line
ending with backslash ("\"), such as:

first line \
second line

the read i version reads both lines into one instance of
$i (sans the escaping backslash: "first line second line").
but the `line` version executes twice, first reading the
backslash-ending line (with the backslash) into an instance
of $i ("first line \"), and the second time 'round the loop
the subsequent line into $i ("second line").

another difference: leading spaces/tabs are stripped in
the read i version (at least in some versions of various
shells; i cannot recall if all shells have always done this
or not).

refers to Heiner Steven's unix shell threads

2009年3月10日星期二

GTK+界面无法激活FCITX

升级ibus至1.1版本后无法启动。运行ibus-setup报以下错误

Traceback (most recent call last):
File "/usr/share/ibus/setup/main.py", line 359, in
Setup().run()
File "/usr/share/ibus/setup/main.py", line 77, in __init__
self.__init_ui()
File "/usr/share/ibus/setup/main.py", line 90, in __init_ui
self.__config = self.__bus.get_config()
AttributeError: 'Bus' object has no attribute 'get_config'

没办法,从fcitx svn上check了源码(3.6.0RC),打了了一个deb包。安装过程参照了英文Locale下使用中文输入法
, 重启X后, 发现所有的GTK程序无法用激活fcitx, 一番折腾后, 貌似XIM找不到正确的gtk.immodules配置文件引起的。解决办法:
1. gtk-query-immodules-2.0 > ~/.gtk-2.0/gtk.immodules
2. 在.profile文件里增加一行: export GTK_IM_MODULE_FILE=~/.gtk-2.0/gtk.immodules
3. 编辑/etc/X11/Xsession.d/95xinput

#!/bin/bash
export XMODIFIERS="@im=fcitx"
export XIM=fcitx
export XIM_PROGRAM=fcitx
export GTK_IM_MODULE="xim"
export QT_IM_MODULE="xim"
fcitx

4. 注意"xim"大小写要与~/.gtk-2.0/gtk.immodules里一致

2009年3月3日星期二

从源码编译fcitx的DEB包

sudo apt-get build-dep fcitx
svn checkout http://fcitx.googlecode.com/svn/trunk/ trunk
svn export trunk fcitx
cd fcitx
./autogen.sh
fakeroot dpkg-buildpackage -b

2009年2月26日星期四

今天碰到一个MIME问题,在ROX中(nautilus, thunar中正常),.doc(MS-Word)被识别被text/plain,导致我在为其他文本文件如.txt设置set run action: xterm -e vi "$@"后,.doc文件也会用vi打开。用MIME-Editor发现text/plain中包含了.doc文件类型。
以'su'编辑/usr/share/mime/globs文件,删除行 text/plain:*.doc
问题就解决了。

2009年2月24日星期二

XToolkit on Solaris/Linux

Starting with release J2SETM 5.0, AWT has been re-implemented on the Solaris and Linux platforms. The new Toolkit implementation provides the following advantages:
  • Removes the dependency on Motif and Xt libraries.
  • Interoperates better with other GUI Toolkits.
  • Provides better performance and quality.

The new Toolkit (XToolkit) is the default on Linux in J2SE 5.0. Solaris will continue to use the MToolkit (Motif-based Toolkit) as the default in J2SE 5.0, but eventually will be replaced with XToolkit.

Explicitly Setting the Toolkit

You can explicitly set the toolkit for an applet or application using an environment variable or a system property. Keep in mind that the environment variable overrides the system property.

  • Setting the toolkit for an application:

    • Using an environment variable. This needs to be set before starting the VM.
       csh:
      setenv AWT_TOOLKIT XToolkit #selects the XToolkit
      setenv AWT_TOOLKIT MToolkit #selects the MToolkit

      ksh/bash:
      export AWT_TOOLKIT=XToolkit
      export AWT_TOOLKIT=MToolkit

    • Using a system property on the command line:
       java -Dawt.toolkit=sun.awt.X11.XToolkit MyApp
      java -Dawt.toolkit=sun.awt.motif.MToolkit MyApp
  • Setting the toolkit for an applet:

    • Using an environment variable.

      If the browser is started from a terminal window, the environment variable must be set in the terminal window before launching the browser. If the browser is launched from a desktop icon or menu, the toolkit for an applet can't be set using an environment variable. The Java Plug-in Control Panel should be used instead.

    • Using the Plug-in Control Panel:

      • Launch the Java Plug-in Control Panel:
        $java_home/bin/ControlPanel

      • Add the system property to the Java Runtime Parameters field under the Advanced tab.
        -Dawt.toolkit=sun.awt.X11.XToolkit
        -Dawt.toolkit=sun.awt.motif.MToolkit

2009年2月7日星期六

N70 with Ubuntu

以下命令必须以"su"身份执行

1)检测手机:

# obexftp -u

输出:
Found 2 USB OBEX interfaces
Interface 0:
Manufacturer: Nokia
Product: Nokia N70
Interface description: SYNCML-SYNC
Interface 1:
Manufacturer: Nokia
Product: Nokia N70
Interface description: PC Suite Services
Use '-u interface_number' to connect
Nothing to do. Use --help for help.

接口1将N70作为一个文件服务器提供出来。

2)查看内存卡内容

# sudo obexftp -u 1 -v -l

以上命令查看有几个分区, 一般是C:和E:两个分区
# sudo obexftp -u 1 -v -l C:/Nokia/
3)创建目录
# obexftp -u 1 -v -C E:/Songs

4)上传多个文件

# obexftp -u 1 -v -c E:/Songs -p $HOME/Songs/*.mp3

5) 删除一个目录

# obexftp -u 1 -v -k E:/Songs

thanks to stylesen's Nokia N70 with Debian Etch!

N70 Formatting

前段时间我的Nokia N70几乎收不到短信,先用*#7780#(手机软复位,保留联系人、通话记录等)无效;后用*#7370#(恢复原厂设置),原始密码12345,恢复正常。*恢复前备份通信录

2009年2月3日星期二

Balsamiq Mockups: a great web UI mockup tool

在闲逛Fenng Blog的时候发现了他推荐的这个Web原型界面设计工具,试用之下,感觉非常称手,推荐一下。

我用Linux版本画了一张很随意的界面图

功能和亮点:
  1. 操作方面,拖拽,控件分组,甚至元素之间的对齐都做得很贴心;
  2. 预制了很多界面元素,从简单的输入框,下拉框,浏览器主要元素,到经常用得到的导航条,日历,表格,到复杂的Tag Cloud,Cover Flow, 地图,WYSWYG的格式工具栏等,有了这些不用从头画起,往往比用白板都快;
  3. 界面元素的修改很简单,比如导航条的几个标签页的label,就是用逗号分隔的文字,下拉框的选项就是分行的文字;
  4. 使用xml语言来记录和保存界面元素和布局,
    1. 这使得每个设计都能被很好得放进SVN,Git,和CVS等工具中进行管理和跟踪;
    2. 可以设计复杂的界面元素,保存后,以后可以重复使用(包括修改);
  5. 可以将设计导出成PNG格式的图片;
  6. 可以用命令行进行导出操作,这样就能让我写个脚本,从svn里checkout某个目录下的所有设计文件后,导出图片,打包后用邮件发到项目经理,工程师甚至客户那;
  7. 跨平台,Balsamiq Mokups是用Flex和Air实现的,所以在Mac OS, Linux和Windows下都能使用;
  8. 不仅仅有桌面版本,还有能集成在Confluence,JIRA,和XWiki中的版本,使得异地在线协作更方便有效;
试用版本功能有局限性,不能保存文件或导出为图片。

总体而言作者要价$79还是比较公道的。

用import多次截屏后出现崩溃

用import多次截屏后出现崩溃,Session自动重启,原因不明。
改用scrot, 暂时没出问题。唯一不便的是执行scrot命令后,鼠标形状没有变化,这一点import做得好一点。

#!/bin/bash
# my screenshot script

TODAY=`date '+%Y%m%d'`
NOW=`date '+%H-%M-%S'`
FNAME=screenshot-${NOW}
EXT=png

SCRDIR=${HOME}/Pictures/screenshot/${TODAY}/
if [ ! -d "${SCRDIR}" ]; then
mkdir -p "${SCRDIR}"
fi

# 延时4秒
# sleep 4

#import -window root "$HOME/Desktop/${FNAME}.${EXT}"
#import "${SCRDIR}${FNAME}.${EXT}"
scrot -s "${SCRDIR}${FNAME}.${EXT}"

2009年1月9日星期五

借低俗的名义

牛博被封,实在是意料之中。不过倒省了一笔宣传费

2009年1月4日星期日

删除本地资源的SVN配置信息

cd $TargetDir && find . -name .svn -type d -print0 | xargs -0 rm -rf
Find directories named .svn in or below the current directory and delete them, processing filenames in such a way that file or directory names containing spaces or newlines are correctly handled.