vendredi 31 décembre 2010

sylisa camp-json is on gitorious :-)

The serializer from C++ to JSON using CAMP is now on gitorious.

The build system is qmake and it is under the boost license.

BTW I plan to use CAMP for my dblite library, I am just curious to see how it fits :-)

best regards & happy new year 2011

sylisa-dblite is born :-) - a sqlite wrapper C++ library

I searched a library to be easily embedded in an c++ application (like sqlite amalgamation), with a good license like boost.
A long time ago, I went on SOCI and it was really good to see this kind of syntax.

Unfortunately, sqlite is available in the git repository only, and not officially supported.
Furthermore, after having a look on the code, I saw that everything was retrieve as "string" and I was not able to modify it easily as the internals were complex enough.

Then, I decided to give a try to have a simpler library but having a better fit with sqlite.

This is an early version for now, but still it is functional, and should answer already most of the needs.
I am anyway working on it.

In the future, I would like to integrate more database (sqlite will stay the first one first class), why not using SOCI as an underlying layer to access other databases? I would like to, "challenge accepted" :-)

The library is available under the boost license on gitorious

I hope some others will join of course :-)

Bye, I wish you all the best for the next coming year

lundi 13 décembre 2010

CAMP JSON Serializer

I wrote the last week an module for CAMP for an output to JSON.

There was already one existing called camp-json but it uses a c library behind, that obliged to have another dependency and an additional memory structure before the serialization.

I removed this dependency and the additional structure by serializing directly in JSON.
I also detect if Qt is used in CAMP and I output the Qt String into UTF-8, as I think it is the standard on the web.

so you can use it like:

    MyClass o;
    camp::UserObject object = o;

    QString json;
    QTextStream ts( &json );

    camp::json_serializer::serialize( ts, object, "nojson" );
    std::cout << json.toStdString();

You can find the module source code here, the CAMP forum

I would be very happy to hear your comments and critics.


mardi 7 décembre 2010

CAMP reflexion library

Few month ago, I discovered CAMP, a library that I could use to access dynamically my properties and functions. It is really wonderful! very simple!

I am currently writing a json serialiser that is not using an intermediate representation to do the output. As you may know, I like Qt and this lib detects the QString to output in the UTF-8 format.

happy coding :-)

vendredi 15 octobre 2010

IE 8 and opacity on PNG 24

RRRAaaaa I had a dashboard with a lot of LEDs to display and some should be transparent to better focus on the important ones. Unfortunately, as usual, IE is a pain.

IE 8 has a bug in displaying the PNG 24 with an certain opacity, Raaaaa
There is absolutely no workaround! I finished by making another version of the LEDs with Photoshop with an opacity effect!

after I had to ensure that it was compatible IE6, Raaaa again
IE 6 has a issue with PNG transparency, so I had to use a different tag IMG with a workaround using

var tag_img = '<img class="led" src="images/blank.gif" width="13" height="13" border="0" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+img_src+'\', sizingMethod=\'scale\');">'

with a very cool : if( $.browser.msie && $.browser.version.substr(0,1)==='6') {

It was probably not difficult enough with just IE6, we have now to support IE6 and IE8
Super I enjoy :-)

See you,

mardi 24 août 2010

SQLite with ICU on MacOSX for 32 and 64 bits (universal lib)


As I compiled Qt for 32 and 64 bits for being able to have the flash plugin working in the QtWebkit.
I will do it until Adobe will release a 64 bits version of its player ... Adobe, please do it asap.

but Qt is relying on sqlite then I had to compile sqlite in 32 and 64 bits.
Still no issue (yet).

The thing is that I want now to have sqlite with the ICU support (for REGEXP, the most important)
and now it become hard because ICU does not support the universal compilation 32 and 64 bits.
(it is 32 or 64 bits)

so how to do then ?

héhéhé, I have now a solution, that works so far, but it is a manual process to get there.
I heard about a tool named "lipo" that can merge 2 libraries into one for to create an universal library.

So now we have to create 2 folders with the ICU sources,
so I propose:
icu64 and icu32

for icu64, in the folder source, type the command
>./runConfigureICU MacOSX --with-library-bits=64

for icu32, in the folder source, type the command
>./runConfigureICU MacOSX --with-library-bits=32

then you have now the libraries for 32 and 64 bits in

