OpenSync with Nokia 2730 Classic

My Nokia 2730 classic is found to work with the following configuration file for the SyncML plugin for OpenSync:

<?xml version=”1.0″?>
<config>
<bluetooth_address>XX:XX:XX:XX:XX:XX</bluetooth_address>
<bluetooth_channel>11</bluetooth_channel>
<interface>0</interface>
<identifier>PC Suite</identifier>
<version>1</version>
<wbxml>1</wbxml>
<username></username>
<password></password>
<type>2</type>
<usestringtable>0</usestringtable>
<onlyreplace>0</onlyreplace>
<onlyLocaltime>0</onlyLocaltime>
<recvLimit>0</recvLimit>
<maxObjSize>0</maxObjSize>
<contact_db>Contacts</contact_db>
<calendar_db>Calendar</calendar_db>
<note_db>Notes</note_db>
</config>

For more details see this guide and this HOWTO.

欲與願

欲為人本,得所欲,則身易入安適。願長思於,執其願,則心可恆平定。

『欲』和『願』都是使人作為的動力。不同的是『欲』著於果、著於『得』之予否,而『願』著於因、著於是否『執』之。修為者可以離去『欲』而直接求取『安適』,但如不能長『願』,則人生便是空無罷了。

synchronize work spaces on different machines

While working on a set of files on different machines, it’s a common problem to keep things in sync. A real solution is to use a revision control system (with git being my current favorite). However, a quick fix is to use rsync. Following script tries to figure out which copy of the work space is newer and invokes rsync accordingly.

