This blog embraces totally the foundamentals of the Open Source Spirit and Soul. Hence all material founded here is free and the user may read, copy, manipulate, reproduce it all, without limitations of any kind, no copyright allowed here!
Nevertheless the author will appreciate if the user will cite him, when using his scripts, as a recognition of his work.
Knowledge is the prime right of umanity and has to be protected and shared with every possible means.
abidibo.

Tuesday, November 30, 2010

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 fehfeh 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 out
Open the ~/.fulxbox/menu file and add some wallpaper voices, like

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).
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

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 run

echo $DISPLAY

take the result and put it in place of :0.0
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

$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

Thursday, October 28, 2010

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:

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.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 GODThe 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

Wednesday, July 28, 2010

-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:

/*
* 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;
}

Friday, July 9, 2010

Hi, today I'll show how to retrieve informations about a MySQL table through php in order for example to create a php class making editable a table in an automatic way (that is: stupid class, i give you a name of a table and YOU have to create its backend for me). This work is done very well by the python framework Django for example.
Now, there are several ways to do so, I'll use the interrogation of the information_schema db.
Well, let's see the code. I post here a simple function, clearly the informations that may be retrieved are more than these.

Thursday, April 1, 2010

Hi,
today I write about a nice javascript class that creates a typical horizontal scrollable list starting from an html unordered list. The final result is like many others in the web. The LI elements of a list are used to create the items of this scrollable list. The number of items visible at a time is a paramether, and if is greater than the maximum possible one, is reduced in order to get the items to stay in their space. The controller are two arrow buttons on the left and right of the slide. They have three states: ON, OFF and OVER controlled through javascript and personalizable by css. The width of the entire object and of the single item are needed, the height of the single item is not necessary because is calculated by javascript (through an iteration along all items), but clearly for a good result all items would rather have the same height.
Let's see the details now.

Imagine we have an unordered list where the LI elements are images set as css background of a DIV, for example:

Now, we want to transform it in a classical scrollable horizontal list, like the one represented in the image (the same one).
Well, here comes my mootools based javascript class which coupled with some css realizes it. First the code, then the usage

So simply we instanciate the class hScrollingList, passing the paramethers:

'hlistVideo': the id of the unordered list (we may pass even the DOM Object)

5: the number of items 'for page', that is the number of elements in the viewport for each scrolling action

600: the total width of the object

150: the width of a single item (a LI element)

Observe that the class is able to auto-reduce the number of items 'for page', because it tries to put them in the space allowed, and if thay can't stay correctly in the space their number is reduced by one untill they will.
So you only have to take this code, personalize the arrows images, the three states of the buttons through css and obtain your own personalized horizontal scrollable list.
For info or problems write at abidibo@gmail.com
Bye!