Archive for the ‘Software’ Category

FAT32 with SD cards on GNU/Linux or GParted: FAT32 grayed out

dissabte, maig 2nd, 2009

If you are a GNU/Linux user, you may have forgotten that there is a lot of people behaving in a strange way, like using NTFS or FAT32. At least, I sometimes do. Today I got a pendrive already formatted (FAT32) and, when I plugged it in, I pretended to delete its contents. Debian told me «I can’t: it’s read only». It wasn’t read only, though. It had been  auto-mounted with standard methods. Since I wanted to delete all contents, I reckoned I could format it. Okay, it’s not one of the best practices because it’s a SD card and has a writing limit, but I just use it once a month.

debian:/home/edu# gparted

I umount /dev/sdf in order to format it, and… fat32 is grayed out. I can just use ext2, ext3, swap and reiserfs.

What nobody told me is that I need the dosfstools package:

debian:/home/edu# apt-get install dosfstools

And after that, everything worked fine. I now own a fat32 formatted 1Gb device.

PROLOG: introducció a la programació lògica – 2

dilluns, abril 13th, 2009

Avís: article orientat a estudiants d’Enginyeries en Informàtica de la FIBUPC. Basat en les explicacions a classe del professor Enric Rodríguez.

La programació lògica es cursa en les assignatures d’«introducció a la lògica» i a «lògica per a la informàtica». La utilitat directa per un fíber és: calcular respostes pel concurs «Cifras y letras» o trobar una manera de resoldre el problema de missioners i caníbals. També es fa servir per calcular horaris de l’ACB o els mateixos de la FIB.

Problema de concatenació

Inducció per concatenació:

concat([], L, L).
concat([X|Y1], Y2, [X|Y3]) :- concat(Y1, Y2, Y3).

Vegem que si L1, L2 són llistes i L3 és una variable, aleshores la consulta

edu@debian:~$ prolog
GNU Prolog 1.3.0
By Daniel Diaz
Copyright (C) 1999-2007 Daniel Diaz
| ?- concat(L1, L2, L3)

instancia (unifica) L3 amb la concatenació de L1 i L2.

Cas base

L1 és la llista buida []. Per la primera clàusula, tenim que L3 queda instanciada a L2, de manera que L3 s’instancia correctament.

Cas inductiu

Suposem que la llista L1 té almenys un element, és a dir, és de la forma [X | Y1]. Y1 amb longitud n+1. Aleshores, per hipòtesi d’inducció, la consulta

| ?- concat(Y1, L2, L3)

on Y3 és una variable, instancia Y3 a la concatenació de Y1 i Y2. Y1 té longitud n.
Per la segona clàusula, la consulta

| ?- concat([X|Y1], L2, L3).

instancia L3 a [X|Y3], que és la concatenació de X, Y1, Y2. Per tant, L3 queda instanciada correctament.

css: center content

dilluns, març 30th, 2009

When I began playing with CSS, centering a page was rather difficult. CSS allowed it, but try a search «center content» or «center css». It throws lots of results, and most of them, when I needed it, were not relevant. The trick is margin: 0 auto;

captura-la-serra.jpeg

Create a <div> where you’ll put all contents, with id=”content”, for example.

<html>
<body>
    <div id="content">
        <p>Today's a good day to code.</p>
    </div>
</body>
</html>

Now, in a style sheet create a rule:

#content {
    width: 1024px;
    margin: 0 auto 0 auto;
}

And enjoy your centered content :)

shell: some useful commands

dissabte, març 28th, 2009

The Linux shell offers lots of commands, but there are a few used every day. For a standard user, the shell isn’t really important. We can do (almost) whatever using GUIs, but there are some actions that are to be done with a shell. It’s powerful, faster, and easier. How do you put in a text file all permissions of all files in a given directory? How do you modify a line matching a pattern all system wide? We shall have a look at the frequently used commands:

more, less

You can use more for paging through text one screenful at a time. There is another command, less, that does the same but faster. more came first, but while it only used to allow moving forward through the text, the less command let the user go backwards. Nowadays, we can use both commands as synonyms.

$ ls -l /etc/ | more