#!/bin/bash
if (( $# != 3 )); then
echo "Usage: `basename $0` <local file> <remote host> <remote file>"
exit 1;
fi
LOCAL_FILE="$1"
REMOTE_HOST="$2"
REMOTE_FILE="$3"

# make sure directories end with '/'
if [ -d "${LOCAL_FILE}" ]; then
LOCAL_FILE=${LOCAL_FILE%/}/
REMOTE_FILE=${REMOTE_FILE%/}/
echo "sync directory: '`basename ${LOCAL_FILE}`' with ${REMOTE_HOST}"
else
echo "sync file: '`basename ${LOCAL_FILE}`' with ${REMOTE_HOST}"
fi

# find out the last modification time in the entire directory
TM_LOCAL=`if [ -e "${LOCAL_FILE}" ]; then find $LOCAL_FILE -printf "%Ts %Pn"|sort|tail -n1; else echo 0; fi`
TM_REMOTE=`ssh ${REMOTE_HOST} "if [ -e "${REMOTE_FILE}" ]; then find $REMOTE_FILE -printf "%Ts %Pn"|sort|tail -n1; else echo 0; fi" < /dev/null`

echo Local Newest: $TM_LOCAL
echo Remote Newest: $TM_REMOTE
if [[ $TM_LOCAL < $TM_REMOTE ]]; then
echo -n "remote => local"
rsync -auz -e ssh --delete ${REMOTE_HOST}:""${REMOTE_FILE}"" "${LOCAL_FILE}"
echo ", Done!"
elif [[ $TM_LOCAL > $TM_REMOTE ]]; then
echo -n "local => remote"
rsync -auz -e ssh --delete "${LOCAL_FILE}" ${REMOTE_HOST}:""${REMOTE_FILE}""
echo ", Done!"
else
echo "Nothing to do!"
fi

Duplication elimination

In engineering a computation project, one desires a single point of information entry. It’s elegant to come up with coding structures that will facilitate this requirement, that is, a single place in the codes pertinent to the to-be-computed problems. However, while the programming language is an interface between human and machine. It’s not generally friendly to the users. The ultimate way of choice is to have human readable/editable files and make programs to generate corresponding codes when needed.

無我

也許『我』在理論上並不存在,但是在體驗上卻是很真實的。但是『我』的界線在那裡呢?以身體為界在以往也許沒有問題,但是醫學、科技的發展只會讓這個分界愈來愈模糊。甚至以大腦為界也不能恆久。或許有一天,『無我』可能不會只是個玄疑的理論而已…

adding OCR to djvu file

For each page in the file “cake.djvu”, we can use the “tesseract” to process the page image:

djvused -e “select ${page};save-page-with “cake_page.djvu”” cake.djvu
convert cake_page.djvu cake.tif
tesseract cake.tif cake_box batch.nochop makebox
tesseract cake.tif cake_txt batch.nochop

This produces the information for the text structure (lines and words) and positioning (coordinate for each character). To convert this information to the hidden-text format for use with djvused, use

perl<<'EOL'>cake_text.txt
open TXT, "<:utf8", "cake_txt.txt";
open BOX, "<:utf8", "cake_box.txt";
$pxn = 1000000;
$pxx = 0;
$pyn = 1000000;
$pyx = 0;
$pagebuf = "";
while ($line = <TXT>) {
chop $line;
@words = split /s+/, $line;
next if $#words < 0;
$lxn = 1000000;
$lxx = 0;
$lyn = 1000000;
$lyx = 0;
$linebuf = "";
foreach $word (@words) {
$xmin = 1000000;
$xmax = 0;
$ymin = 1000000;
$ymax = 0;
$w = "";
for ($i = 0; $i < length($word); $i ++) {
$c = substr($word, $i, 1);
do {
$cline = <BOX>;
} while (substr($cline, 0, 1) ne $c);
($xn, $yn, $xx, $yx) = substr($cline, 2) =~ /S+/g;
$w = $w . '\' if $c eq '"';
$w = $w . '\' if $c eq '\';
$w = $w . substr($cline, 0, 1);
$xmin = $xn if ($xmin > $xn);
$xmax = $xx if ($xmax < $xx);
$ymin = $yn if ($ymin > $yn);
$ymax = $yx if ($ymax < $yx);
}
$wline = '(word ' . $xmin . ' ' . $ymin . ' ' . $xmax . ' ' . $ymax . ' "' . $w . '")';
$linebuf = $linebuf . "n " . $wline;
$lxn = $xmin if ($lxn > $xmin);
$lxx = $xmax if ($lxx < $xmax);
$lyn = $ymin if ($lyn > $ymin);
$lyx = $ymax if ($lyx < $ymax);
}
$pagebuf = $pagebuf . "n (line $xmin $ymin $xmax $ymax" . $linebuf . ')';
$pxn = $lxn if ($pxn > $lxn);
$pxx = $lxx if ($pxx < $lxx);
$pyn = $lyn if ($pyn > $lyn);
$pyx = $lyx if ($pyx < $lyx);
}
close BOX;
close TXT;
binmode(STDOUT, ":utf8");
print "(page $pxn $pyn $pxx $pyx", $pagebuf, ')', "n";
EOL

which generates “cake_text.txt” in the accordant format. The hidden text can be saved back to the djvu file with

djvused -e “select ${page};set-txt “cake_text.txt”;save” cake.djvu

We just need to repeat this for all the desired pages.

季氏第十六之一

兩千多年前的思想,今天用來還是十分適切。

季氏將伐顓臾,冉有、季路見於孔子,曰:「季氏將有事於顓臾。」孔子曰:「求,無乃爾是過與?夫顓臾,昔者先王以為東蒙主,且在邦域之中矣,是社稷之臣也。何以伐為?」冉有曰:「夫子欲之,吾二臣者,皆不欲也。」孔子曰:「求,周任有言曰:『陳力就列,不能者止。』危而不持,顛而不扶,則將焉用彼相矣?且爾言過矣!虎兕出於柙,龜玉毀於櫝中,是誰之過與?」冉有曰:「今夫顓臾,固而近於費;今不取,後世必為子孫憂。」孔子曰:「求,君子疾夫舍曰欲之,而必為之辭。丘也聞有國有家者,不患寡而患不均,不患貧而患不安。蓋均無貧,和無寡,安無傾。夫如是,故遠人不服,則修文德以來之。既來之,則安之。今由與求也,相夫子,遠人不服而不能來也;邦分崩離析而不能守也;而謀動干戈於邦內。吾恐季孫之憂,不在顓臾,而在蕭牆之內也!」

若為政者皆能有如是的見解,則世上的苦難必可少去許多。