Saturday, April 19, 2008

wine强制全屏游戏在窗口模式下运行

wine explorer /desktop=1024x768 whatever.exe

...
Read More

Monday, April 7, 2008

用psyco优化python程序

psyco是python的一个扩展,它通过编译python代码来提升python程序的速度。

使用的方法很简单,在python程序里加上下面两句就可以了:

import psyco
psyco.full()

psyco会在程序运行时编译部分代码(具体怎么编译还不清楚),因此程序的初始化时间会增加,但运行速度会变快。

这里有一篇gentoo-wiki介绍用psyco优化portage速度的:

http://gentoo-wiki.com/TIP_Speed_up_portage_with_Psyco

这篇文章中说,用了psyco以后,portage性能可以提升2-5倍,不过同时也警告说psyco现在还不稳定,可能会带来很多问题,因此不推荐使用。

我试了一下,用了psyco的emerge速度快多了(看来2-5倍不是吹的),有一些不影响使用的小问题,比如没有用sudo的emerge会抛异常、确认删除时选“no”也会抛异常。我猜测这都是因为psyco对try-except语句支持得不好,原来的程序里catch住的异常现在引发了psyco的新异常。

不过这些问题都不影响正常使用。继续观望。

另外,有些别的python程序原生支持psyco,像Frets On Fire,我看了它的源码,它会初试使用psyco。我装了psyco以后再玩Frets On Fire,感觉快了一点,不过没有portage那么明显。

...
Read More

Friday, April 4, 2008

HOWTO XDMCP in Gnome

XDMCP stands for "X Display Manager Control Protocol" and is a network protocol. It allows a way of running X-Terminal on your PC (or Mac) and uses the X Server to provide a client/server interface between display hardware (the mouse, keyboard, and video displays) and the desktop environment while also providing both the windowing infrastructure and a standardized application interface. The X-Terminal can be displayed with an individual window or multiple windows, based on your X window system's software capabilities and setup.


On your X-Server, you must tweak the configuration of your graphical login manager (displaymanager).

for GDM, you need to change the [xdmcp]-section in your configfile:
/etc/X11/gdm/custom.conf

[xdmcp]
Enable=true

Depending on how your gdm.conf/custom.conf is set up, you might also need to add or change the [greeter] section as shown below. Without this, you will not be able to XDMCP in to your server.

[greeter]
Browser=true


How to use XDMCP

on the remote machine you can either use Xnest or simply X:
$ X -ac -query servername :1
or
$ Xnest -ac -query servername :1

where servername is your servername or IP. :1 is the display number. (:0 should be your running X-Server)

To change screen resolution of Xnest, use "geometry" option:
$ Xnest -geometry=1280x800 -ac -query servername :1

...
Read More

Sunday, March 30, 2008

用Python删除Eclipse的旧插件

Eclipse升级插件以后似乎没有办法删除旧版本的插件。

于是我写了个python脚本清除旧插件。

import os
import glob

def removeOldFiles(dir):
  os.chdir(dir)
  files = glob.glob('*')
  files.sort()
  prevfile = files[0]
  for filename in files[1:]:
    if (filename.find(prevfile.partition('_')[0]) == 0):
      os.system('rm -rf ' + prevfile)
    prevfile = filename

# main
removeOldFiles('/usr/lib/eclipse-3.3/plugins')
removeOldFiles('/usr/lib/eclipse-3.3/features')


...
Read More

Friday, March 28, 2008

Java程序和X程序无法调用scim输入的解决办法

最近发现Java程序都无法输入中文,按ctrl+space不弹出scim。

然后发型纯X程序(像xterm)也是一样的症状,而gtk和qt程序则没问题。

上网查了一下,了解到java程序和x程序一样是用xim引擎进行输入的,而qt/gtk是用scim,因此觉得是配置文件写错了。

检查了一下/etc/X11/xinit/xinitrc.d/xinputrc文件,果然把XMODIFIERS一行写成小写@im=scim了,而这是大小写敏感的。现在正确的内容如下:

XMODIFIERS=@im=SCIM
XIM="scim"
XIM_PROGRAM="scim"
XIM_ARGS="-d"
GTK_IM_MODULE="scim"
QT_IM_MODULE="scim"

export XIM XIM_PROGRAM XMODIFIERS GTK_IM_MODULE QT_IM_MODULE

# start xim server
$XIM_PROGRAM $XIM_ARGS &

...
Read More

Tuesday, March 25, 2008

