4/15/08

decoding dianping.com google map lat/lng

diandianping.com now use Google map for its biz locations. I'd like to get latitude and longitude for some of the restaurants I found there.
But "view source" showed its lat/lng are encrypted.

I just don't understand these Chinese sites like mapbar, mapabc, now dianping, why encrypt them? What's the point?
Because dianping use gmap, it has to send clear lat/lng to google, that means the browser has to decode lat/lng, that mean the decoding code is right there in javascript. In this case, the decoding happens in jquery.jmap.min.js.
This js is also obstructed. But I was able to crack it in a short time.
It appears the javascript evaluates and generates code on the fly and then evaluate the generated code that decode lat/lng and send them to google.

Here's my decoding script. It works now but might not in the future as dianping might change the parameters like digi, add, plus and cha.

Chinese: 点评用谷歌地图,但是给地图坐标加了密。我不知道这样做是为了什么。因为你必须在浏览器里解密,所以研究下代码,很容易就解了密。这里给出解密代码,是用python写的。

6/1/07

utf8 and gb chinese to pinyin converter

This program convert Chinese text encoded in either UTF-8 or GB2312/GBK to pinyin. It's small and does not use external lookup table. I wrote this for my own use in Chihe Project.
Maybe someone will find it useful.

5/25/07

putty, utf8 and chinese

I often have to edit utf8 encoded files that contain Chinese, on remote linux machine, through putty. To edit and display Chinese correctly, I have to configure putty and my environment setting on the remote host.


First putty:open putty configuration Window -> appearance -> font settints->change... select NSimSun (新宋体)
Window -> Translation -> Character set ... select UTF-8


Save configuration to a session.
Next we setting up remote host:
put this in ~/.bashrc
export LANG=en_US.UTF-8

Re-"source" bashrc.

Issue a "locale" and make sure LC_CTYPE is set correctly. If not do a "locale -a" and see what's available.
In Fedora or CentOS, just do a "yum install glibc-common" to install glibc-common to get all locales.
In Ubuntu, edit file /var/lib/locales/supported.d/local and add this line:
en_US.UTF-8 UTF-8
Then do a "dpkg-reconfigure locales".

That's it. Now we can edit UTF8 encoded Chinese file without problem.



5/23/07

lightbox with slideshow

Lightbox is very cool (I know it's hated by some), but you have to click mouse to view next image.

Why not make it run by itself, like a slideshow.

Googling didn’t turn out anything useful, so I added a few lines of code to lightbox.js to make it run slideshow.

If you have lightbox, replace your js/lightbox.js with lightbox-ss.js, and you’re ready to go.

Demo is here.

5/22/07

Vim, Gvim, utf8, and Chinese in Windows XP

See the post for using chinese in dos (cmd) under Windows XP (English).

If you have set locale to PRC as in above post, you are all set to input Chinese in Vim and Gvim. Do a ":set encoding" in vim/gvim, it should say the encoding is set to cp936 (codepage 936, ie. GBK/GB2312).
This is fine if you want to save file as encoded in GB2312. However I usually save all my file as UTF8. To do this I can issue ":set fileencoding=utf8" in vim, but I have to do it every time for a new file. Also, when you open a file previously saved as utf8 in Vim, it will displayed incorrectly because Vim assume it's encoded in gb2312. You can ask vim to reload a file with utf8 encoding by issue a ':e ++enc=utf8', but again you have to do it every time.

To solve these 2 problems, we need to edit our _vimrc file(located in Program Files\vim), and add these 2 lines:
set fileencoding=utf8
set fileencodings=ucs-bom,utf8,prc

The first line tell Vim to save any new file encoded in utf8, the 2nd line tell it to detect file encoding in that order.

That's it, now we can edit both utf8 and GB encoded file.

If you want to make Gvim look prettier when displaying Chinese, add following lines in _vimrc (assume you already have Chinese font installed):
if has("gui_running")
set guifont=NSimSun:h12:cGB2312
endif

5/21/07

Dos, Chinese under window xp

To use Chinese in dos under windows XP (English), just change the locale to "Chinese (PRC)".
These are the steps.

Go to Control Panel -> Regional and Language Options -> (tab) Advanced -> Language for non-Unicode programs, select "Chinese (PRC)".
Also on Languages tab, make sure "Install files for East Asian languages" is checked (may prompt you to install fonts from Windows XP cd).After a reboot, you should be able to enter chinese in dos (cmd).

5/16/07

Chinglish

You can see some Chinglish examples in my lbss (lightbox-slideshow) demo.

Click "Start Demo Slideshow".

2/27/07

on DVBBS

What a piece of crap!

You think Discuz is bad? DVBBS is far worse.

10/26/06

(not) Using "text" as table name in RoR

-bash-3.1# ruby script/generate model Text
./script/../config/../config/environment.rb:8: warning: already initialized constant RAILS_GEM_VERSION
The name ‘Text’ is reserved by Ruby on Rails.
Please choose an alternative and run this generator again.
Suggestions:

Sense 1
text, textual matter — (the words of something written; “there were more than a thousand words of text”; “they handed out the printed text of the mayor’s speech”; “he wants to reconstruct the original text”)
=> matter — (written works (especially in books or magazines); “he always took some reading matter with him on the plane”)

WTF?!

10/1/06

interesting line

Life is a sexually-transmitted disease with a 100% fatality rate.