$ ls -l /etc/ | less

$ less file.text

$ more file.text

Warning: type q to quit less or more.

cat

It’s kind of more. It outputs the contents of a file.

$ cat text.file

sort

Another filter that sorts lines of text files. The manual is quite large, so let’s see a few quick examples:

$ sort /etc/htpasswd

Shows on stdout (the screen, by default), the /etc/htpasswd  sorted alphabetically by lines.

$ sort -t: -k3 -n /etc/passwd

Performs a numeric sort  (-n) by the 3rd field (-k3). Two fields are separated by  ‘:’ (-t:).

$ ls -l /etc | sort -k5 -n -r | less

Orders the output of ls -l /etc by  the 5th field (the file’s size, as man ls says) descending (-r). We use the field separator by default (one or more white spaces).

cut

Selects parts of lines of the input file.

$ cut -d: -f3,5 /etc/passwd

Shows the 3rd and 5th field of all lines of /etc/passwd, having ‘:‘ as a field separator (-d:). Notice that with the sort command, we used -t to choose the separator.

$ ls -l /etc/passwd | cut -c2-10

Only outputs the file permissions, as they are on columns 2 to 10 in ls -l /etc/passwd.

head

Selects the first lines or characters in a file. We can use it after a pipe ( | ) or as a usual command:

$ cat /etc/passwd/ | head -2

Outputs the 2 first lines of /etc/passwd

$ head -2 /etc/passwd

idem :)

You have learnt the cut usage, haven’t you? Then mix your knowledge:

$ sort /etc/passwd | head -2 | cut -d: -f1

Shows the 2 first user id of the system, having the file sorted alphabetically.

tail

Opposite of head. Outputs the last lines or characters of files.

$ ls -l /etc | tail -2

shows the two last lines of the ls -l /etc output. Is it useful? Not really, yet. Use sort:

$ ls -l /etc  | sort -k5 -n | tail -2

Shows the 2 biggest files in /etc

tr

This is one of the most useful commands. It just translates characters. e.g: you want to replace all ‘a’ chars in a file for ‘z’, or e.g: you wish to delete all ‘b’ in a file (replace ‘b’ with ‘BLANKSPACE’):

$ tr aeiou AEIOU < /etc/passwd

the < character means: «redirect /etc/passwd to the standard input of the tr command». This line replaces all lower-case vowels to upper-case. a->A, e->E and so on. The first letter in «aeiou» corresponds to the first letter in «AEIOU». Thus, if you want to replace a,e,i,o,u with ‘V’, do:

$ tr aeiou VVVVV < dummyfile

or

$ tr aeiou V < dummyfile

This line doesn’t modify the /etc/passwd or the dummyfile. If you wish so, you have to redirect the output to the file you want to save the changes in, like that:

$ tr aeiou VVVVV < dummyfile > dummyout.

DON’T DO IT WITH /etc/passwd

wc

As simple as «word-count», but powerful: it can count lines, words and characters of the input. Example:

$ wc -c /etc/passwd

How many characters does /etc/passwd contain?

$ ls -l /etc | wc -l

how many files and directories are in /etc ?

uniq

reports or ommits repeated lines in a list. «compacts» them. e.g: We have a file containing:

edu@debian:~$ cat dummyfile
Hi,
Hi,
This is a script of Family Guy.
Have a good day,
Have a good day,
Have a good day,

Edu

Eduard Gamonal

edu@debian:~$

Its got repeated lines. I like counting things and I wish to know how many repeated lines are there.

edu@debian:~$ cat dummyfile | uniq -c
2 Hi,
1 This is a script of Family Guy.
3 Have a good day,
1
1 Edu
1
1 Eduard Gamonal
1
edu@debian:~$

Funny, but not really useful. What if instead of a dummy file we had a list of processes running on our system?

$ ps -e | cut -c25- | sort | uniq -c

For each running command , outputs the processes that are executing it. ps -e shows the command name from the 25th column on (notice the last hyphen in -c25- ).

It may seem complex sometimes, and the user my spend half an our to type a correct command, but after that we have the output we wanted and we can use it, since it’s text in a shell, not in a window.

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


Entra