Tuesday, October 16, 2012

Make XeTeX show quotation marks properly

Because of some annoying CJK font problems, I've switched from traditional LaTeX to Unicode-capable XeTeX.

After several trials, I finally made it worked on my computer and got the result which fitted almost my expectation. I said ``almost'' because there was a little problem of the quotation marks. In stead of showing expected curly marks, XeTeX outputted the marks in original text mode.

The solution I found is to add a bit of setting as follows.
\defaultfontfeatures{Mapping=tex-text}
\setmainfont{YOUR_FONT_NAME}

or simply
\setmainfont[Mapping=tex-text]{YOUR_FONT_NAME}
Actually I have no idea about the difference between the two implements listed above. My own guess is: the first one provides global effect while the second one affects only on the main font?

---
ref:
http://tug.org/pipermail/xetex/2008-October/010929.html

Monday, October 15, 2012

CThruView Transparent Image Viewer -- test in Ubuntu 12.04

In addition to qiv mentioned in the previous post, I found another image viewer which could do some amazing things when viewing transparent images. It is CThruView written in Java.

However, my trial got some problems. The transparent background was replaced by a gray one, and its visibility can only be reduced along with the foreground image by setting the opacity of overall image. The following screenshot shows my test.

At the first trial, I though the fails might be due to the OpenJDK which is the default installation in Ubuntu. So I found the method to install Sun Java 6 but got the same result.

Another failed test was the option ``Click-Thru'' which had no function. Except for these, other options worked properly.

Sunday, October 14, 2012

qiv -- Viewing image with transparent background

In Ubuntu, there is a image viewer named qiv which can show image files with transparent backgrounds.

For installation, just type
$ sudo apt-get install qiv

Invoke qiv in command line, and there are many many options to meet most requirements.

To show the image with its transparent background, the argument -p has to be used:
$ qiv -p IMAGE_FILE.png

Below is a screenshot of my own test. Note that the original image was save as png file with transparent background.

Use qiv to show image with transparent background.

Thursday, October 04, 2012

Visual Studio 2005: the symbol xxx is not defined

I've encountered the problem several times. Every time I have to use Ctrl+F to go through all the source code and it's somewhat annoying.

The only solution I could think of is to delete the *.ncb file or rebuild the project. And it's what I found on internet when I launched the search.

Unfortunately, it didn't work for me.

Fortunately, I finally got a solution which save my live.

Here is the method to solve the ``symbol xxx is not defined'' error:

Edit -> Intellisense -> List Members


XeTeX -- using the system fonts for CJK tex files

After using LaTeX for several years, I found XeTeX might be the best choice for Unicode files and therefore for the production of CJK documents.

When producing the CJK documents, it will be convenient to make the system fonts available for XeTeX. Here is a simple method to make it work.

To install system fonts, put *.ttc or *.ttf  files to the following folder:
/usr/share/fonts/truetype

Then build the font information cache files:
$ sudo fc-cache -f -v 

---
ref:
Mac下的Latex中文解決方案: XeTeX
http://www.hitripod.com/blog/2011/04/xetex-chinese-font-cjk-latex/
http://www.ubuntu-tw.org/modules/newbb/viewtopic.php?post_id=230060#forumpost230060
http://www.tmes.mlc.edu.tw/wiki/index.php/Freefonts
http://www.ptt.cc/bbs/LaTeX/M.1315925855.A.C38.html

Saturday, March 03, 2012

Set Vim in Windows to work with Unicode

My Windows has been installed and set for traditional Chinese environment and occasionally it makes some trouble when I need text files encoded in Unicode instead of Big5.

I've started to write some personal working logs in Markdown syntax with Vim. It's simple and quick. But when I tried to compile the plain text into HTML file, the Chinese characters introduced trouble for the Python implementation of Markdown. The error message was something like:
UnicodeDecodeError: 'utf8' codec can't decode byte
To prevent this kind of error, I thought the best approach was to make Vim work with Unicode in my Windows. The settings were added in C:\Program Files\Vim\_vimrc and they are as follows:

set fileencoding=utf8
set fileencodings=ucs-bom,utf-8,default,latin1

The first line tells Vim to save the text in utf8 and the second line gives Vim to open and convert the files in the given order of encoding.

Sunday, January 08, 2012

Cannot set Chromium as your default browser?

I was using FreeMind to manage information of my work, and there were several links embedded in the mind map. When I was trying to open the links, they were opened in Firefox instead of Chromium that has been my default browser. I tried to set Chromium as the default browser in the Preferences tab but it said ``Chromium cannot determine or set the default browser.''
The solution was found on Ubuntu Forums. In the thread, user cavalier911 provided a method using update-alternatives to set the default browser. The command is as follows.

$ sudo update-alternatives --config x-www-browser

Pretty easy and works like a charm.

Monday, January 02, 2012

Screencast of particular window in Ubuntu using ffmpeg

When you want to record the screen output, there have been some software good to use [1]. However, I found none of them can properly record the zone in which a C++ program produced video stream combining webcam input and OpenGL objects.

After some trials, I found an useful solution [2] and made some modifications. It is a shell script that uses ffmpeg to record the video content of target window.

