math expression on www

rarely need to write mathematics expressions on the web, but the last time I did, it took me some times to figure out just how to do. It’d turned out to be pretty easy, there’s a free LaTeX rendering server at yourequations.com. Excellent site! Just feed it with a LaTeX expression, it would render an image for you to put on your web page. This may be the best solution for now, while waiting for an workable HTML version that supports math.

There’s also a guide to embed this feature onto Blogger blogs (and also WordPress, and some PHP forums…) Just insert your LaTeX code between the pre (or code) tags as below and the jsTeXrender JavaScript would do the rest for you. This works fine for any browser with JavaScript support (mouse over the expressions and you would see the underlying LaTeX code). You may also need this LaTeX Reference Card for a list of LaTeX’s symbols.

Update, Otc 1st, 2010

Due to heavy traffic, yourequations.com has ceased the service. Please see this new post on how to run a LaTeX rendering server of your own!

trăng chiều

ừ trước đến nay có xu hướng giới thiệu nhiều nhạc miền Nam trước 75, đôi lúc còn khẳng định: CNXH làm băng hoại con người và cảm quan nghệ thuật. Đó có phải là một cái “confirmation bias” hay không thì tùy các bạn nghĩ. Cùng thời gian đó, sự xuống cấp không cứu vãn nổi của một bộ phận lớn âm nhạc ở miền Nam, kiểu nhạc Chế Linh – Lính chê, cũng chẳng phải là không hiển nhiên !?!?

Trăng chiều - Đặng Hữu Phúc - Ái Vân 

Để xoá bỏ những định kiến nếu có, mời các bạn nghe một đoản khúc thơ nho nhỏ dưới đây (nho nhỏ hàm ý là dễ thương nhưng có phần đơn giản). Để quay lại một không gian Hà Nội trong mắt ai, những năm đầu 80, có một mối tình đơn phương tuổi học trò, lãng mạn và sâu lắng. Có một chàng nhạc sĩ (tương lai) thầm yêu một cô ca sĩ (tương lai), tên cả hai người được ghi ra bên đây, bên dưới tiêu đề bài hát.

sáo thần nguyễn đình nghĩa


ó lẽ tôi phải dùng những ngôn từ tốt đẹp nhất để ngợi ca tiếng sáo thần Nguyễn Đình Nghĩa, tiếng sáo trúc Việt mê hồn này là thành qủa của một đời nghiên cứu và diễn tấu. Sinh ra và lớn lên tại Đà Nẵng, cựu học sinh trường Phan Châu Trinh, từ nhỏ được học khai tâm về sáo với một nghệ nhân gốc Hoa, tiếng sáo đã theo ông suốt một đời nghệ sĩ.

Polonaise (M.K. Oginsky) 
Badinerie (J.S. Bach) 
Tình ca (Phạm Duy) 
Nhạc sầu tương tư (Hoàng Trọng) 

Từ đầu những năm 60, tiếng sáo của ông đã nổi tiếng và được gọi là tiếng sáo thần. Ông dạy trường Quốc gia Âm nhạc và phụ trách môn Quốc nhạc tại Đại học Vạn Hạnh. Ông cũng tham gia nhiều liên hoan âm nhạc ở nước ngoài và thường được Hoàng gia các nước Thái Lan, Lào… mời trình diễn. Sau 1975, bị cấm trình diễn, ông chuyển qua nghiên cứu âm nhạc và nhạc cụ dân tộc. Ông là người đã cải tiến đàn T’rưng, mở rộng âm vực từ 1 octave lên 4 octave, cải tiến sáo trúc Việt Nam từ 6 lỗ thành 11 lỗ (rồi 16 lỗ).

Các nhạc cụ cải tiến đó đã có khả năng trình tấu nhạc cổ điển Tây phương, mà vẫn không mất đi âm sắc nguyên thủy của nhạc cụ truyền thống. Năm 1984 ông sang Mỹ, cùng với gia đình (vợ và 5 người con) tham gia trình diễn trên đài phát thanh, tham gia giảng dạy nhiều khoá học. Ông được nhiều giải thưởng của chính quyền Mỹ. Người Mỹ trong quá trình đi tìm những cái gọi là “complementary music” đã đánh giá những công trình của Nguyễn Đình Nghĩa rất cao. Nhiều thông tin về người cố nghệ sĩ có thể tìm thấy ở đây.