Programmer's Fonts

Programmers have very particular font needs. A font for programming must be monospaced, extremely readable, and must sharply distinguish between similar characters, such as capital O and zero and the number 1, capital I, and lowercase l. In addition, good programming fonts allow you to view more lines of code on screen at once.

You can find many programmer's fonts at this website:
http://www.lowing.org/fonts/

view the sample of the fonts

...
Read More

Thursday, March 20, 2008

HOWTO Highlight C++/Java/TeX source code syntax in LaTeX

There is a greate package which supports syntax highlighting for a huge amount of programming languages (Fortran, C, C++, csh, HTML, Java, Matlab, Mathematica, Pascal, Perl, SQL, XML, Delphi, PHP, VBScript, SAS and even Latex itself - and many more). The usage is simple: 
Load the package: \usepackage{listings} 
Set the language: \lstset{language=TeX} 
Open a lstlisting environment: \begin{lstlisting} 
Include all your programming code 
Close the lstlisting environment: \end{lstlisting} 

If this does not seem to work for your language, even if the language is listed above, try upgrading to the lastest MiKTeX version. The listings package is being updated continuously. 

Here's a more advanced example on the source code highlight: 
 \usepackage{color}
 \usepackage{listings}
 \definecolor{Brown}{cmyk}{0,0.81,1,0.60}
 \definecolor{OliveGreen}{cmyk}{0.64,0,0.95,0.40}
 \definecolor{CadetBlue}{cmyk}{0.62,0.57,0.23,0}
 \begin{document}
 
 \lstset{language=R,frame=ltrb,framesep=5pt,basicstyle=\normalsize,
  keywordstyle=\ttfamily\color{OliveGreen},
 identifierstyle=\ttfamily\color{CadetBlue}\bfseries, 
 commentstyle=\color{Brown},
 stringstyle=\ttfamily,
 showstringspaces=ture}

\begin{lstlisting}
...
\end{lstlisting}

...
Read More

HOWTO Editing Gnome/KDE Menus

Introducion