#!/bin/sh

echo -e "Usage: bash $0 outputfile\nClick on the window to be recorded."

size=$(xwininfo -frame | awk '/geometry/ {print $2}')
offset=$(echo $size | awk -F + '{print $2","$3}')

ffmpeg -f alsa -ac 2 -ab 192k -i pulse -f x11grab -s $size -r 30 -i :0.0+$offset -acodec pcm_s16le -vcodec libx264 -vpre lossless_ultrafast -threads 0 $1
---
[1] Such as recordMyDesktop and xvidcap
[2] Run FFMPEG with x11grab

Tuesday, November 08, 2011

[Py] The Python Challenge -- Level 06

Here is a note of my solution to solve Level 06 of The Python Challenge.

The main library used is the zipfile module.

Monday, October 31, 2011

[Py] The Python Challenge -- Level 05

Here is a note of my solution to solve Level 05 of The Python Challenge.

The main library used is the pickle.

Sunday, October 30, 2011

[Py] The Python Challenge -- Level 04

Here is a note of my solution to solve Level 04 of The Python Challenge.

The main library used is the urllib.parse to parse the url and the urllib.request for retrieving the web page source.

Thursday, October 27, 2011

[Py] The Python Challenge -- Level 03

Here is a note of my solution to solve Level 03 of The Python Challenge.

The main library used is the urllib.request for retrieving the web page source and the re for regular expression operations.

[Py] The Python Challenge -- Level 02

Here is a note of my solution to solve Level 02 of The Python Challenge.

The main library used is the urllib.request. In Python 2.x, it is just urllib.

Wednesday, October 26, 2011

[Py] The Python Challenge -- Level 01

Here is a note of my solution to solve Level 01 of The Python Challenge.

Used functions: ord() and chr().

Thursday, October 20, 2011

pss: searching your source code in command line

When I was working on my Ubuntu with Vim to write or to view source code, I had no simple way to find certain functions scattering in the files by their name or key words.

Now I have one useful tool which is named pss written by Eli Bendersky. The tool is written in Python and that is attractive to me, because I can read the source code and maybe learn something from it. :-)

Download: https://bitbucket.org/eliben/pss/downloads

Okular: Annotations are stored in local directory

This is just a quick note.

When using Okular to view the PDF files, you can add various annotations in the documents. These annotations, however, are not embedded in the PDF files. Instead, they are stored in your local directory. In my Ubuntu PC, the path is

~/.kde/share/apps/okular/docdata

The annotations are stored in individual XML files for the corresponding annotated PDF files.


Thursday, September 15, 2011

Using Boost accumulators to calculate the variance

Boost seems a promising set of C++ library, but I found it's not easy for me to figure out its usage. After serveral trials, I finally got the variance calculated.

Here is the testing code I used (in VS2005):

#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/variance.hpp>

int main(){
    using namespace boost::accumulators;
    accumulator_set< double, stats<tag::variance> > acc_variance;

    for (int i = 0; i < 10; i++){
        std::cout << i << ", ";
        acc_variance(i);
    }

    std::cout << std::endl << "Variance = " 
        << variance(acc_variance) << std::endl;

    return 0;
}

The output is:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
Variance = 8.25

When I tried to varify the result, I use MS Excel but got unexpected result. The variances given by Boost and Excel are different!

Did I make any mistakes? Oh, I didn't realise the variance calculated by Boost function was the population variance, and the VAR function of Excel gave the sample variance. To have population variance in Excel, you need VARP, not VAR.


---
Ref: Variance calcs in the stats library and in Excel

Using Git as a working logger

I am working on a project, which is a experimental program coded and maintained by myself.

It is redundant and seems stupid to copy the whole working folder whenever I want to change the code to another version. Especially when the folder contains not only source code but some other documents or videos of testing results.

``I need a version control tool.'' The idea came to my mind.

``But I've never used or been familiar with any.'' The truth is cruel.

Then I thought of Git, a term which I might saw several times when surfing webpages.

Because the project I am working on is written and compiled with Visual Studio 2005, I started to search how to use Git with VS2005 and found Git Extensions.

Wednesday, August 31, 2011

VLC outputs black screen while the audio works fine

My VLC video player gives strange behaviour these days. When playing video, there is only sound with black screen. I once though the video files were broken, but they can be viewed by using QuickTime. So, the problem must be in VLC.

I searched on the Web and didn't find exact issue I encountered. Then I found this post, but the solution didn't work for me and didn't make sense to me. However, the post remind me about preference settings, and I thought of there was a post I glanced mentioned about video card. Oh! I've changed my video card several weeks ago. It might be the cause! I looked into the ``Video Settings'' of preference menu, and unchecked the item named ``Accelerated video output (Overlay)''. It works! :-)


Monday, July 25, 2011

[Py] Example code of FAST corner detection

Edward Rosten developed the FAST corner detection algorithm and gives several versions of source code. Python code is one of them. I downloaded the Python source code but found there was no example to illustrate the basic usage. Fortunately, the Matlab code has one example m-file. Based on the m-file, I tried to write a Python version and it works.