Xin giới thiệu đến các bạn hai bản nhạc Việt và hai bản cổ điển Tây phương qua tiếng sáo Nguyễn Đình Nghĩa. Phần nhạc cổ điển là hai bản nhạc tôi rất ưa thích và thường nghe, phần nhạc Việt là hai tác phẩm, một của Phạm Duy và một của Hoàng Trọng. Nghe tiếng sáo này rồi mới hiểu tại sao trong văn hóa Tây phương, danh từ The piper lại ám chỉ một “thế lực” quyến rũ ma quái đến vậy. Cũng xin nói thêm là chính nhờ bản trình tấu sáo này mà tôi nhận ra và cảm thấy dáng nhạc thượng du miền Bắc rất duyên dáng trong Nhạc sầu tương tư, một bản nhạc tôi đã nghe nhiều nhưng vẫn không cảm được cho dù là qua sự trình diễn của nhiều giọng ca nổi tiếng.

đêm ngắn tình dài

Theo tôi tân nhạc Việt Nam phải thể hiện rõ cá tính Việt Nam. Để đạt được điều này, người sáng tác phải hiểu rõ nhạc Việt qua cách học nhạc cụ cổ truyền cũng như hát được các điệu hát cổ truyền. (Dương Thiệu Tước)

Dương Thiệu Tước thật tình muốn dùng nhạc pháp Tây Phương để soạn nhạc Việt mới, nhưng ông bị nhạc ngũ cung Việt Nam trói ông lại… Nhạc Dương Thiệu Tước, theo tôi, là loại nhạc tình tứ, nhưng cũng rất sang trọng. Ðó là những ca khúc tình ái thốt lên từ con tim của một nghệ sĩ dòng dõi nhà quan. ( Hồi ký Phạm Duy, tập 1, chương 12)

uốn mượn bài hát Đêm ngắn tình dài này như phần mở đầu cho bài viết giới thiệu về một nhạc sĩ đặc biệt: Dương Thiệu Tước. Lúc nhỏ, đây gần như là bài nhạc duy nhất của Dương Thiệu Tước gây được dấu ấn sâu đậm trong tôi, một phần vì lúc ấy tôi còn chưa hiểu và cảm được những giai điệu ngũ cung, chỉ biết về ông qua một số ca khúc mang tính Tây phương: Đêm ngắn tình dài, Bóng chiều xưa, Ngọc lan, Chiều… Phần nữa vì nét nhạc vừa cổ kính, vừa tân kỳ của bài hát, ca tụng khát vọng tình yêu đôi lứa trong một không gian phảng phất Đường-thi: có trăng, có rượu hoàng hoa… và lại có anh và em, có người con trai và con gái, điều rất ít thấy trong thơ cổ.

Đêm ngắn tình dài - Thái Thanh 
Tiếng xưa - Hà Thanh 

Còn một tối gần bên nhau… cái lời nhạc nói lên khát vọng tình yêu vừa mãnh liệt, vừa êm đềm, đối với tôi lúc ấy đã đủ để nói lên một tâm hồn nhạc đặc biệt mà chỉ sau này tôi mới hiểu rõ được. Khi viết nhạc thất cung theo kiểu Tây phương, nhạc của ông “rất Tây”, điển hình như bài Ngọc lan, nghe bài này chúng ta tưởng như đang nghe Chopin hay Schumann. Ngay từ khi mọi người còn phải vay mượn nhạc điệu Tây phương để soạn lời ca tiếng Việt và gọi nó là bài ta theo điệu tây thì ông đã soạn những bài có thể gọi là bài tây theo điệu ta.

Còn khi viết nhạc ngũ cung, nhạc của ông lại “quá ngũ cung”. Nếu như nhạc ngũ cung của Phạm Duy là thoát thai từ dân ca, khi hát cần luyến láy một chút thì mới tìm thấy được dáng nhạc, thì của Dương Thiệu Tước tự nó đã có đậm đặc chất ngũ cung rồi, cứ hát lên là như tìm lại được những nét dân ca miền Thùy Dương xứ Huế. Tuy là người Hà Nội nhưng nhạc của Dương Thiệu Tước thể hiện một sự thẩm âm đặc biệt mẫn cảm với dân ca Huế, phải chăng chính là nhờ mối tình say đắm với một người con gái sông Hương núi Ngự, nữ ca sĩ Minh Trang (thân mẫu ca sĩ Quỳnh Giao).

Một vài bìa nhạc Dương Thiệu Tước:

la bohème

he only song posted twice on my blog, my previous post is here (this version is performed when Charles was still young, a much higher tempo). I’d listened to both the vocal & instrumental versions of this song long before, but didn’t recognize that they are actually one same song. Just by a sudden special chance in Dalat made me realise that it is Paul Mauriat who was covering Charles Aznavour.

La Bohème - Charles Aznavour 
La Bohème - Paul Mauriat 

Charles Aznavour is a very big name in American & French music, but much more popular in his French audience. Till now, he still go to stage and have many performance at the age of 83, and still attract and seduce a lot of listeners. He is called by the title French Frank Sinatra, but to me Charles Aznavour is much more different however, Frank Sinatra didn’t wrote the song himself.

dell inspiron mini 9



