Ok after more than 2 years here again, just to say that if you want to find my entries of the last years and the future ones, you have to visit my personal website:
http://www.abidibo.net
Thursday, June 20, 2013
Tuesday, March 22, 2011
Mootools 1.3 DatePicker class
I think that DatePicker mootools class by monkeyphysics is fantastic. It is fast, well written, it has a nice layout and some awesome options like the inputOutputFormat one. Recently I upgrade to mootools 1.3 without compatibility in a project of a php framework which uses this class.
So I need to make DatePicker class working with the new release of my favourite js framework.
During the upgrade work I found and fixed a bug in the date selection when selecting a day of the previous/next year in january/december months view.
Moreover I added the z-index management so that the calendar is always shown above all document elements.
Maybe more improvemets will come in the next future.
My project is a fork of the original one and hosted on my github repository.
From command line you may simply clone my project
So I need to make DatePicker class working with the new release of my favourite js framework.
During the upgrade work I found and fixed a bug in the date selection when selecting a day of the previous/next year in january/december months view.
Moreover I added the z-index management so that the calendar is always shown above all document elements.
Maybe more improvemets will come in the next future.
My project is a fork of the original one and hosted on my github repository.
From command line you may simply clone my project
git clone git://github.com/abidibo/mootools-datepicker.git
Etichette:
datepicker,
javascript,
mootools
Monday, March 21, 2011
XDebugButton. Php XDebug with Vim.
Vim is fucking awesome. Vim is fucking extensible.
You may find a lot of plugins transforming it in a perfect IDE for you programming language.
One of the best plugin for php programmers is xdebug, which runs a debug session right into vim.
On the web you may find many articles, explaining how-to install it and make it working (it involves some configurations in vim, php.ini), here is the one I read.
Once you have installed it and made it working, you'll know that to activate the connection between vim and the server you have to recharge the web page passing a get variable: XDEBUG_SESSION_START=1
Now here comes my work, very easy indeed, but was my first firefox addon developement.
I wrote a firefox extension that appends automatically the paramether at the url, checking for the right symbol to insert (& or ?).
You may find my addon source, with the instructions on how-to install it on my github account here.
From command line you may simply clone my project (install git first)
You may find a lot of plugins transforming it in a perfect IDE for you programming language.
One of the best plugin for php programmers is xdebug, which runs a debug session right into vim.
On the web you may find many articles, explaining how-to install it and make it working (it involves some configurations in vim, php.ini), here is the one I read.
Once you have installed it and made it working, you'll know that to activate the connection between vim and the server you have to recharge the web page passing a get variable: XDEBUG_SESSION_START=1
Now here comes my work, very easy indeed, but was my first firefox addon developement.
I wrote a firefox extension that appends automatically the paramether at the url, checking for the right symbol to insert (& or ?).
You may find my addon source, with the instructions on how-to install it on my github account here.
From command line you may simply clone my project (install git first)
git clone git://github.com/abidibo/XDebug-Button---Firefox-Add-on.git
If you find errors or bugs please write to abidibo@gmail.com.
Friday, March 4, 2011
Add total time logged in infos to SMF message posters
Well,
some hours ago I had the need to show the total time logged in info in the poster message area below the number of posts published by the member.
The forum platform is SMF, I 've just started working with it so I can't give a professional opinion about it.
Now what we have to do to achieve our goal is what follows.
I displayed the count of time in this form;
xd xh xm
you can show it as
x days x hours and x minutes
or in the form you want, you only have to edit the language locate files of the languages you're interedsted in and set the text you prefer, you may define new strings and so on. Brutally you may also print the string you want directly into the template without using the locate system.
Hasta la proxima siempre.
some hours ago I had the need to show the total time logged in info in the poster message area below the number of posts published by the member.
The forum platform is SMF, I 've just started working with it so I can't give a professional opinion about it.
Now what we have to do to achieve our goal is what follows.
- Edit the /Sources/Load.php file.
goto line 838 (inside the loadMemberData method) and add to the fields selected by the query the one we want: mem.totalTimeLoggedIn - Well, now the information we want is selected from db.
- Goto line 1006 (inside loadMemberContext method). Here the member context variable to be passed to the template is prepared. We have to add our informations to the array returned by this method, so add the following key=>value pair to the $memberContext[$user] array:
'total_time_logged_in' => array(
'days' => floor($profile['totalTimeLoggedIn'] / 86400),
'hours' => floor(($profile['totalTimeLoggedIn'] % 86400) / 3600),
'minutes' => floor(($profile['totalTimeLoggedIn'] % 3600) / 60)
) - Well done, now our information is present in the context member variable passed to the template we have to edit. Notice that we have divided the amount of time in days, hours and minutes.
- Now we have to show this information in the right place, that is the right template, which is /Themes/default/Display.template.php, or the one corresponding to your used theme if present in the theme folder. Open the file and goto line 316. At this line are printed the informations about the number of posts written by the message poster, so below that we insert our code:
// Show how many posts they have made.
echo '
', $txt[26], ': ', $message['member']['posts'], '
';
// Show total time online.
if (!empty($message['member']['total_time_logged_in'])) {
echo '
', $txt['totalTimeLogged1'];
// If days is just zero, don't bother to show it.
if ($message['member']['total_time_logged_in']['days'] > 0)
echo $message['member']['total_time_logged_in']['days'], $txt['totalTimeLogged5'];
// Same with hours - only show it if it's above zero.
if ($message['member']['total_time_logged_in']['hours'] > 0)
echo $message['member']['total_time_logged_in']['hours'], $txt['totalTimeLogged6'];
// But, let's always show minutes - Time wasted here: 0 minutes ;).
echo $message['member']['total_time_logged_in']['minutes'], $txt['totalTimeLogged7'], '<br /><br />';
}
else echo '<br />';
I displayed the count of time in this form;
xd xh xm
you can show it as
x days x hours and x minutes
or in the form you want, you only have to edit the language locate files of the languages you're interedsted in and set the text you prefer, you may define new strings and so on. Brutally you may also print the string you want directly into the template without using the locate system.
Hasta la proxima siempre.
Etichette:
php,
programming,
smf
Tuesday, November 30, 2010
HowTo randomly change fluxbox wallpaper every n minutes
Some weeks ago' I've discovered this fantastic WM (Windows Manager), thanks to Gentoo/Sabayon + GNOME dbus sessions problems with my Imac. I desired so much to learn something about portage and the gentoo world that I accepted going on without gnome. Fortunatelly.
Fluxbox is a very light and high configurable WM for X server, super super fast and with all such things one need to work fine (alt-tab to move around opened windows, a nice bar showing opened applications and so on). It doesn't have icons by default, but has an amazing menu totally and easily configurable showing up when clicking on the desktop.
Here I want to show how is possible to set a cronjob task that changes randomly the desktop wallpaper every 5 minutes.
FIRST: install feh
feh is a fast, lightweight image viewer, supporting many image formats that we'll use to show the wallpaper. So
Open the ~/.fulxbox/menu file and add some wallpaper voices, like
Now clicking on the desktop and selecting a wallpaper voice from the menu should change our fluxbox wallpaper, if not maybe there were some problems during the installation of feh, try solving them and continue.
THIRD: make a script that changes the background randomly
So put all the desired images inside a folder and then copy this code in a file that we'll call chgWallpaper.sh
The second line of the script launches fbsetbg passing it one (tail -1) file randomly (sort -R) taken from the ~/Wallpapers directory (ls).
FOURTH: schedule the script with crontab
Now we have to schedule this script. My system has vixie-cron, many others uses crond, it's the same. We want to schedule the script as normal user (abidibo in my case), so
TROUBLESHOOTING
If this doesn't work may be it happens something like what happened to me.
Read your system log file, in my case
If you notice somithing like
Now if it still doesn't work and your system log says something like
That's all. Hasta la proxima siempre!
Fluxbox is a very light and high configurable WM for X server, super super fast and with all such things one need to work fine (alt-tab to move around opened windows, a nice bar showing opened applications and so on). It doesn't have icons by default, but has an amazing menu totally and easily configurable showing up when clicking on the desktop.
Here I want to show how is possible to set a cronjob task that changes randomly the desktop wallpaper every 5 minutes.
FIRST: install feh
feh is a fast, lightweight image viewer, supporting many image formats that we'll use to show the wallpaper. So
$sudo emerge feh
SECOND: try it outOpen the ~/.fulxbox/menu file and add some wallpaper voices, like
[submenu] (Wallpaper)
[exec] (tamars) {fbsetbg -f /home/abidibo/Wallpapers/sabayon_t.png}
[exec] (minus_tamars) {fbsetbg -f /home/abidibo/Wallpapers/sabayon.png}
[exec] (matrix) {fbsetbg -f /home/abidibo/Wallpapers/sabayon_matrix.jpg}
[exec] (winzoz) {fbsetbg -f /home/abidibo/Wallpapers/winzoz.jpg}
[exec] (toilet) {fbsetbg -f /home/abidibo/Wallpapers/toilet.jpg}
[exec] (linuxVSwin) {fbsetbg -f /home/abidibo/Wallpapers/linuxvswin.jpg}
[end]
fbsetbg is a wrapper that searches for a image viewer in order to set the fulxbox background (in our case it'll use feh, but other programs may be used).[exec] (tamars) {fbsetbg -f /home/abidibo/Wallpapers/sabayon_t.png}
[exec] (minus_tamars) {fbsetbg -f /home/abidibo/Wallpapers/sabayon.png}
[exec] (matrix) {fbsetbg -f /home/abidibo/Wallpapers/sabayon_matrix.jpg}
[exec] (winzoz) {fbsetbg -f /home/abidibo/Wallpapers/winzoz.jpg}
[exec] (toilet) {fbsetbg -f /home/abidibo/Wallpapers/toilet.jpg}
[exec] (linuxVSwin) {fbsetbg -f /home/abidibo/Wallpapers/linuxvswin.jpg}
[end]
Now clicking on the desktop and selecting a wallpaper voice from the menu should change our fluxbox wallpaper, if not maybe there were some problems during the installation of feh, try solving them and continue.
THIRD: make a script that changes the background randomly
So put all the desired images inside a folder and then copy this code in a file that we'll call chgWallpaper.sh
#!/bin/bash
export DISPLAY=:0.0
fbsetbg -f /home/abidibo/Wallpapers/$(ls ~/Wallpapers | sort -R | tail -1)
Why we export the DISPLAY variable? Well, we always have to remember that the processes started by cron have no (or almost no) normal environment setup, and our script require this variable. So from terminal as normal user runexport DISPLAY=:0.0
fbsetbg -f /home/abidibo/Wallpapers/$(ls ~/Wallpapers | sort -R | tail -1)
echo $DISPLAY
take the result and put it in place of :0.0The second line of the script launches fbsetbg passing it one (tail -1) file randomly (sort -R) taken from the ~/Wallpapers directory (ls).
FOURTH: schedule the script with crontab
Now we have to schedule this script. My system has vixie-cron, many others uses crond, it's the same. We want to schedule the script as normal user (abidibo in my case), so
$sudo crontab -u abidibo -e
This commands opens your favourite editor, now we have to insert the job:*/5 * * * * /bin/bash /home/abidibo/Scripts/chgWallpaper.sh
This way the script is run every 5 minutes. Now we save the file and exit and the new crontab is installed. We wait 5 minutes and our desktop background should change, if not go on reading.TROUBLESHOOTING
If this doesn't work may be it happens something like what happened to me.
Read your system log file, in my case
$sudo vim /var/log/messages
and search for cron messages.If you notice somithing like
Nov 30 14:35:01 localhost cron[7500]: (abidibo) CMD (bash /home/abidibo/Scripts/chgWallpaper.sh)
Nov 30 13:35:01 localhost postfix/postdrop[7511]: warning: unable to look up public/pickup: No such file or directory
Then you're welcome. Here we have a postfix problem, the pickup FIFO (files used by different processes to communicate) file is not present in your system, we have to create it, runNov 30 13:35:01 localhost postfix/postdrop[7511]: warning: unable to look up public/pickup: No such file or directory
$sudo mkfifo /var/spool/postfix/public/pickup
$sudo /etc/init.d/postfix restart
And that should be fix it. $sudo /etc/init.d/postfix restart
Now if it still doesn't work and your system log says something like
Nov 30 14:44:00 localhost postfix/local[7846]: fatal: open database /etc/mail/aliases.db: No such file or directory
you're welcome! It means you don't have that file. So you need to create it running the command$sudo newaliases
$sudo /etc/init.d/postfix restart
Now cron may comunicate with you and send you emails that you may read by$sudo /etc/init.d/postfix restart
$vim /var/mail/USERNAME
In my case cron was happy to say me such thingFrom abidibo@abidibo-sabayon.localdomain Tue Nov 30 15:29:01 2010
Return-Path: <abidibo@abidibo-sabayon.localdomain>
X-Original-To: abidibo
Delivered-To: abidibo@abidibo-sabayon.localdomain
Received: by abidibo-sabayon.localdomain (Postfix, from userid 1000)
id 999DDD9E654; Tue, 30 Nov 2010 15:29:01 +0100 (CET)
From: root@abidibo-sabayon.localdomain (Cron Daemon)
To: abidibo@abidibo-sabayon.localdomain
Subject: Cron <abidibo@abidibo-sabayon> /bin/bash /home/abidibo/Scripts/chgWallpaper.sh
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/abidibo>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=abidibo>
X-Cron-Env: <USER=abidibo>
Message-Id: <20101130142901.999DDD9E654@abidibo-sabayon.localdomain>
Date: Tue, 30 Nov 2010 15:29:01 +0100 (CET)
Error: Can't open display:
That led me to add the "export DISPLAY=:0.0" line in my script (thing that you've already done).Return-Path: <abidibo@abidibo-sabayon.localdomain>
X-Original-To: abidibo
Delivered-To: abidibo@abidibo-sabayon.localdomain
Received: by abidibo-sabayon.localdomain (Postfix, from userid 1000)
id 999DDD9E654; Tue, 30 Nov 2010 15:29:01 +0100 (CET)
From: root@abidibo-sabayon.localdomain (Cron Daemon)
To: abidibo@abidibo-sabayon.localdomain
Subject: Cron <abidibo@abidibo-sabayon> /bin/bash /home/abidibo/Scripts/chgWallpaper.sh
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/abidibo>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=abidibo>
X-Cron-Env: <USER=abidibo>
Message-Id: <20101130142901.999DDD9E654@abidibo-sabayon.localdomain>
Date: Tue, 30 Nov 2010 15:29:01 +0100 (CET)
Error: Can't open display:
That's all. Hasta la proxima siempre!
Thursday, October 28, 2010
Load local XML through AJAX request problems in IE
Have you got a simple html-js-xml project (doesn't need a server) that works locally on firefox but not in IE? You're welcome!
Understanding the problem
Let's see my example... I had an html document which only charges an external javascript which has the due to load an xml file representing a flowchart and simulate a navigation through the tree, with conditional steps and forwards steps.
Even if I'm a mootools lover, for this project I used jQuery because the mootools core 1.2.x xml loader doesn't work for IE in any case.
So I used jQuery ajax method to load the xml this way:
The scenario
- Application hosted on a server
works if visited with any browser and any OS
- Application hosted on my local server running on Ubuntu 9.04
works if visited with any browser and any OS
- Application hosted on a PC with Windows XP not under a server
works with firefox but not with IE
OH MY GOD
The answer
So at the end I gained the solution. The problem is that I was trying to get the responseXML from the ajax object, but without a server "telling" the browser that yes, that content is really an XML. Moreover (OH OH) IE is not so intelligent as to understand this things without help.
The solution
So what may we do? Simple. We get not the responseXML but the responseText and then load it using the loadXML method of the ActiveXObject. What follow is my example code
Saludos
Understanding the problem
Let's see my example... I had an html document which only charges an external javascript which has the due to load an xml file representing a flowchart and simulate a navigation through the tree, with conditional steps and forwards steps.
Even if I'm a mootools lover, for this project I used jQuery because the mootools core 1.2.x xml loader doesn't work for IE in any case.
So I used jQuery ajax method to load the xml this way:
var xml = $.ajax({
async: false,
type:"GET",
context: this,
url: chart_path,
dataType:"xml"
}).responseXML;
Now, I thought at my xml variable as a DOM object over which use all the traversing methods implemented by jQuery. That was true... in some cases.async: false,
type:"GET",
context: this,
url: chart_path,
dataType:"xml"
}).responseXML;
The scenario
- Application hosted on a server
works if visited with any browser and any OS
- Application hosted on my local server running on Ubuntu 9.04
works if visited with any browser and any OS
- Application hosted on a PC with Windows XP not under a server
works with firefox but not with IE
OH MY GOD
The answer
So at the end I gained the solution. The problem is that I was trying to get the responseXML from the ajax object, but without a server "telling" the browser that yes, that content is really an XML. Moreover (OH OH) IE is not so intelligent as to understand this things without help.
The solution
So what may we do? Simple. We get not the responseXML but the responseText and then load it using the loadXML method of the ActiveXObject. What follow is my example code
var xmltext = $.ajax({
async: false,
type:"GET",
context: this,
url: chart_path,
dataType:"xml"
}).responseText;
if($.browser.msie) {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.loadXML(xmltext);
}
else {
parser = new DOMParser();
xml = parser.parseFromString(xmltext, "text/xml");
}
Now my xml variable is ready and contains the desired XML object.async: false,
type:"GET",
context: this,
url: chart_path,
dataType:"xml"
}).responseText;
if($.browser.msie) {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.loadXML(xmltext);
}
else {
parser = new DOMParser();
xml = parser.parseFromString(xmltext, "text/xml");
}
Saludos
Wednesday, July 28, 2010
HowTo navigate through a tree without recursive methods (while loop instead)
-Hi,
today I was simply writing a local template in order to render a menu following the MVC pattern.
Now my local template system does not use a meta-language, but loops, if statements and so on are written directly in php, because I don't have enough time to write an interpreter.
So really I can use all php functionalities in my templates including recursive functions. But it's not the way I want to follow, moreover maybe some day I'll find the time to write my interpreter and then will be very easy to "convert" if statements and cycles, not so easy if not impossible to convert recursive functions.
Well, so the problem was the following:
I have a n-dimensional menu tree, and have to generate the classical html code for such a menu, that is something like:
today I was simply writing a local template in order to render a menu following the MVC pattern.
Now my local template system does not use a meta-language, but loops, if statements and so on are written directly in php, because I don't have enough time to write an interpreter.
So really I can use all php functionalities in my templates including recursive functions. But it's not the way I want to follow, moreover maybe some day I'll find the time to write my interpreter and then will be very easy to "convert" if statements and cycles, not so easy if not impossible to convert recursive functions.
Well, so the problem was the following:
I have a n-dimensional menu tree, and have to generate the classical html code for such a menu, that is something like:
<ul id="nav">
<li>Voice1</li>
<li>Voice2
<ul>
<li>Voice21</li>
<li>Voice22</li>
</ul>
</li>
<li>Voice3</li>
</ul>
So let's see HOW TO get this without recursion. The code is well commented, here it goes:<li>Voice1</li>
<li>Voice2
<ul>
<li>Voice21</li>
<li>Voice22</li>
</ul>
</li>
<li>Voice3</li>
</ul>
<?php
/*
* Menu tree is represented by an n-dimensional array.
* Array keys are the labels and array values are either a link
* or a submenu (another array)
*/
$voices["Home"] = array("Home1" => array("Home11"=>"#"), "Home2"=>array("Home21"=>"#"));
$voices["News"] = array("News1" => "#", "News2"=>array("News21"=>"#"));
$voices[_("About")] = array("About1"=>array("About11"=>array("About111"=>"#", "About112"=>"#")), "About2"=>"#");
$voices[_("Services")] = '#';
$voices[_("Faq")] = '#';
/*
* INIT SOME VARIABLES
*/
// control the exit from the loop
$continue = true;
// this variables stores the branch currently analized
$parsed = $voices;
// stores all the branches parsered, because the tree is navigated following a branch
// until the foil. So when returning on top levels the navigation must continue on
// branches interrupted earlier.
$tree = array();
// stores the last key of the current branch array
$last = null;
echo "<ul id=\"nav\">\n";
/*
* THE MAIN LOOP
*/
while($continue === true) {
// if the value of the current element parsered is an array than has a submenu
if(is_array(current($parsed))) {
// echo the current voice and open a new submenu (ul)
echo "<li><a href=\"#\">".key($parsed)."</a>\n<ul>\n";
// we're going to begin navigate the branch ->
// we store the branch we're leaving in the tree array
$tree[] = $parsed;
// the branch to analyze is now the submenu
$parsed = current($parsed);
// get the last key of the new branch
end($parsed);
$last = key($parsed);
// reset the array pointer
reset($parsed);
}
// else if the value of the current element is not an array (but a link)
// and not false (i.e. after calling next on the last element of an array)
elseif(current($parsed)!==false) {
// echo the current voice
echo "<li><a href=\"".current($parsed)."\">".key($parsed)."</a></li>\n";
// if the voice printed is the last of its branch
// than close the submenu and get the last branch stored in the
// varable tree (the parent branch) as the one to follow parsering
if(key($parsed)==$last) {
echo "</ul></li>\n";
$parsed = array_pop($tree);
}
// move the pointer to the next element
next($parsed);
}
// else the value of the current element is false -> we have already passed the last element
// then we close the submenu and get the parent branch as the current one, passing to the next element
else {
echo "</ul></li>";
$parsed = array_pop($tree);
next($parsed);
}
// if we are navigating the first tree level and have passed through all them -> exit
if(count($tree)==0 && current($parsed)==false) $continue = false;
}
echo "</ul>\n";
?>
Hasta la proxima!
/*
* Menu tree is represented by an n-dimensional array.
* Array keys are the labels and array values are either a link
* or a submenu (another array)
*/
$voices["Home"] = array("Home1" => array("Home11"=>"#"), "Home2"=>array("Home21"=>"#"));
$voices["News"] = array("News1" => "#", "News2"=>array("News21"=>"#"));
$voices[_("About")] = array("About1"=>array("About11"=>array("About111"=>"#", "About112"=>"#")), "About2"=>"#");
$voices[_("Services")] = '#';
$voices[_("Faq")] = '#';
/*
* INIT SOME VARIABLES
*/
// control the exit from the loop
$continue = true;
// this variables stores the branch currently analized
$parsed = $voices;
// stores all the branches parsered, because the tree is navigated following a branch
// until the foil. So when returning on top levels the navigation must continue on
// branches interrupted earlier.
$tree = array();
// stores the last key of the current branch array
$last = null;
echo "<ul id=\"nav\">\n";
/*
* THE MAIN LOOP
*/
while($continue === true) {
// if the value of the current element parsered is an array than has a submenu
if(is_array(current($parsed))) {
// echo the current voice and open a new submenu (ul)
echo "<li><a href=\"#\">".key($parsed)."</a>\n<ul>\n";
// we're going to begin navigate the branch ->
// we store the branch we're leaving in the tree array
$tree[] = $parsed;
// the branch to analyze is now the submenu
$parsed = current($parsed);
// get the last key of the new branch
end($parsed);
$last = key($parsed);
// reset the array pointer
reset($parsed);
}
// else if the value of the current element is not an array (but a link)
// and not false (i.e. after calling next on the last element of an array)
elseif(current($parsed)!==false) {
// echo the current voice
echo "<li><a href=\"".current($parsed)."\">".key($parsed)."</a></li>\n";
// if the voice printed is the last of its branch
// than close the submenu and get the last branch stored in the
// varable tree (the parent branch) as the one to follow parsering
if(key($parsed)==$last) {
echo "</ul></li>\n";
$parsed = array_pop($tree);
}
// move the pointer to the next element
next($parsed);
}
// else the value of the current element is false -> we have already passed the last element
// then we close the submenu and get the parent branch as the current one, passing to the next element
else {
echo "</ul></li>";
$parsed = array_pop($tree);
next($parsed);
}
// if we are navigating the first tree level and have passed through all them -> exit
if(count($tree)==0 && current($parsed)==false) $continue = false;
}
echo "</ul>\n";
?>
Subscribe to:
Posts (Atom)