// LM is the number of days in one year = 365.25/12 days
var ds, aux, D0, D1, DD, DM, DY, LM = 30.4375;
// The returned format date is dd-mm-yy
// JavaScript Date object uses yy-mm-dd
ds = getValue("CrmForm_contract_sdate");
var aux = ds.split("-");
ds = aux[2] + "-" + aux[1] + "-" + aux[0];
D0 = new Date(ds.replace(/\D+/g, "/"));
ds = getValue("Calculator_contract_edate");
aux = ds.split("-");
ds = aux[2] + "-" + aux[1] + "-" + aux[0];
D1 = new Date(ds.replace(/\D+/g, "/"));
// D0 and D1 have the representation of the Date in miliseconds
// Now a day has 24*60*60*1000 miliseconds
DD = Math.round((D1 - D0) / 86400000);
DM = DD / LM | 0;
DD = Math.round(DD - DM * LM);
DY = DM / 12 | 0;
DM %= 12;
aux = DY + "Year";
if (DY>1 || DY==0)
aux += "s, ";
else
aux += ", ";
aux += DM + "Month";
if (DM>1 || DM==0)
aux += "s, ";
else
aux += ", ";
aux += DD + "Day";
if (DD>1 || DD==0)
aux += "s, ";
else
aux += ", ";
$("#lnyears").html("<font color=\"red\" size=\"3\">" + aux + "</font>");
Thursday, 15 March 2012
Monday, 20 February 2012
Setting up Git to manage a website project
In the server:
This is where your code lives, in your DocumentRoot:
$ cd /var/www
$ mkdir mysite
This is the remote repository:
$ cd /home/user
$ mkdir mysite.git && mysite.git
$ git init --bare
Initialized empty Git repository in /home/user/mysite.git/
$ vi mysite.git/hooks/post-receive
~
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f
~
~
~
And in the local machines:
$ cd /var/www
$ mkdir mysite && cd mysite
$ git init
Initialized empty Git repository in /var/www/mysite/.git/
$ git remote add web ssh://<user>@<server_url>/home/user/mysite.git
$ git push web +master:refs/heads/master
$ echo 'Hello, world!' > index.html
$ git add index.html
$ git commit -m "first commit"
$ git push web
Then:
Another user could clone the remote repository:
git clone ssh://<user>@<server_url>/home/user/mysite.git
This is where your code lives, in your DocumentRoot:
$ cd /var/www
$ mkdir mysite
This is the remote repository:
$ cd /home/user
$ mkdir mysite.git && mysite.git
$ git init --bare
Initialized empty Git repository in /home/user/mysite.git/
$ vi mysite.git/hooks/post-receive
~
#!/bin/sh
GIT_WORK_TREE=/var/www/www.example.org git checkout -f
~
~
~
And in the local machines:
$ cd /var/www
$ mkdir mysite && cd mysite
$ git init
Initialized empty Git repository in /var/www/mysite/.git/
$ git remote add web ssh://<user>@<server_url>/home/user/mysite.git
$ git push web +master:refs/heads/master
$ echo 'Hello, world!' > index.html
$ git add index.html
$ git commit -m "first commit"
$ git push web
Then:
Another user could clone the remote repository:
git clone ssh://<user>@<server_url>/home/user/mysite.git
Monday, 13 February 2012
Accessing MySQL from PHP error
I was getting this weird error on Yii:
CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 111
If you are accessing MySQL from PHP and both reside on the same server you must use localhost as the server name on the MySQL configuration file. Like this one I had on my Yii application.
On my Yii config/main.php I changed this:
'connectionString' => 'mysql:host=<host_url>;dbname=<db_name>',
For this:
'connectionString' => 'mysql:host=localhost;dbname=<db_name>',
This post saved my life: MySQL Forums
CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2013] Lost connection to MySQL server at 'reading initial communication packet', system error: 111
If you are accessing MySQL from PHP and both reside on the same server you must use localhost as the server name on the MySQL configuration file. Like this one I had on my Yii application.
On my Yii config/main.php I changed this:
'connectionString' => 'mysql:host=<host_url>;dbname=<db_name>',
For this:
'connectionString' => 'mysql:host=localhost;dbname=<db_name>',
This post saved my life: MySQL Forums
Subscribe to:
Posts (Atom)