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






jeudi 11 juin 2009

SQL server and the stored procedures

I am currently at the customer site to make some reports, based on a sql server 2000.

one report is one stored procedure.

I should say that it works well! :-)
however we lack the possibility to really reuse the stored procedure like a function.

it is quickly limited but still, it stays "workable" enough.

today I was wondering how we should do that with sqlite,
-> with a file per report of course ! :-)

bye for today

lundi 25 mai 2009

SQLite and CSV files

SQLite is really great !
I use it now in almost every application I do :-)

My way to work is to combine the shell script with it,
the result is amazingly fast and clean :-)

but I "recently" solved what I imagined as the weakness of the Sqlite command line:
it is the CSV import !

in real work life, we need to treat CSV files like:
my field 1,"my opinion, my view on it", my field 3

or simply a field on multiple lines like
"my
multi-lines
field",...

the .import does not manage this kind of CSV file....

I wrote a state machine (a big switch/case) to parse the CSV file.
I progress in my state machine by getting the next character until the end of the file.

The funny thing is that I always try to rely on ".import" when I know I am using simple files,
but I had to change it for one file, the day after I wrote my own parser :-)
funny isn't it?

long life to SQLite !













Linux in the VMWare fusion (macosx)

I am since 3 years converted to the macosx... it gives me the power and freedom of unix (shell script, all gnu softwares, etc) and a superb interface with "must-have" softwares like photoshop, dreamweaver, flash, etc

... on another hand, it is good to continue to learn on linux as 99% of hosting providers are on linux. I recently had a look on a dedicated server ... linux!

then I installed the gentoo first (the one I know and I prefered few years ago), spent 2 days on it, and honestly disappointed of the long compile time...
then I installed (...just to see) a fedora 11 (preview) and a suse 11.1.
it was so fast, with a working KDE in 20 minutes !

then I tried to install the vmware-tools... a nightmare ! it doesn't compile on fedora 11, neither on suse 11.1 :-/

then I tried the fedora 10, and it worked perfectly in 2 minutes (d&d, resizable, shared folders) ... then I stay with the fedora.
-> It seems easier than the suse, I like the "yum" program.

The most funny thing is I installed KDE and gnome to compare, but gnome is better.
I am a unconditional fan of Qt and with a certain extent of KDE, but I should say that the KDE 4.1.2 is not really usable.
.... then I will stay with Gnome for now... waiting a good release of KDE :-)

Also I found that Linux in a VM is really excellent,
-> I can try without breaking anything -> snapshot / restore :-)

good work for redhat ! I was really amazed of the simplicity for installing their distribution.
(I probably become too old and go straight to the simplicity)

Good night!

Cheers
















mercredi 22 avril 2009

Unicode CString and Qt QString

arg!

with Visual Studio, if you don't define UNICODE in the PREPROCESSOR
then it is straightforward:
CString a("hello");
QString qtstring (a);

but if you define UNICODE then this code does not compile anymore :-/
you should do then:
CString a("hello");
QString qtstring = QString::fromUtf16( a.GetBuffer(), a.GetLength() );

an advise? yes, be careful to encapsulate this sort of transformation in those bloody MFC programs!

Yes I know, I should have spoken about CSV files and SQLite :-)
I will do it soon !

Bye

dimanche 19 avril 2009

My first blog

Waooo My first entry in my blog...
I am so impatient to share some technical point of views et some solutions I have found for helping myself...

stay tuned !!!