Archive for the ‘Software’ Category

Treball de recerca: Projecte Gilean

diumenge, març 22nd, 2009

Ja és el meu tercer any a la Facultat d’Informàtica de Barcelona. He trobat el codi del treball de recerca de segon de batxillerat a l’Escola Joan Pelegrí d’Hostafrancs (coses de tenir GNU/Linux, que no s’ha de formatar gaire sovint), i he pensat que estaria bé penjar el document sencer. Amb un company, Víctor Díaz Jiménez (que ara fa Enginyeria de Telecomunicacions a La Salle), vam muntar un robot controlat amb el port paral·lel. Funcionava de forma teledirigida amb l’ordinador, programada llegint un fitxer de text, o de forma autosuficient. Està programat amb Visual Basic 6, tot i que la idea inicial era fer-ho en C++ o Java i sota Linux, però no va ser possible.

Deixo aquí el text, el codi i unes fotos. Probablement necessiteu la biblioteca io.dll, que trobareu a geekhideout.

Aquesta obra està subjecta a una llicència Reconeixement-NoComercial-CompartirIgual 2.5 de
Creative Commons. Per veure’n una còpia, visiteu http://creativecommons.org/licenses/by-nc-
sa/2.5/ o envieu una carta a Creative Commons, 559 Nathan Abbott Way, Stanford, California
94305, USA.

Projecte Gilean: zip que conté el document, llicències, i annexos

Codi de C-Gilean: programari de control del robot construït

El codi té llicència GPL. Atenció estudiants de batxillerat: GPL vol dir que en podeu fer el que vulgueu, però és obligat reconèixer l’autor original «Eduard Gamonal» i mantenir la llicència.

Captures del programari:

i del robot

Shell, find it! Some examples of the find command line tool

dilluns, març 16th, 2009

Have you lost something? You may fall in love with the find command. GNU Find tells you where a file is, given a condition. You shall use regular expressions and parameters related to lots of file features, like last access date, last modification date, its i-node, the file format of the device where it’s being saved, etc.

The syntax is find dir1 … dirM cond1 .. condN. It will search the directory tree rooted at each diri, for i = 1 to M, all files matching conditions cond1 to condN evaluated from left to right.

Let’s see some examples:

  1. find /bin -links +1
    Searches files in /bin and its subdirectories having 1 or more hard links.
  2. find /bin -links +1 -type f
    Idem, but only matches regular files (-type f).
  3. find -size +8k -printf ‘%p %s\n’
    If no directory root is given, the default is . (the working one). This command seeks files whose size is at least 8KB and writes its name and size.
  4. find . -name core -exec rm -i {} \; -print
    Looks for files called «core» (-name core), asks for confirmation to delete them (-exec rm -i {} \;) and, after all, prints their name (-print). Notice that you can run any command with «-exec». In rm -i, -i stands for «Ask for a confirmation», and «{}» means «the file matching the conditions». «-exec» must be closed with «\;».
  5. find /usr/include -name ‘*.h’ -exec grep -H SIGCHLD {} \;
    Looks from /usr/include on all files with the extension .h (-name ‘*.h’, with quotes to avoid the shell understanding the * as a metacharacter and letting the find command use it) and having the string «SIGCHLD». That is, for each file that has matched the conditions, «grep -H SIGCHLD» is run.
  6. find -atime +1 -type f -exec mv {} TMP \;
    Moves files that haven’t been accessed today (-atime +1) to the dir called TMP, in our working directory.

Thanks FIB.

Impressive Impressive

dimecres, març 11th, 2009

Last Saturday I went to uni to attend a few afternoon conferences, organised by FiberParty (ca). There was a talk about graphic design (integrating Inkscape, The Gimp, Scribus and Blender), and another one, very interesting, about Python. I’m sorry I can’t remember the name of the guy who talked, but I remember he used a little app called Impressive (written in Python, of course).

It’s a command line tool to improve our PDF presentations by making them more eye candy. Ow, but you’ve got OpenOffice.org+OpenGL running on a fashionable portable computer with GNU/Linux. I do, too :) but Impressive is also useful:

I don’t really like laser pointers; I reckon they are too small. This tool has solved it :) Look below. I’d like to make the audience pay attention to an iPod shown in the picture.

1b.jpg 1.jpg

It’s a screenshot of a PDF presentation I run like:

edu@debian:~/Impressive-0.10.2$ ./impressive.py ~/Desktop/mll-aep.pdf

