Recently in Linux秘技 Category

Rules[1]

  • Board - The board is an 8×8 grid, with alternating black and red squares, called a checkerboard (in the U.S., in reference to its checkered pattern, also the source of the name checkers). The playable surface consists of the 32 dark squares only. A consequence of this is that, from each player's perspective, the left and right corners encourage different strategies.
  • Pieces - The pieces are usually made of wood and are flat and cylindrical. They are invariably split into one darker and one lighter color. Traditionally, these colors are red and white. There are two kinds of pieces: "men" and "kings". Kings are differentiated as consisting of two normal pieces of the same color, stacked one on top of the other. Often indentations are added to the pieces to aid stacking.
  • Starting Position - Each player starts with 12 pieces on the three rows closest to their own side, as shown in the diagram. The row closest to each player is called the "crownhead" or "kings row". The black (darker color) side moves first.
  • How to Move - There are two ways to move a piece: simply sliding a piece diagonally forwards (also diagonally backwards in the case of kings) to an adjacent and unoccupied dark square, or "jumping" one of the opponent's pieces. In this case, one piece "jumps over" the other, provided there is a vacant square on the opposite side for it to land on. Again, a man (uncrowned piece) can only jump diagonally forwards, and a king can also move diagonally backwards. A piece that is jumped is captured and removed from the board. Multiple-jump moves are possible if, when the jumping piece lands, there is another piece that can be jumped. Jumping is mandatory and cannot be passed up to make a non-jumping move, nor can fewer than the maximum jumps possible be taken in a multiple-jump move. When there is more than one way for a player to jump, one may choose which sequence to make, not necessarily the sequence that will result in the most amount of captures. However, one must make all the captures in that sequence. (Under traditional draughts rules jumping is not mandatory. If it is not done, the opponent may either force the move to be reversed, huff the piece or carry on regardless.)
  • Kings - If a player's piece moves into the kings row on the opposing player's side of the board, that piece is said to be "crowned" (or often "kinged" in the U.S.), becoming a "king" and gaining the ability to move both forwards and backwards. If a player's piece jumps into the kings row, the current move terminates; having just been crowned, the piece cannot continue on by jumping back out (as in a multiple jump), until the next move.
  • How the Game Ends - A player wins by capturing all of the opposing player's pieces, or by leaving the opposing player with no legal moves.

Compiling

Run command "make" to compiling. The main executable file is "ponder".

Playing

The below chart show the user interface of the Ponder engine. This is the official game board of American checkers game, 8x8 size. The squares are marked from "1" to "32" at the lower left.

$ ponder
  +---+---+---+---+---+---+---+---+
  |   |(w)|   |(w)|   |(w)|   |(w)|
  +---+32-+---+31-+---+30-+---+29-+
  |(w)|   |(w)|   |(w)|   |(w)|   |
  +28-+---+27-+---+26-+---+25-+---+
  |   |(w)|   |(w)|   |(w)|   |(w)|
  +---+24-+---+23-+---+22-+---+21-+
  | \ |   | \ |   | \ |   | \ |   |
  +20-+---+19-+---+18-+---+17-+---+
  |   | \ |   | \ |   | \ |   | \ |
  +---+16-+---+15-+---+14-+---+13-+
  |(b)|   |(b)|   |(b)|   |(b)|   |
  +12-+---+11-+---+10-+---+9--+---+
  |   |(b)|   |(b)|   |(b)|   |(b)|
  +---+8--+---+7--+---+6--+---+5--+
  |(b)|   |(b)|   |(b)|   |(b)|   |
  +4--+---+3--+---+2--+---+1--+---+
;[FEN "B:W21,22,23,24,25,26,27,28,29,30,31,32:B1,2,3,4,5,6,7,8,9,10,11,12"]
  *** Black ***
  • (b) indecate a black man
  • (B) indicate a black king
  • (w) indicate a white man
  • (W) indicate a white king
  •  \  indicate an unoccupied dark square

Move a piece by type the starting square and the destination square with a dash between them.