now I created a small script file to output the universal libraries into a folder lib_32_64
lipo icu64/source/lib/libicudata.44.1.dylib icu32/source/lib/libicudata.44.1.dylib -create -output lib_32_64/libicudata.44.1.dylib
lipo icu64/source/lib/libicui18n.44.1.dylib icu32/source/lib/libicui18n.44.1.dylib -create -output lib_32_64/libicui18n.44.1.dylib
lipo icu64/source/lib/libicuio.44.1.dylib icu32/source/lib/libicuio.44.1.dylib -create -output lib_32_64/libicuio.44.1.dylib
lipo icu64/source/lib/libicule.44.1.dylib icu32/source/lib/libicule.44.1.dylib -create -output lib_32_64/libicule.44.1.dylib
lipo icu64/source/lib/libiculx.44.1.dylib icu32/source/lib/libiculx.44.1.dylib -create -output lib_32_64/libiculx.44.1.dylib
lipo icu64/source/lib/libicutu.44.1.dylib icu32/source/lib/libicutu.44.1.dylib -create -output lib_32_64/libicutu.44.1.dylib
lipo icu64/source/lib/libicuuc.44.1.dylib icu32/source/lib/libicuuc.44.1.dylib -create -output lib_32_64/libicuuc.44.1.dylib