y new Dell Inspiron mini 9 notebook: the company laptop is far too heavy to carry back and forth daily, and this is really a cute tiny toy to have. Having dimensions briefly larger than a pencil, the notebook is really light, its display is bright and clear, sound is pretty good, and the external speaker is amazing for such a mini notebook.

This is a laptop with no moving part: hard disk is solid – state (16GB), no ventilating fan (the temperature is just right after long use). The disadvantage with the toy is that keyboard is quite small and strange, which may take times to get familiar with. Ubuntu (Hardy Heron) came pre-installed, and every softwares work out-of-the-box: graphics, sound, wifi, webcam…

The distro is a customized version for Dell called Netbook Remix, however, after a while, I get bored with that and switch to the default Gnome view. The good point is that mp3, Acrobat Reader, Adobe Flash, Sun Java… licenses come with the distro, there’s no need to hack for these stuffs. Please see below for some GUI screenshots.

signals and slots

C makes U hang yourself;
C++ even gives U a rope object to hang;
C# scourges U using a rope wrapper!

rarely talk about programming unless it comes to some new idea or something fun. However, in this article, I’m going to summarize a part of experiences in my career, about important concepts that I’ve learned and used: signals and slots. First appear and remain as fundamental concepts in the Qt library (“Qt” pronounced “cute” – which is so cute as a cross-platform application framework), the concepts has been adapted and developed into some other libraries (such as boost) and are being proposed as next standards for C++ language.

Please note that we’re talking C/C++ here, although signals & slots has been brought to many other languages (Java, Python, Ruby, JavaScript, etc.) Every coin has two sides and C/C++ is no exception, it has its own advantages and disadvantages (depend on types of applications). But the thing I like about C/C++ is that its half – civilized nature made it a strong language: the balance between abstraction and comprehensiveness has always been considered as core factor.

Noone want to build general applications using Assembly, and noone want to write lengthy code just for some simple features. To adhere the doctrine, strong – abstraction concepts must be introduced to capture grammar of the language, and simple, clear syntax that would make the code concise and comprehensive.

I came to signals & slots as solution to problems I’ve met when leading the CMS project, a DVRs managing software (client & server) with complicated GUI: a few screens, each screen can have a dozen tabs, each tabs can have hundreds of controls. Events on one control can affect other controls on other tab or screen, events can be user inputs as well as various signals come from dozens of (managed) network client machines.

The overwhelmingly – complicated communications surpass every MPM (message passing method), then signals & slots appeared as a saviour solution. To be simple, signals & slots is a very efficient mean of interaction between objects within a process space. I personally think it would be the next metaphor extension added to C/C++ language. Structure of this post would be as follow:

1. Introduction to signals & slots, from raw to abstract concepts.

2. ISO C++ compliant and cross – compiler, cross – flatform problems (would discuss about delegate and how function pointer has evolved from C to C++).

3. Different implementations of signals & slots: Qt, boost, sigslot, libsigc++

1.   INTRODUCTION

Flow of code is no more than a series of function call, and to perform asynchronous function call, traditional C programming use callback. A callback is a pointer to a function, so if you want a processing function to notify you about some event, you pass a pointer to another function (the callback) to the processing function. Callbacks have two fundamental flaws: firstly, they are not type-safe, we can never be certain that the processing function will call the callback with the correct arguments. Secondly, the callback is strongly coupled to the processing function since the processing function must know which callback to call. In C, to define function pointer, you would write something like this:

float (*my_func_ptr)(int, char *);
typedef float (*MyFuncPtrType)(int, char *);
MyFuncPtrType my_func_ptr;

When move to C++, things are a bit more complicated (note the weird syntax ->* to call a member function through pointer).

float (SomeClass::*my_memfunc_ptr)(int, char *);
my_memfunc_ptr = &SomeClass::some_member_func;
SomeClass *x = new SomeClass;
(x->*my_memfunc_ptr)(6, "Another Arbitrary Parameter");

Though a very strong concept in C, function pointer add little to the language C++. The only two uses of member function pointer in C++ are:

  • Demonstrate the tricky syntax of the language.

  • Help in implementation of delegate.

Now, imagine slots as invisible communication channels, every object can register to listen to some channels by providing delegates (pointer to a member function). The delegate would be invoked when slot is “filled” with a signal. The signals and slots mechanism is type safe: signature of a signal must match signature of the receiving slot. Signals and slots are loosely coupled: a class which emits a signal neither knows nor cares which slots receive the signal. To summarize the benifits:

  • Syntactically neater: signals & slots make for very readable code: you define the signals, you define the slots, then you wire them up.

  • Inherently robust: when either end of a signal/slot connection is destroyed, the connection is automatically removed. It is therefore impossible to emit a signal and have it arrive at a class that has already been deleted. Best of all, you don’t need to write any cleanup code.

  • Easier code reuse: since the thing that has to type-agree is the signal and the slot, not the whole class interface, it is much easier to plug together disparate classes that had never initially been intended to work in that way.