;[FEN "B:W21,22,23,24,25,26,27,28,29,30,31,32:B1,2,3,4,5,6,7,8,9,10,11,12"]
+---+---+---+---+---+---+---+---+
| |(w)| |(w)| |(w)| |(w)|
+---+32-+---+31-+---+30-+---+29-+
|(w)| |(w)| |(w)| |(w)| |
+28-+---+27-+---+26-+---+25-+---+
| |(w)| |(w)| |(w)| |(w)|
+---+24-+---+23-+---+22-+---+21-+
| \ | | \ | | \ | | \ | |
+20-+---+19-+---+18-+---+17-+---+
| | \ | | \ | | \ | | \ |
+---+16-+---+15-+---+14-+---+13-+
|(b)| |(b)| |(b)| |(b)| |
+12-+---+11-+---+10-+---+9--+---+
| |(b)| |(b)| |(b)| |(b)|
+---+8--+---+7--+---+6--+---+5--+
|(b)| |(b)| |(b)| |(b)| |
+4--+---+3--+---+2--+---+1--+---+
*** Black ***
10-14
;[FEN "W:W21,22,23,24,25,26,27,28,29,30,31,32:B1,2,3,4,5,6,7,8,9,11,12,14"]
+---+---+---+---+---+---+---+---+
| |(w)| |(w)| |(w)| |(w)|
+---+32-+---+31-+---+30-+---+29-+
|(w)| |(w)| |(w)| |(w)| |
+28-+---+27-+---+26-+---+25-+---+
| |(w)| |(w)| |(w)| |(w)|
+---+24-+---+23-+---+22-+---+21-+
| \ | | \ | | \ | | \ | |
+20-+---+19-+---+18-+---+17-+---+
| | \ | | \ | |(b)| | \ |
+---+16-+---+15-+---+14-+---+13-+
|(b)| |(b)| | \ | |(b)| |
+12-+---+11-+---+10-+---+9--+---+
| |(b)| |(b)| |(b)| |(b)|
+---+8--+---+7--+---+6--+---+5--+
|(b)| |(b)| |(b)| |(b)| |
+4--+---+3--+---+2--+---+1--+---+

While capture a piece, use character "x" instead of dash.

;[FEN "B:W15,21,22,24,25,26,27,28,29,30,31,32:B1,2,3,4,5,6,8,9,10,11,12,14"]
+---+---+---+---+---+---+---+---+
| |(w)| |(w)| |(w)| |(w)|
+---+32-+---+31-+---+30-+---+29-+
|(w)| |(w)| |(w)| |(w)| |
+28-+---+27-+---+26-+---+25-+---+
| |(w)| | \ | |(w)| |(w)|
+---+24-+---+23-+---+22-+---+21-+
| \ | | \ | | \ | | \ | |
+20-+---+19-+---+18-+---+17-+---+
| | \ | |(w)| |(b)| | \ |
+---+16-+---+15-+---+14-+---+13-+
|(b)| |(b)| |(b)| |(b)| |
+12-+---+11-+---+10-+---+9--+---+
| |(b)| | \ | |(b)| |(b)|
+---+8--+---+7--+---+6--+---+5--+
|(b)| |(b)| |(b)| |(b)| |
+4--+---+3--+---+2--+---+1--+---+
*** Black ***
11x18
;[FEN "W:W21,22,24,25,26,27,28,29,30,31,32:B1,2,3,4,5,6,8,9,10,12,14,18"]
+---+---+---+---+---+---+---+---+
| |(w)| |(w)| |(w)| |(w)|
+---+32-+---+31-+---+30-+---+29-+
|(w)| |(w)| |(w)| |(w)| |
+28-+---+27-+---+26-+---+25-+---+
| |(w)| | \ | |(w)| |(w)|
+---+24-+---+23-+---+22-+---+21-+
| \ | | \ | |(b)| | \ | |
+20-+---+19-+---+18-+---+17-+---+
| | \ | | \ | |(b)| | \ |
+---+16-+---+15-+---+14-+---+13-+
|(b)| | \ | |(b)| |(b)| |
+12-+---+11-+---+10-+---+9--+---+
| |(b)| | \ | |(b)| |(b)|
+---+8--+---+7--+---+6--+---+5--+
|(b)| |(b)| |(b)| |(b)| |
+4--+---+3--+---+2--+---+1--+---+

Use "help" or "?" in the game engine to show the help information.

help
? Show this help information.
analyze Engine thinks about what move it make next if it were on
move.
black Set Black on move, and the engine will play White.
force Set the engine to play neither color ("force mode").
go Leave force mode and set the engine to play the color that
is on move. Start thinking and eventually make a move.
help Show this help information.
history Show the record of moves.
new Reset the board to the standard starting position.
ping N N is a decimal number. Reply by sending the string
"pong N"
print Show the current board.
quit Quit this program.
rotate Rotate the board 180 degrees.
setboard FEN Set up the pieces position on the board.
sd DEPTH The engine should limit its thinking to DEPTH ply.
st TIME Set the time control to TIME seconds per move.
undo Back up a move.
verbose Toggle verbose mode.
white Set White on move, and the engine will play Black.

