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.

wget-1.12
http://ftp.gnu.org/gnu/wget/wget-latest.tar.gz
unzip/untar it (double click on it normally is enough)
>./configure
>make
>sudo make install

pkg-config-0.25
http://pkg-config.freedesktop.org/releases/pkg-config-0.25.tar.gz
unzip/untar it (double click on it normally is enough)
>./configure
>make
>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 http://anonsvn.mono-project.com/source/trunk/mono
>svn co http://anonsvn.mono-project.com/source/trunk/mcs

>cd mono

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

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

don't forget to update your .profile to add the path to mono/bin
PATH="$PATH:/usr/local/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

Hello,

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"
SQLITE_EXTENSION_INIT1


#include <unicode/unistr.h>
#include
<boost/regex/icu.hpp>
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;
us.toUTF8String(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
){
SQLITE_EXTENSION_INIT2(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.
Sylvain





ICU UnicodeString to UTF-8

Hello,

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;
us.toUTF8String(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....


lundi 19 octobre 2009

finding the week number with Excel

I had to find the week number from a date,
using it for a sql statement at the end...

in my case a week is starting from monday...

Excel is doing this calculation with the function "WEEKNUM" where the first parameter is obviously the date and the second parameter can be 1 or 2, 1 for the week starting from sunday, 2 for monday.

this function WEEKNUM is part of the add-in "Analysis ToolPak",
so don't forget to add this plugin (installed with Excel)

it saved my time today ....

Bye.

vendredi 18 septembre 2009

Git user.name user.email and default editor

Git is wonderful, much more than SVN :-)

but before to commit anything, don't forget to set the default user.name, user.email and editor:

git config --global user.name "John Doe"
git config --global user.email "john.doe@gmail.com"
git config --global core.editor "nano"


dimanche 23 août 2009

very slow to save a file in Visual Studio

Thanks to this blog

A simple file took 15 seconds to save !!!after having suffered 1 hour, I decided to investigate throught the web, I found the link above...and clearly it was exactly the solution.

I checked the registry to look
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\ProjectMRUList

some files were located on a network drive ... and did slow down all the save process :-(after deleting those registry entries, then it was fast again :-)

Cheers,
Sylvain



jeudi 13 août 2009

using a CGI with PHP-CGI

I started to learn a bit more the CGI... :-)
As it is difficult to find some documentation on the web, I will share some findings
I will use PHP-CGI as a show case.

A CGI is a program that will use the environment variables to run. The output is directly sent back to the browser.

there is two cases, the GET and the POST methods,

summary of the environment variables:

SCRIPT_FILENAME -> name of the script (seems to be specific to PHP)
QUERY_STRING -> contains the query string of the url (ie firstname=Sylvain&lastname=Pointeau)
REQUEST_METHOD -> GET or POST
CONTENT_TYPE -> ie application/x-www-form-urlencoded
CONTENT_LENGTH -> length of the posted data on stdin
HTTP_COOKIE -> the cookies

sample for a GET request:

to test it in php on unix
>export SCRIPT_FILENAME=sample.php
>export QUERY_STRING=firstname=Sylvain&lastname=Pointeau
>export CONTENT_TYPE=application/x-www-form-urlencoded
>export REQUEST_METHOD=GET
>php-cgi

... and for the POST method:

The post variables will be written in stdin for the cgi
we just need to indicate the length of the posted data via the variable
CONTENT_LENGTH

so for instance:
>export SCRIPT_FILENAME=sample.php
>export CONTENT_LENGTH=35
>export CONTENT_TYPE=application/x-www-form-urlencoded
>export REQUEST_METHOD=POST
>echo "firstname=Sylvain&lastname=Pointeau" | php-cgi


You will may encounter a issue when you will try to execute the samples:
a security issue to run php-cgi from the command line.

there is a line in the php.ini to modify:

; cgi.force_redirect is necessary to provide security running PHP as a CGI under

; most web servers. Left undefined, PHP turns this on by default. You can

; turn it off here AT YOUR OWN RISK

; **You CAN safely turn this off for IIS, in fact, you MUST.**

; http://php.net/cgi.force-redirect

cgi.force_redirect = 0


Set this variable to 0 to allow the execution of php-cgi from the console ( and not only through apache )

The best would be to have a separate php.ini and tells php to use it:
>php -c myphpfile.ini

Cheers
Sylvain