When I reached the slide on the left, I pressed enter and the mouse became a big circle. I press enter again and everything goes back to the previous state.

We can draw a box arround the desired area to highlight it, like that:

2.jpg [singlepic id="20" w="320" h="" mode="" float="left" ]

Useful, huh? Highlighting code is easier :) There are more cool features, like an OSD display: run your presentation and press T. You’ll see a little timer to know how long you have been boring your audience. You don’t like having random transition effects? just add the parameter -t:
edu@debian:~/Impressive-0.10.2$ ./impressive.py -t SlideRight ~/Desktop/mll-aep.pdf

And, as usual, type

edu@debian:~/Impressive-0.10.2$ ./impressive.py –help

For further information :)

RSS reader in PHP, compatible with ccHost 4.5

diumenge, març 8th, 2009

Here a plugin for ccHost 4.5 or 5 to get RSS feeds and show them on your cchost_files/*.xml . It may be used out of ccHost without problems. Written in PHP5. License GPL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
function getRSS($feed, $limit = 3) {
    // $feed must be a valid RSS url.
    // the function will return an array with the basic information for our news.
    // print_r($RSSData); for further information.
    // License: GPL  - Eduard Gamonal <edu at eduard-gamonal dot net>
 
    $feedData = file_get_contents($feed);
    $RSSData = new SimpleXMLElement($feedData);
 
    $news = array();
 
    $c = count($RSSData->channel->item);
    for ($i = 0; $i < $limit  and $i < $c; $i++) {
        $news[$i]['title'] = (string)$RSSData->channel->item[$i]->title;
        $news[$i]['link'] = (string)$RSSData->channel->item[$i]->link;
        $news[$i]['pubDate'] = (string)$RSSData->channel->item[$i]->pubDate;
        $news[$i]['description'] = (string)$RSSData->channel->item[$i]->description;
    }
 
    return $news;
}
?>

ccHost 4.5: Moderation control panel

diumenge, març 8th, 2009

When I started developing MusicaLliure.cat with ccHost 4.5, we needed a moderation control panel. It’s not used any more, since we coded a «flag it!» system to avoid having someone approving every new uploaded song.
Anyway, here it is the code, in case someone finds it useful. Notice that your moderators should have permission to publish/unpublish content, but not your users, obviously.
The css is *in* the file, but just feel free to put it in a separate file, as I like.

How does it look like? The moderator sees the queue. For each song, the title, author, a player and two buttons are shown. If the moderator clicks on the title or the author, a search is performed (Google).

As usual, you have to place the code below in local_files/viewfile, and the php part in local_files/lib/

License: GPL

<div>
 
<tal:block define="pendents php:cancons_pendents_de_moderacio()" /> 
<tal:block define="blocades php:cancons_blocades()" /> 
 
<style type="text/css">
 
.cpm {
    margin:15px auto 15px auto;
}
 
.cpm td{
    padding:5px;
    border:1px solid silver;
 
}
 
.cpm td#cpm_aprovala {
    background-color:green;
}
 
.cpm td#cpm_blocala {
    background-color:#cc0000;
}
 
#cpm_aprovala a, #cpm_blocala a {
    color:white;
    font-weight:bold;
}
 
#cpm_aprovala a:hover, #cpm_blocala  a:hover {
    color:silver;
}
 
.cpm td#cpm_idfitxer {
    text-align:center;
}
 
.cpm caption {
    font-size:1.2em;
    font-weight:bold;
}
 
</style>
<h2>Cançons pendents de moderació</h2>
<p><b>Autors</b>: per motius d&#39;etiqueta i educaci&oacute;, com per exemple evitar enviar els administradors a pres&oacute;, MusicaLliure.cat disposa d&#39;un equip de moderaci&oacute; que escolta i comprova que les can&ccedil;ons tinguin la llic&egrave;ncia adequada. Aqu&iacute; nom&eacute;s podeu veure les vostres, tot i que n&#39;hi pot haver m&eacute;s.</p>
<p><b>Moderadors</b>: cal escoltar total o parcialment la can&ccedil;&oacute; abans d&#39;aprovar-la. Si detecteu que incompleix els requisits de MusicaLliure.cat, bloqueu-la. Si ho dubteu, podeu fer clic al t&iacute;tol o al nom de l&#39;autor per fer-ne una cerca al Google. Nom&eacute;s quan estigueu segurs que la can&ccedil;&oacute; pot ser publicada, aproveu-la. Si us equivoqueu, que no us entri el p&agrave;nic. A la p&agrave;gina de la can&ccedil;&oacute; trobareu com blocar-la o despublicar-la.</p>
 
 
<table class="cpm">
<caption>Can&ccedil;ons pendents de moderaci&oacute;</caption>
<thead>
    <th>ID fitxer</th>
    <th>T&iacute;tol</th>
    <th>Autor</th>
    <th>Reproductor</th>
    <th>Penja-la</th>
    <th>Bloca-la</th>
</thead>
<tr tal:repeat="record pendents">
    <td id="cpm_idfitxer">
        <a href="http://beta.musicalliure.net/media/files/${record/user_name}/${record/upload_id}">${record/files/0/file_id}</a>
    </td>
 
    <td>
         <a href="http://www.google.com/search?hl=ca&q=%22${record/upload_name}%22">${record/upload_name}</a>
    </td>
 
    <td>        
        <a href="http://www.google.com/search?hl=ca&q=%22${record/user_real_name}%22">${record/user_real_name}</a>
    </td>
 
    <td>
        <object type="application/x-shockwave-flash" width="200" height="20" data="http://beta.musicalliure.net/cclib/xspf_player/xspf_player_slim.swf?autoload=0&song_url=http://beta.musicalliure.net/media/download/${record/user_name}/${record/files/0/file_id}/${record/files/0/file_name}">
        <param name="movie" value="http://beta.musicalliure.net/cclib/xspf_player_slim.swf?autoload=0&song_url=http://beta.musicalliure.net/media/download/${record/user_name}/${record/files/0/file_id}/${record/files/0/file_name}" />
        </object>
    </td>
 
    <td id="cpm_aprovala">
        <a href="http://beta.musicalliure.net/media/files/publish/${record/user_name}/${record/upload_id}">Aprova-la</a>
    </td>
 
    <td id="cpm_blocala">
        <a href="http://beta.musicalliure.net/media/admin/ban/${record/upload_id}">Bloca-la</a>
    </td>
 
</tr>
</table>
 
 
<table class="cpm">
<caption>Can&ccedil;ons blocades</caption>
<thead>
 
 
    <th>ID fitxer</th>
    <th>T&iacute;tol</th>
    <th>Autor</th>
    <th>Reproductor</th>
    <th>Desbloca-la</th>
</thead>
<tr tal:repeat="record blocades">
    <td id="cpm_idfitxer">
        <a href="http://beta.musicalliure.net/media/files/${record/user_name}/${record/upload_id}">${record/files/0/file_id}</a>
    </td>
 
    <td>
         <a href="http://www.google.com/search?hl=ca&q=%22${record/upload_name}%22">${record/upload_name}</a>
    </td>
 
    <td>        
        <a href="http://www.google.com/search?hl=ca&q=%22${record/user_real_name}%22">${record/user_real_name}</a>
    </td>
 
    <td>
        <object type="application/x-shockwave-flash" width="200" height="20" data="http://beta.musicalliure.net/cclib/xspf_player/xspf_player_slim.swf?autoload=0&song_url=http://beta.musicalliure.net/media/download/${record/user_name}/${record/files/0/file_id}/${record/files/0/file_name}">
        <param name="movie" value="http://beta.musicalliure.net/cclib/xspf_player_slim.swf?autoload=0&song_url=http://beta.musicalliure.net/media/download/${record/user_name}/${record/files/0/file_id}/${record/files/0/file_name}" />
        </object>
    </td>
 
    <td id="cpm_aprovala">
        <a href="http://beta.musicalliure.net/media/admin/ban/${record/upload_id}">Desbloca-la</a>
    </td>
 
</tr>
</table>
</div>

And here the cool and easy part:

<?php
    function cancons_pendents_de_moderacio() {
        //
        // retorna les cançons pendents de moderació
        //
 
        $c =& CCUploads::GetTable();
        $c->AddJoin( new CCFiles(), 'upload_id');
        $c->AddJoin( new CCUsers(), 'upload_user');    
 
        $c->SetOrder('upload_date','DESC');
 
        return $c->GetRecords('upload_published = 0 and upload_banned = 0');
 
    }
 
    function cancons_blocades() {
        //
        // Retorna les cançons blocades
        //
 
        $c =& CCUploads::GetTable();
        $c->AddJoin( new CCFiles(), 'upload_id');
        $c->AddJoin( new CCUsers(), 'upload_user');    
 
        $c->SetOrder('upload_date','DESC');
 
        return $c->GetRecords('upload_banned = 1');
    }
?>

Entra