Archive for the ‘Uncategorized’ Category

2012-01-31

January 31, 2012
  • Work on git-push-mac and git-pull-mac, should not use meaningless commit message dubbed “mf”.

TODO 把firefox bookmark做成可搜索的?    pe

TODO fix gnome-open    pe

DONE fix sdim while C-s searching    pe

CLOSED: 2012-01-31 Tue 22:01

  • CLOSING NOTE 2012-01-31 Tue 22:01

DONE fix emacs url-proxy-services error on home PC    pe

CLOSED: 2012-01-31 Tue 22:27

  • CLOSING NOTE 2012-01-31 Tue 22:27
    Must not use localhost:8580 as the proxy; must use 127.0.0.1; IPV6 is involved to mess up

Advertisements

Things done on 2012-01-30

January 31, 2012

Work on org-jira, fixed priority required when creating issue

Work on Network Manager under sawfish

  • Will not allow delete network profile, while under gnome, a auth dialog popup asking for root password, and can go on to delete/add network profile.
  • This is fixed by starting policykit after diff with gnome session processes. More may need be fixed.
  • Started gnome-keyring-daemen in ~/.xprofile. GDM3 will source this file.
  • Will not be able to save after you edit a profile, must delete and then add and get it right when adding. It is different if you run nm-applet as root; in that case it can be saved.

Work on RNDIS XP driver, turns out only need a .inf file.

html2mht.pl and dir2html.pl

November 26, 2011

I have been working on 2 piece of perl scripts that convert a whole directory / a whole bunch of (inter-connected) .html files into a single page .mht file.

You can get the source code at html2mht.pl and dir2html.pl.

Here’s a small weird thing (aka, bug) I found out about .mht file, ancher does not work in .mht.

More specifically, for e.g., IE does not work when a index.html in a .mht contains a link pointing to chap1.html#sec1, which are also in the same .mht file.

Weird enough, firefox with the unmht plugin works fine with the above situation.

For the html2mht.pl, I must thank the html2mht project on sourceforge.

beagrep under win32

November 26, 2011

I have ported beagrep under win32.

I have not made it fit into the configure/make/make install 3-step thing yet, but am very close to that. I will probably do it when I need to do it on another PC…

git clone git://github.com/baohaojun/beagrep.git -b windows

Using dvp under Win32

November 26, 2011

In a previous blog I posted, I mentioned I was using dvp under Win32 with a custom AutoHotKey (AHK) script I wrote. Now I have abandoned that script. For 2 reasons:

  • It does not work on some programs/input boxes, not sure why, but google suggests maybe because they are run in SYSTEM account…
  • It fails to translate key presses occasionally. This is because the low level KeyboardHook/SendInput Win32 mechanism it employs is a half-baked buggy system itself.

Now I have switched to the kbddvp.dll provided by dvp creator Roland Kaufmann, and also solved the Chinese IME problem, turns out I only need to point the “Layout File” of my IME to “kbddvp.dll” in the registry:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layouts\E0350804]
"Ime File"="ywbhj35.dll"
"Layout File"="kbddvp.dll"
"Layout Text"="Chinese (Simplified) - YWB35"

There comes another problem through: cygwin-x does not work with my new solution. In fact, cygwin-x has nothing to do with Win32 keyboard layout/IME. Xwindows has its own keyboard layout mechanism. Sadly, dvp is not part of cygwin-x yet.

But I can live with that, since the 2 most fundamental GUI programs I use, terminal emulator and emacs, both I can do without X. I use mintty and emacs-nt, both of which are not X programs.

Using CLI and GUI Together Seemlessly

September 30, 2011

Some people love CLI like heaven, hate GUI like hell, and vice verser for some other people.

Me? I used to belong to the first group, but now I have learned to another level. Why not stop the love and hate and make them work together?

For e.g., now I often start from the CLI, and end in the GUI. If I want to open a file for uploading in GUI browser, I start from the CLI shell, because navigating directories and searching for files is so much easier in CLI shell than clicking all the way down the directory hierarchy in GUI FindFile dialog. Then I, while still in CLI shell, put the file path into clipboard with xclip (for Linux) or putclip (for Cygwin), switch back to the browser FindFile dialog, and paste it.

Similarly, when I want to locate a file in FileManager like Explorer for e.g., I start from the shell with this bash function:

function oc()
{
    cygstart `which explorer.exe` /n,/select,\""`cygpath -alw \"$1\"`"\"
}

When I want to locate a registry entry in regedit.exe, I use another command I wrote in python and pywin32, and made a short name of in bash:

alias or=regopen.py #open registry

When I want open a file with its associated opener, like Word for .doc, Excel for .xls, I use cygstart in Cygwin, and gnome-open in Linux:

if test `uname` = CYGWIN_NT-5.1 -o `uname` = CYGWIN_NT-6.1
then
    function of()
    {
        if test -e "$1"; then
            cygstart "$@"
            return
        fi
    
        if which "$1" >/dev/null 2>&1; then
            if [[ "$1" == of ]]; then
                local file=`which cygstart`
            else
                local file="`which \"$1\"`"
            fi
            shift
            cygstart "$file" "$@"
        else
            cygstart "$@"
        fi
    }
else
    alias of=gnome-open
fi

This way, I can use the same .bashrc under both Linux and Windows (think, Cygwin), and the same (well, not completely) of command to Open File.

(So this is not just about CLI/GUI together, but also about using Linux/Windows (again, think Cygwin) in the maximally possible same way).

Introducing beagrep, the beast like grep

September 29, 2011

I just found out about the beagle project couple of months ago, I’m totally excited by it. It’s the missing brick that I longed for to write a `grep on steroid’ which I can use as a source code reading tool.

Yeah, right, I was using grep to read souce code, often times finding cscope insufficient (because some files are not source code, and even cscope’s fuzzy syntax parser can not parse them). On the other hand, with large projects, such as Linux Kernel, or the even larger Android system, grepping can be very slow on the whole project. I once searched for readlink in android source tree, it took me >30 minutes!

With beagrep (beagle combined with grep), I can grep it for less than 2 seconds!

Why is it possible

When you grep for reading source code’s sake, you often don’t need complex regexp power: when you search readlink, you grep readlink, not grep r.*e.*a.*d.*l.*i.*n.*k, that just does not make any sense!

IOW, you 99.9% times search only for whole words like readlink, which is a kind of simple regexp, and unlike complex regexps (such as r.*e.*a.*d.*l.*i.*n.*k), is something search engines can deal with perfectly.

How is it done

It is really a very simple idea, when you want to grep a target repexp, do the following:

  1. Break the target regexp into whole words, for e.g., grep -e some.*fun.*stuff should be broken into “some fun stuff”.
  2. Query beagle with the whole words, beagle answers with which files in the repository contais these words. These files are the possibe matching files.
  3. Grep the target regexp in those possible files (which often is only a very small part of the whole repository, thus grep can finish in a blink of the eyes).

Modifications to beagle

Here’s the details of how I changed beagle to satisfy my need (warning: boring stuff ahead):

  1. Change all beagle built in filters to FilterText. This is because I don’t want those keywords filtered by those SourceCode filters. This way, I can beagle-query `extends CFunny’ to see which classes are inheriting from `CFunny’ in Java (The default Java filter will remoke extends since it is too common and uninteresting in java source files).
  2. Remove some restricts. For e.g., only the first 100000 tokens in a file would be indexed, which is undesirable for my purpose. Also, I enlarged the memory threshold by 10 times, since I found it causing problems with some large xml files.
  3. Remove more restricts. Basically, I unremoved anything the NoiseFilter will remove. Also, another filter will remove common English words, I unremoved those as well.
  4. Added support for indexing Chinese characters (This is because I’m a Chinese).

Usage

Here’s how I use it:

  1. Build a static index at the top level dir of the souce code:
    mkbeagleidx
    
  1. Use beagrep in any directory in the source tree:
    ~/bin/beagrep -e "ENGLISH_STOP_WORDS" 
    

    The output is like the following:

    beagle query argument `ENGLISH STOP WORDS'
    /src/beagle/beagled/LuceneCommon.cs:1206: ...ENGLISH_STOP_WORDS...
    ...
    ...
    

    Note: ENGLISH_STOP_WORDS is broken into 3 words before beagle is queried.

Where to find everything

I have put the source code at github.

If you checkout the source code, you can find the beagrep and its helper scripts under windows-config/bin.

The beagle source code I modified is under windows-config/gcode/beagle.

The c# program which breakes ENGLISH_STOP_WORDS to ENGLISH STOP WORDS is under windows-config/gcode/BeagleTokenizer.

The simplest way to set things up is to run

~/windows-config/bin/after-co-ln-s.sh

and then

~/windows-config/bin/linux/after-check-out.sh

For more details, please RTFS using beagrep!

Switched to USA Pragrammer Dvorak Keyboard

September 29, 2011