Source Code

You can download the source code of Ponder, the American checkers engine from Mamiyami Web site.

Copyrights

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

狂写 bash 脚本数日,偶有所得。

Usually, we use [ -n "$VAR" ] to check if a shell variable contain non null string. But bash man page does not describe how to check if a shell variable is set or not.

After some search and investigation, I got the following missing bash manual

Parameter Expansion

${parameter-word}
Use Default Values. If parameter is unset, the expansion of word
 is substituted. Otherwise, the value of parameter is substituted.
${parameter=word}
Assign Default Values. If parameter is unset, the expansion of
 word is assigned to parameter. The value of parameter is then
 substituted. Positional parameters and special parameters may not
 be assigned to in this way.
${parameter?word}
Display Error if Unset. If parameter is unset, the expansion of
 word (or a message to that effect if word is not present) is
 written to the standard error and the shell, if it is not
 interactive, exits. Otherwise, the value of parameter is
 substituted.
${parameter+word}
Use Alternate Value. If parameter is unset, nothing is
 substituted, otherwise the expansion of word is substituted.

Some section in bash man page for reference

${parameter:-word}
Use Default Values. If parameter is unset or null, the expansion
 of word is substituted. Otherwise, the value of parameter is
 substituted.
${parameter:=word}
Assign Default Values. If parameter is unset or null, the
 expansion of word is assigned to parameter. The value of
 parameter is then substituted. Positional parameters and special
 parameters may not be assigned to in this way.
${parameter:?word}
Display Error if Null or Unset. If parameter is null or unset,
 the expansion of word (or a message to that effect if word is not
 present) is written to the standard error and the shell, if it is
 not interactive, exits. Otherwise, the value of parameter is
 substituted.
${parameter:+word}
Use Alternate Value. If parameter is null or unset, nothing is
 substituted, otherwise the expansion of word is substituted.

Here are some examples

[ -n "${VAR+x}" ]  ## Fails if VAR is unset
[ -n "${VAR:+x}" ] ## Fails if VAR is unset or empty
[ -n "${VAR}" ]    ## Fails if VAR is unset or empty
[ -n "${VAR-x}" ]  ## Succeeds if VAR is unset
[ -n "${VAR:-x}" ] ## Succeeds if VAR is unset or empty
[ -z "${VAR}" ]    ## Succeeds if VAR is unset or empty

蝈蝈死掉了

| | Comments (1) | TrackBacks (0)

蝈蝈死掉了。一共养了一百八十六天。

***** 552 ** pts/1 * <neo@zircon> *** ~ *****
$ echo $(( ( $(date -d 'Jul 23, 2008' +%s) \
> - $(date -d 'Jan 19, 2008' +%s) ) \
> / 86400 ))
186

这个东东实在是太惊人了。它让你在赶往公司的途中,出租车上,火车上,都可以维护自己的服务器,随时随地 SSH 一下。

完整的规格包括支持 SSH1/SSH2/Telnet 协议,可以通过手机键盘输入各种特殊键和组合键,可以移动光标,VT320 终端模拟。这整个软件还是开放源代码并且使用 GPL 协议发布。

说到缺点,手机屏幕上的字实在是太......太小了。当然可以把字体变大,不过这样的话,屏幕上显示的内容就会相应的变少了。通过手机键盘输入命令也非常......非常的让人抓狂,尤其是要输入各种奇怪的标点符号的时候。不过这毕竟是全功能的 SSH 客户端,不佩服一下作者也不行。

详情就请大家自己看图好了,点击看大图。在 Nokia 6275 CDMA 的 QVGA 屏幕上竟然可以显示 80 列 40 行字符呢,真是让人绝倒。

img_1522s.jpg

img_1517s.jpg

使用 vim scp://remoteuser@server.tld//path/to/document 运行 vim。或者在 vim 运行时输入 :e scp://remoteuser@server.tld//path/to/document

Vim 支持通过 dav、fetch、ftp、http、rcp、rsync、scp 或者 sftp 编辑远程文件。

在 Windows 上面使用 gVim

  1. 下载及安装 gVim
  2. 下载及安装 PuTTY
  3. %ProgramFiles%\PuTTY 加入 PATH
  4. 创建 %ProgramFiles%\PuTTY\scp.bat
    @echo off
    pscp.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

参考资料