2.   DELEGATE

To summarize section 1: pointer is the root of all evils. Function pointer is the physical of callback method traditionally used in C programming. When evolved to C++, the C++ standard committee failed to address how to define function pointer to a single C++ object. With common-sense knowledge, we know that it take two elements to represent the thing: first is the address of the object itself (the implicit pointer this), second is pointer to the object’s member functions. The undefined land leads to different implementations across various compilers.

Contrary to common belief, the actual physical storage of pointer differs between various compilers, and even differs between types of pointer, e.g: pointer to a single – inheritance object, an multiple – inheritance one or virtual inheritance. The table below shows how many bytes it take to store pointers on different compilers (just make use of the operator sizeof). Then to calculate the actual member function’s address, each compiler uses one kind or another of offset:

struct BorlandMFP
{
        CODEPTR m_func_address;
        int delta, vindex;
};
if (vindex==0) adjustedthis = this + delta;
else adjustedthis = *(this + vindex –1) + delta;
C++
compiler
void*
pointer
function
pointer
single
inheritance
multiple
inheritance
virtual
inheritance
MS VC++ 4 4 4 8 12
GNU G++ 4 4 8 8 8
Borland C++ 4 4 12 12 12

So, delegate is just the new name for pointer to (an object’s) member function. The hard part really is that: since each compiler stores different type of pointers differently, there’s need for a way to store delegate in a universal manner: cross compilers and cross flatforms. Various techniques have been proposed by excellent programmers. Please refer to the articles below for specific techniques. I personally would prefer the method of Quynh Nguyen, an engineer at Global Cybersoft (Vietnam) Ltd.

3.   IMPLEMENTATIONS

To make those obscured concepts above clearer, I would go into some detailed implementations of signals & slots with the emphasize on the sigslot library, for this is really a compact lib: everything is contained in just one header file. Suppose you have a server that would receive some signal from network (tcp socket), then parse the received data and trigger some processing (display on GUI, store to disk…). We would define the “network signal” as follow (please note any number of parameters can be defined, we use an int and a char* here just for the example):

// the temmplate ‘signal2’ denote for
// a signal with 2 parameters

signal2<int, char*>m_netSig;

Then, at the place you want to process that event, e.g some class CDisplayForm, you would need to provide a function to process the signal:

DisplayForm::OnNetSig (int cmd, char* data)
{
  // the delegate would be invoked
  // when the signal is recieved

}

Please note that multiple objects can register to a same signal slot (and vice versa), e.g some class CRecordThread would also need to log that event to database. Then the listening objects would just register with the signal slot using a connect function:

// we pass the function pointer
// here to be called later

m_netSig.connect (this, &CDisplayForm::OnNetSig);

When the network signal arrive, e.g in some class CAsyncSocket, we would fire the signal and get it populated to all connected objects:

// emit the signal with it’s data
m_netSig.emit (NETSIG_DATA_RECEIVE, xmlStr);

Then the CDisplayForm and CRecordThread object would both receive the signal. Please note that when either end of the communication channel go out of scope, the connection is automatically removed, you don’t have to write any cleanup code. Just define the signal, the slot and wire them up! Any unrelated classes can be wired up in this type-safe manner without any pre-defined relation within them.

Speaking as an ex-hardware designer, I’d like software components to have pins around their edges, like ICs, so they can be ‘wired up’, but otherwise should be well behaved… I don’t want to know how that pin is wired internally – I just want to know that it will work when I send a signal into it.
(Sarah Thompson – sigslot library)

lucky luke – 2

ộ truyện tranh Lucky Luke thú vị trong từng chi tiết nhỏ: một lão thợ hớt tóc người Ý (thợ hớt tóc luôn phải là người Ý) mang cái tên Baldini (chẳng phải đã có câu thành ngữ: Never trust a bald barber đó sao) 😀, một tay tướng cướp lấy biệt hiệu là Po-8 (đọc như poet – nhà thơ)… Những nét cá tính và văn hoá Mỹ được mô tả một cách cô đặc, cường điệu và đầy tính hài hước.

Quá khiếp sợ vì 4 anh em nhà Dalton…

Và sáng kiến sửa chữa bánh xe độc đáo…

Ngay cả tiếng ngáy của những con người khác nhau cũng sẽ khác nhau.

Cuộc sống của những cao-bồi, lúc nào cũng canh chừng nhau thế này, ai đó hắt hơi thì sẽ có đổ máu.

Con sư tử mang tên đô đốc Nelson, và những chế giễu trên cái tên.

Thức uống của người và ngựa.

Lập trường nghề nghiệp của tay nhà đòn.

Đạo đức của người và ngựa.

Vận mệnh lớn lao của nước Mỹ qua việc treo cổ một người khác.