After reading xahlee‘s articles on keyboards, I recently made 2 big changes (and many other small changes because of the 2 big ones) to the way I type. I switched from QWERTY to UPD (USA Programmer Dvorak), and I switched my Control keys and Alt keys.

And how does it feel? Well, at first it was like pain in the ass. But then it seems to get better and better.

And to make it even better, I bought a Microsoft Ergonomics 4000 keyboard for use at work!

Here’s some hacking around this switch.

Switching Chinese and English at the same time

As a Chinese, I also need to type Chinese using an Input Method, such as Wubi. Now, I want myself to use the same UDP keyboard layout when using IME, because it would be crazy if I switch back to QWERTY when typing Chinese and stick to UDP when typing English…

But switching to UDP for my IME is even more painful. Because I am using Wubi, instead of PinYin, and the secret about Wubi is you use your muscle to memorize the encoding, so basically I just re-learned Wubi.

Some changes to Emacs

Xahlee considered Progammers Dvorak no better than Simple Dvorak (he tried UDP and then gave up), but I chose it anyway and have no plan to change again. I kinda feel its not that a bigger differenc now that both are Dvorak…

But Progammers Dvorak does give me some edge, considering the fact that I also switched Controls and Alts (which is also one of the advices by Xahlee).

This made a lot trouble with C-x and M-x. In the mean time, C-x got separated with many of the combination keys that used to be typed with the same hand as itself: C-x C-s, C-x C-f, etc.

Finally I found my solution (after searching Dvorak on EmacsWiki and some inspiration):

  1. Switch C-h and C-x using keyboard-translate.
  2. Stop using M- prefix altogether, use C-[ (the same effect as ESC) instead. Now Progammers Dvorak seem a much better choice than Simle Dvorak, because C-[ is very easy to type.

I tried to add more hacks, but finally stopped to reduce the confusion, and because the above 2 is about enough.

Using Progammers Dvorak under Windows.

Not that I use Windows a lot nowadays, but I do use it once in a little while, and I don’t want to be a fool when at it. So I need to find a way to use Progammers Dvorak under Windows.

Windows already provide a Simple Dvorak keyboad layout, and Programms Dvorak also available on the net. But they are both incompitable with IME.

I found on the net people has used autohotkey to provide Simple Dvorak, which does can be used at the same time with IME.

So I just wrote my Programms Dvorak version of autohotkey script. You can get it here. This ahk script was generated from 3 bash scripts, which you can find here, here and here.

Semi-offline wikipedia reader

October 27, 2010

ttsiod already built an (fast) offline wikipedia reader 2~3 years
ago, and it’s still working with latest wikipedia .xml.bz2 database dump
file!

wikipediaDumpReader also enables you to browse wikipedia offline.

I tweaked ttsiod’s software a little bit, so now you can get a better
user feeling when offline browsing: you can see images! Oh, well,
actually these images requires network connection for viewing, that’s why I call it semi-offline 🙂

You may wonder what’s my point updating this tool, it’s working, why
bother fixing it. Well, it has some issues dealing with new mediawiki
templates, and the pages sometimes are rendered less satisfactory. The
mediawiki parser ttsiod used is version 1.7.1, and the current version
is 1.16, so maybe things are breaking down.

As about the images viewing, well, who doesn’t love images, right?

You can look at the screencast at the end of this article.

To use my version of software:

  1. make sure you have the required software installed on your system:

    apt-get install python-django libxapian-dev xapian-tools

    Then check out my code:

    git clone http://github.com/baohaojun/windows-config.git ~/windows-config

    and put ~/windows-config/bin/linux/wiki-* (2 scripts) into your path.

  2. Get wikipedia dump file:

    mkdir ~/wikipedia
    cd ~/wikipedia
    wget http://download.wikimedia.org/enwiki/latest/enwiki-latest-pages-articles.xml.bz2

    This takes time, since the file is currently about 6.2G

  3. Build the index using wikipediaDumpReader

    cd ~/windows-config/gcode/wikipediaDumpReader-0.2.10/
    python ./mparser.py ~/wikipedia/enwiki-latest-pages-articles.xml.bz2

    This will generate a file at ~/wikipedia/enwiki-latest-pages-articles.idx

  4. Build the index database:

     cd ~/windows-config/gcode/offline.wikipedia
    make
  5. Start the server:

     cd ~/windows-config/gcode/offline.wikipedia/mywiki
    python manage.py runserver
  6. Start browsing offline wikipedia:

     firefox http://localhost:8000/article/Mathematics/

我要记住这一刻

October 10, 2010

Sun Oct 10 16:59:10 CST 2010