家里有两台台式机,我一台,爹妈挖地雷一台。我有一台 Apple PowerBook G4,主要通过 Wi-Fi 接入家庭网络。路由器是用一台旧机器自己做的,上面运行 Debian GNU/Linux ,顺便提供提供 DNS、DHCP、NTP、SSH、TOR 服务。一条 2M 的 ADSL 链路提供 7 x 24 的 Internet 接入服务。

2M ADSL 链路所提供的带宽

  • 下行 2Mbps = 250KB/s = 244.141KiB/s
  • 上行 640Kbps = 80KB/s = 78.125KiB/s

设定 QoS

我通常长时间的运行骡子,有时运行 SSH 会话。骡子会消耗大量的带宽,导致网络拥塞。后果是网络传输时延增加,SSH 会话的迟滞很严重,网上冲浪也要花更多时间等待。通过给不同的网络流量限定带宽和设定优先级,可以有效的改善这些。

胡乱设定的规则

  1. 第一优先级
    这是需要最小时延的应用
    • ICMP 报文
    • SSH 会话
    • 带有 SYN 标记的 TCP 报文
    • DNS 查询
  2. 第二优先级
    这主要是网上冲浪所产生的流量
    • HTTP 和 HTTPS 会话
    • FTP 的控制连接
  3. 第三优先级
    • 路由器本身产生的流量
  4. 第四优先级
    这是剩下的通过路由器转发,传输大量数据的应用。即时通讯软件所产生的流量也在这里。
    • FTP 的数据连接
    • 所有通过路由器转发的 UDP 流量
  5. 第五优先级
    这是需要最少花费的应用,主要是 Email 产生的流量
    • SMTP
    • POP3
    • IMAP
  6. 第六优先级
    这包括所有剩下的流量。骡子BT 产生的流量都会在这里。

应用 QoS 后获得的好处

  • 可以不用针对骡子特别限速,骡子可以充分利用剩下的带宽,最大化吞吐量。
  • SSH 会话的迟滞显著减少了。
  • 即便网络很繁忙,网上冲浪还是很顺畅。

参考资料

问题

公司内部网络防火墙密布,戒备森严,封锁了一切流向公司外部的网络流量。访问外部的网络,唯有透过 HTTP 代理服务。

解决方案

透过 HTTP CONNECT 方法可以达成目的。

+--------+          +--------+  +----------+                         +--------+
| ssh | | proxy | | router/ | | ssh |
| client | | server | | firewall | __ __ | server |
|+------+| | | | | _/ \/ \_ | |
||ssh- || https |+------+| | | / \ ssh |+------+|
||https-|===========>|squid |===> -> -> -> ===| Internet |=========>| sshd ||
||tunnel|| port 80 |+------+| | | \_ _/ port 22 |+------+|
|+------+| or 3128 | | | | \__/\__/ or 443 | |
+--------+ or 8080 +--------+ +----------+ +--------+

Perl 脚本 ssh-https-tunnel 发送 CONNNET 请求到你的代理服务器,指示它打开一个到远程主机端口的 TCP 连接。然后它允许你通过标准输入/标准输出和这个端口通讯。

更新你的 ~/.ssh/config 文件。

Host www.example.com
ProxyCommand ~/.ssh/ssh-https-tunnel %h %p

把你的代理服务设置放在 ssh-https-tunnel 文件中

#### Configuration ####
my $proxy = "my-proxy.company.com";
my $proxy_port = 80;
然后就可以通过 HTTP 代理服务来访问 ssh 了
$ ssh -v www.example.com
OpenSSH_4.3p2 Debian-9, OpenSSL 0.9.8c 05 Sep 2006
debug1: Reading configuration data /home/neo/.ssh/config
debug1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Executing proxy command: exec ~/.ssh/ssh-https-tunnel www.example.com 22
debug1: identity file /home/neo/.ssh/identity type -1
debug1: identity file /home/neo/.ssh/id_rsa type -1
debug1: identity file /home/neo/.ssh/id_dsa type -1
debug1: Remote protocol version 1.99, remote software version OpenSSH_3.5p1
debug1: match: OpenSSH_3.5p1 pat OpenSSH_3.*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3p2 Debian-9
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 zlib
debug1: kex: client->server aes128-cbc hmac-md5 zlib
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'www.example.com' is known and matches the RSA host key.
debug1: Found key in /home/neo/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: Enabling compression at level 6.
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
neo@www.example.com's password:
debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Requesting X11 forwarding with authentication spoofing.
debug1: Requesting authentication agent forwarding.
debug1: Sending environment.
debug1: Remote: No xauth program; cannot forward with spoofing.
[neo@www neo]$