then I copied back the libraries in lib_32_64 in the icu64/source/lib folder
>cp lib_32_64/* icu64/source/lib

then I go into the icu64/source and run the make install command
>cd icu64/source
>sudo make install

then you can compile SQLite with the ICU support :-)
>./configure CFLAGS="-arch i686 -arch x86_64 -DSQLITE_ENABLE_ICU `icu-config --cppflags`" LDFLAGS="-arch i686 -arch x86_64 `icu-config --ldflags`" --disable-dependency-tracking
>sudo make install

don't forget to install readline and to compile it with the following command before to compile SQLite:
> CFLAGS='-arch i686 -arch x86_64' LDFLAGS='-arch i686 -arch x86_64' ./configure
>sudo make install

and you have now SQLite, readline and ICU with universal 32 and 64 bits libraries!

happy coding!

write to you soon,

lundi 23 août 2010

sqlite configure 32 bits and 64 bits on mac os x

I am running MacOSX in 64 bits.
However for some reasons, I need sometimes to compile some programs in 32 bits (depending on 32 bits libraries)

so I need sqlite in 32 and 64 bits, and I configure it with the following command line:
> CFLAGS='-arch i686 -arch x86_64' LDFLAGS='-arch i686 -arch x86_64' ./configure --disable-dependency-tracking

Write to you soon,

mercredi 11 août 2010

QWebElement is great!

I recently used the Qt API to access the DOM of a web page through QtWebkit. I just hesitated to use it or to use the JQuery (via evaluateJS)

Probably the JS solution would be more extensible (plugins etc), however the additional work to export the data would be also largely more than expected... and one question also came about it. What if the page (that I want to grab information) already has JQuery (different version, when the evaluate happens etc)?

so I went ahead with the QWebElement object... and it is really powerful, easy to use and the CSS 3 syntax is a must. Purely great :-)

QWebElementCollection allTitles = document.findAll("*.title");
foreach( QWebElement e, allTitles ) {

a good link to read about it is from the Qt Labs

jeudi 5 août 2010

ubuntu 10.04 running on vmware fusion 3.1 mac os x

I just installed ubuntu 10.04 on vmware.
I compared it with the fedora but I found ubuntu largely better than fedora, I just find it really great.
I have a mac for now and I am not ready to change but if I had a PC then I will change to ubuntu without any hesitation.

running linux on a vmware has several advantages :-)
when I don't know the results, when I am trying to do something that could damage the system, hop la I do a snapshot :-D really great.

I am very surprised about ubuntu, I didn't think it was so great. it seems to behave a bit the same as macosx. please continue your excellent work.

write to you soon.

lundi 26 juillet 2010

C++/CLI String^ to std::string and vice-versa

I propose you 2 functions for converting std::string to/from String^ in C++/CLI

    String^ UTF8ToString( const char *s ) {
        int len = strlen(s);
        cli::array^ a = gcnew cli::array(len);
        int i = len;
        while (i-- > 0) {
            a[i] = s[i];
        return System::Text::Encoding::UTF8->GetString(a);

    std::string StringToUTF8( String ^ s) {
        System::Text::UTF8Encoding^ utf8 = gcnew System::Text::UTF8Encoding;
        array^encodedBytes = utf8->GetBytes(s);
        std::string os="";
        for (int i=0;iLength;i++) {
        return os;

Useful to work with other libs working in UTF-8 like sqlite...

samedi 24 juillet 2010

install Mono on MACOSX 64 bits

I recently installed mono from sources, no other choice for having it on 64 bits
I didn't have any previous installation of mono.

first you need to install wget and pkg-config. We normally need also gettext but seems it is not compatible with 64 bits, and as we can disable it then I did it without gettext.

unzip/untar it (double click on it normally is enough)
>sudo make install

unzip/untar it (double click on it normally is enough)
>sudo make install

now we get the sources of mono from the SVN repository
As we need 2 folder, we just create a root folder "mono-trunk"

>mkdir mono-trunk
>cd mono-trunk

>svn co
>svn co

>cd mono

// -- enable-nls=no is for disabling gettext

>./ --prefix=/usr/local/mono --build=x86_64-apple-darwin10 --enable-nls=no
>make get-monolite-latest
>sudo make install

don't forget to update your .profile to add the path to mono/bin

normally your are done with mono on macosx, please let me know if it worked for you :-)

mercredi 19 mai 2010

How to implement an regex replace as a sqlite extension using ICU and boost


I am currently implementing a sqlite dll extension for having the regexp replace...
it is so useful that I decided to share it with you all.

first of all, I went with boost + icu because I met some issues with Qt. I still didn't find any workaround for using Qt...

I am working on a mac os x 10.6.3 and I don't know if it works on other platform, maybe yes, maybe not... Let me know :-)

I made a c++ file that I named sqliteextensions.cpp

#include "/usr/local/include/sqlite3ext.h"

#include <unicode/unistr.h>
using namespace std;

extern "C" void sqlite3_regexp_replace(sqlite3_context *context, int argc, sqlite3_value **argv){
UnicodeString column_value_uft8 = UnicodeString::fromUTF8((const char*)sqlite3_value_text(argv[0]));
const unsigned char* pattern_utf8 = sqlite3_value_text(argv[1]);
UnicodeString pattern_replace_utf8 = UnicodeString::fromUTF8((const char*)sqlite3_value_text(argv[2]));
const boost::u32regex e = boost::make_u32regex(pattern_utf8); //from docs: UTF-8 when char size = 1
UnicodeString us = boost::u32regex_replace(column_value_uft8, e, pattern_replace_utf8);
string cs;

sqlite3_result_text( context, cs.c_str(), -1, SQLITE_TRANSIENT );

extern "C" int sqlite3_extension_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
sqlite3_create_function(db, "regexp_replace", 3, SQLITE_UTF8, 0, sqlite3_regexp_replace, 0, 0);
return 0;

then you compile this file using the command line below:

g++ -O3 -shared src/sqliteextensions.cpp \
-arch x86_64 -Xarch_x86_64 \
-framework CoreFoundation \
-L/usr/local/lib/ -lboost_regex \
-licudata -licui18n -licuio -licule -liculx -licutu -licuuc \
-o ../libsqliteextensions.dylib

now run sqlite3 (for me located in /usr/local/bin/ to have the latest version that I installed)
and type this command:

.load ../../libsqliteextensions.dylib

now you can use the regexp_replace function like:

update mytable set myfield = regexp_replace(myfield,'^[ \t]+','')

... and much more ... That's really great, isn't it?
it made my day :-)

I forgot to mention that I used ICU 4.2 and boost 1.43.
boost has been compiled with ICU, to make the regex lib aware of unicode.

Write to you soon.

ICU UnicodeString to UTF-8


This morning, I spent most of the time to know how to convert an ICU UnicodeString to an UTF-8 string.

the result is so simple, but no documentation, nowhere on google land...
The ICU documentation is obviously not so up-to-date.
I am using the latest version of ICU thought (4.2).

so to convert UnicodeString to std::string is simple as:
UnicodeString us = ...;
string cs;

so simple but so complex to find, I ended up to look at the source code...

so I hope it will be helpful for others....