You know the menu that's shown if you start the kde-menu, gnome-menu, xfce-menu or something else. There's no real name for this kind of menu (it's also often called "root-menu"), but the menu is saved in a Freedesktop-Standard. 

Where are the files saved?

The menus are made out of a "Main file" (.menu file). The file is written in XML, and it contains a kind of links to the Applications (.desktop files). 

The Main file detailing system-wide default menu structure might be located in one of the followings directorys: 
/etc/xdg/menus/ 
User-specific menu edits: ~/.config/menus/ 
If you have not found your file yet, search for it: find / -iname *.menu 

System-wide Menu entries (.desktop files) are stored in many places, for example: 
/usr/share/applications/ 
/usr/share/applink/
Gnome applications:
/usr/share/gnome/apps/
KDE applications: 
/usr/kde/3.5/share/applications/
User-specific applications: 
~/.local/share/applications/

Or search for the files: find / -iname *.desktop

...
Read More

Monday, March 17, 2008

HowTo: Mount Bin/Cue files in Linux

* Method 1: Use CDEmu.
cdemu 0 pro.cue
mount -t iso9660 /dev/cdemu/0 /mnt/temp

* Method 2: Convert to ISO.
Convert BIN/CUE to ISO:
bchunk -v acrobat6pro.bin pro.cue pro

* Just mount the ISO by executing as root.
mount -o loop,ro -t iso9660 .iso
mount -o loop pro01.iso /mnt/temp

* Method 3: Use AcetoneISO2.

...
Read More

Saturday, March 15, 2008

【转】JDK6中文乱码完美解决之雅黑版

JDK6在LINUX环境下不支持中文,以下是解决办法。

实验环境:Ubuntu7.04,JDK6
路径说明:1、字体文件路径/usr/share/fonts/yahei/msyh.ttf
2、JAVA_HOME=/usr/lib/jvm/jdk
(请根据你的实际路径修改变命令内容)

解决AWT外的乱码:
1、cd /usr/lib/jvm/jdk/jre/lib/fonts
(进入jre的fonts文件夹)
2、sudo mkdir fallback
(创建文件夹fallback,文件名必须是"fallback",这是设置文件中指定的)
3、cd fallback
(进入fallback文件夹)
4、sudo ln -s /usr/share/fonts/yahei/msyh.ttf
(建立msyh.ttf字体文件的软连接)
5、sudo mkfontscale
(建立fonts.scale文件)
6、sudo mkfontdir
(在fonts.scale的基础上建立fonts.dir文件)

如果使用中不涉及AWT中文显示,问题已解决,针对AWT的乱码问题,必须实施以下步骤:

1、cd /usr/lib/jvm/jdk/jre/lib/fonts
(进入jre的fonts文件夹)
2、sudo cat ./fallback/fonts.dir >> fonts.dir
(把/fallback/fonts.dir的内容添加到fonts.dir文件的结尾,可以手动复制,目的是把雅黑字体的相关内容添加进jre的fonts.dir里)
3、cd ..
(返回上一级目录,即/usr/lib/jvm/jdk/lib)
4、sudo mkdir fontconfigs
(建立fontconfigs文件夹,fontconfigs可以随便命名)
5、sudo mv fontconfig.* ./fontconfigs
(把lib文件夹内的fontconfig开头的文件剪切到fontconfigs文件夹下,因为这些设置文件是应用于不同系统的,按一定顺序查找,如果不把它们移走,不能保证执行我们将要建立的文件fontconfig.properties)
6、sudo gedit fontconfig.properties
(创建并打开文件fontconfig.properties,文件名必须是默认查找顺序列表中的一个,fontconfig.properties就是其中之一)
7、复制以下内容到fontconfig.properties,并保存:


# @(#)linux.fontconfig.Ubuntu.7.04.properties 1.2 07/10/02
#
# Copyright 2007 ganjinghong, Inc. All rights reserved.
#

# Version

version=1

# Component Font Mappings
serif.plain.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
serif.bold.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
serif.italic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
serif.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
sansserif.plain.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
sansserif.bold.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
sansserif.italic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
sansserif.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
monospaced.plain.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
monospaced.bold.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
monospaced.italic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
monospaced.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialog.plain.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialog.bold.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialog.italic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialog.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialoginput.plain.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialoginput.bold.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialoginput.italic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialoginput.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0
dialoginput.bolditalic.chinese-cn=-microsoft-microsoft yahei-medium-r-normal--*-%d-*-*-p-*-gb2312.1980-0

serif.plain.latin-1=-b&h-lucidabright-medium-r-normal--*-%d-*-*-p-*-iso8859-1
serif.bold.latin-1=-b&h-lucidabright-demibold-r-normal--*-%d-*-*-p-*-iso8859-1
serif.italic.latin-1=-b&h-lucidabright-medium-i-normal--*-%d-*-*-p-*-iso8859-1
serif.bolditalic.latin-1=-b&h-lucidabright-demibold-i-normal--*-%d-*-*-p-*-iso8859-1
sansserif.plain.latin-1=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bold.latin-1=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.italic.latin-1=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
sansserif.bolditalic.latin-1=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
monospaced.plain.latin-1=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bold.latin-1=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.italic.latin-1=-b&h-lucidatypewriter-medium-i-normal-sans-*-%d-*-*-m-*-iso8859-1
monospaced.bolditalic.latin-1=-b&h-lucidatypewriter-bold-i-normal-sans-*-%d-*-*-m-*-iso8859-1
dialog.plain.latin-1=-b&h-lucidasans-medium-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bold.latin-1=-b&h-lucidasans-bold-r-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.italic.latin-1=-b&h-lucidasans-medium-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialog.bolditalic.latin-1=-b&h-lucidasans-bold-i-normal-sans-*-%d-*-*-p-*-iso8859-1
dialoginput.plain.latin-1=-b&h-lucidatypewriter-medium-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bold.latin-1=-b&h-lucidatypewriter-bold-r-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.italic.latin-1=-b&h-lucidatypewriter-medium-i-normal-sans-*-%d-*-*-m-*-iso8859-1
dialoginput.bolditalic.latin-1=-b&h-lucidatypewriter-bold-i-normal-sans-*-%d-*-*-m-*-iso8859-1


# Search Sequences

sequence.allfonts=latin-1,chinese-cn

# Exclusion Ranges

# Font File Names

8、无需重启,问题已解决。

其他字体设置方法:
把fontconfig.properties文件中的microsoft-microsoft yahei替换为你所用字体的名称。
TIPS:
1、名称获取方法:可以在字体文件同级目录下执行:sudo mkfontscale,然后打开生成的fonts.scale,里面就有相关的名称。
2、必须把你所用中文字体的fonts.scale的相关内容添加到/lib/fonts/fonts.dir

...
Read More
 
/* google analytics */