出问题的是 Red Hat Enterprise Linux 4 Update 2 for i386。这个发行版里面附带的单处理器版本内核不能驱动第二块 BCM5700 网卡。

BCM5700 是千兆以太网卡,使用 tg3.ko 这个内核模块。

假若机器上面有一个处理器,有两个 BCM5700 网卡。在这种情况下 Red Hat 的安装程序会自动帮你安装单处理器版本的内核。在第二个 RJ45 接口上插好网线,给 eth1 配置一个 IP 地址让它运转起来。最终会发现 eth1 实际上是不能工作的。

mii-tool 会回报说 eth1 接口上“link ok”,但是 ethtool 会抱怨说 eth1 接口上Link detected: no”。当然实际的情况是网线好好的插在接口上,而 Red Hat 附带的内核是烂的。

迂回的解决方法就是换上 SMP 版本的内核。当然这会略微损失运转的效率。

在 Red Hat Enterprise Linux 4 Update 3 x86_64 上面安装 Oracle Enterprise Edition for x86_64 Linux 10g R2 的时候,就出现了这个破东东。当然安装过程就意外终止啦。

错误出现的位置就是在安装快要完成,ld 正在拼命进行最后的连接工作的时候。

根据 google 到的各种攻略,这个错误是说某个正在工作中的进程意外终止了。与它协同工作的进程突然失去联系,就会抱怨这个错误。

经过不断的 google ,在破碎的连接器输出和安装日志中爬行……最终发现……

要安装 64-bit 版本的 libaio 。

这应该算作是 Red Hat 安装程序的缺陷。Red Hat 安装程序本该装好 64-bit 版本 libaio 的。可是实际上只安装了 32-bit 版本的 libaio ,没有安装64-bit 版本。

http://ora-12547.ora-code.com/

~~~snip~~~
Jun 1 01:38:19 alum pppd[5541]: pppd 2.4.3 started by root, uid 0
Jun 1 01:38:22 alum hcid[3299]: link_key_request (sba=00:0D:93:0F:FB:D4, dba=00:14:A7:FE:AA:23)
Jun 1 01:38:23 alum chat[5543]: report (CONNECT)
Jun 1 01:38:23 alum chat[5543]: abort on (BUSY)
Jun 1 01:38:23 alum chat[5543]: abort on (VOICE)
Jun 1 01:38:23 alum chat[5543]: abort on (NO CARRIER)
Jun 1 01:38:23 alum chat[5543]: abort on (NO DIALTONE)
Jun 1 01:38:23 alum chat[5543]: abort on (NO DIAL TONE)
Jun 1 01:38:23 alum chat[5543]: send (AT&F+CRM=1;+CSO=33;^M)
Jun 1 01:38:23 alum chat[5543]: expect (OK)
Jun 1 01:38:23 alum chat[5543]: AT&F+CRM=1;+CSO=33;^M^M
Jun 1 01:38:23 alum chat[5543]: OK
Jun 1 01:38:23 alum chat[5543]: -- got it
Jun 1 01:38:23 alum chat[5543]: send (ATDT#777^M)
Jun 1 01:38:23 alum chat[5543]: expect (CONNECT)
Jun 1 01:38:23 alum chat[5543]: ^M
Jun 1 01:38:29 alum chat[5543]: ATDT#777^M^M
Jun 1 01:38:29 alum chat[5543]: CONNECT
Jun 1 01:38:29 alum chat[5543]: -- got it
Jun 1 01:38:29 alum chat[5543]: send (^M)
Jun 1 01:38:29 alum pppd[5541]: Serial connection established.
Jun 1 01:38:29 alum pppd[5541]: Using interface ppp0
Jun 1 01:38:29 alum pppd[5541]: Connect: ppp0 <--> /dev/rfcomm0
Jun 1 01:38:30 alum pppd[5541]: PAP authentication succeeded
Jun 1 01:38:31 alum pppd[5541]: Cannot determine ethernet address for proxy ARP
Jun 1 01:38:31 alum pppd[5541]: local IP address 220.205.156.190
Jun 1 01:38:31 alum pppd[5541]: remote IP address 220.192.0.11
Jun 1 01:38:31 alum pppd[5541]: primary DNS address 220.192.0.130
Jun 1 01:38:31 alum pppd[5541]: secondary DNS address 220.192.8.58
~~~snip~~~

About this Archive

This page is a archive of recent entries in the Linux秘技 category.

办公室英文 is the next category.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.12