tag:blogger.com,1999:blog-89912325949864384692024-02-21T16:29:31.985+01:00Becoming a Nerd in Polynomial TimeThen there is the "1 bit" microprocessor that has two instructions: "NOP" and "HALT"Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.comBlogger55125tag:blogger.com,1999:blog-8991232594986438469.post-81471768276187487892013-06-20T12:13:00.001+02:002013-06-20T12:13:43.234+02:00Good programmingThis is going to be a great software!<br />
<br />
<br /></div>
<pre class="brush:cpp">#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("Segmentation Fault\n");
exit(EXIT_FAILURE);
}</pre>
</div>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0Roma, Italia41.8929163 12.48251989999994341.5147698 11.837072899999942 42.2710628 13.127966899999944tag:blogger.com,1999:blog-8991232594986438469.post-7379515773969145202012-10-19T10:28:00.003+02:002012-10-19T10:29:05.081+02:00shell clipboardEver wanted to cut something from the shell?<br />
Do you need to paste some information stored in a file into your web browser, but you are too lazy to fire up your text editor, select, and hit ctrl+c?<br />
Are you a shell enthusiast?<br />
<br />
Than <span style="font-family: Courier New, Courier, monospace;"><a href="http://linux.die.net/man/1/xclip" target="_blank">xclip(1)</a></span> is good for you. It's a CLI to X clipboard, which lets you store into the clipboard buffer what you type on <span style="font-family: Courier New, Courier, monospace;">stdin</span>, or from a file.<br />
<br />
But to simplify more the task of cutting and pasting, you can create (if you are using, for example, bash) a simple alias in your .bashrc file like this one:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">alias clipboard="xclip -i -selection clipboard"</span><br />
<br />
Then, you can simply copy a file in the clipboard like:<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">$ cat file | clipboard</span><br />
<br />
or directly write in it:<br />
<br />
<br />
<span style="font-family: Courier New, Courier, monospace;">$ clipboard </span><br />
<span style="font-family: Courier New, Courier, monospace;">hi, how are you?</span><br />
<span style="font-family: Courier New, Courier, monospace;">CTRL+D</span><br />
<br />
And your productivity will be maximized for sure!!!<br />
<div>
<br /></div>
<br />
<br />Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com1tag:blogger.com,1999:blog-8991232594986438469.post-15652443509609081762012-09-06T16:45:00.002+02:002012-09-08T18:12:47.175+02:00Bash Shell CalculatorWorking on the Linux shell has always missed something, in my experience: an easy-to-use calculator.<br />
<br />
Yes, there is the almighty <span style="font-family: 'Courier New', Courier, monospace;">bc</span>, but it is everything but immediate to use. So here I'm just sharing an easy to implement wrapper to <span style="font-family: 'Courier New', Courier, monospace;">bc</span>, which allows to easily use your shell as a calculator.<br />
<br />
Simply drop these lines into a file called 'calc':<br />
<br />
<br />
<pre class="brush:bash">#!/bin/bash
echo "scale=2; $1" | bc; exit
</pre>
<br />
Then simply make it executable and copy it into <span style="font-family: 'Courier New', Courier, monospace;">/usr/bin/</span>:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">$ chmod 755 calc<br /># mv calc /usr/bin</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: inherit;">Then, you can start doing your math in your shell, simply like:</span><br />
<span style="font-family: inherit;"><br /></span>
<span style="font-family: 'Courier New', Courier, monospace;">$calc 3/2</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">1.50</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: inherit;">Consider that, if you want to use more complex operations, you have to escape any special character, like:</span><br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">$ calc \(3+2\)/4</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">1.25</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span>
<span style="font-family: inherit;">And simply change the number after "</span><span style="font-family: 'Courier New', Courier, monospace;">scale=</span><span style="font-family: inherit;">" to add more precision to the results!</span><br />
<span style="font-family: inherit;"><br /></span>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com1tag:blogger.com,1999:blog-8991232594986438469.post-15927202134840790942012-07-08T16:56:00.000+02:002012-07-08T18:04:56.954+02:00Rotate it!<style>
div#rotate-this {
display:block;
position:absolute;
right:420px; top:0px;
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
}
</style>
<!--[if IE]>
<style>
div#rotate-this {
filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=1);
right:-15px; top:5px;
}
</style>
<![endif]-->
<div class="latex">
$
\left[
\begin{array}{c}
\cos 90 \quad \sin 90 \\
-\sin 90 \quad \cos 90
\end{array}
\right]
\left[
\begin{array}{c}
a_1 \\
a_2
\end{array}
\right]
=
$
</div><div class="latex" id="rotate-this">
$
\left[
\begin{array}{c}
a_1 \\
a_2
\end{array}
\right]
$
</div>
(And yes, this was just to experiment with CSS rotations!)Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0tag:blogger.com,1999:blog-8991232594986438469.post-7255272503576753182012-06-18T17:45:00.002+02:002012-12-04T17:47:23.252+01:00Multilanguage Posts in BloggerA common use-case is the one where we want to broadcast multiple language content on a blog.<br />
<br />
Blogger itself does not provide such a facility, but I'm here presenting a javascript hack which allows posts to be written in multiple languages, and have flags on top of the page to switch among them.<br />
<br />
First of all, you have to write within a single post a different version for every language which you want to support. To do this, you must first set the correct environment. When editing a post, you should switch to HTML view first:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7Aclhxpw02ef4SVDyBTyVhE0ITtDmomTw1hERVVHP4hr5DehBPPodA8CA9Ot0r_PrtDD96STN8iibweqA_6Sdn8VMFsvmpvSq_lUX_AZwk-ICwzw-U8R7wUOYezb3Ix7dqNcUzzI3T4Ct/s1600/multilang-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7Aclhxpw02ef4SVDyBTyVhE0ITtDmomTw1hERVVHP4hr5DehBPPodA8CA9Ot0r_PrtDD96STN8iibweqA_6Sdn8VMFsvmpvSq_lUX_AZwk-ICwzw-U8R7wUOYezb3Ix7dqNcUzzI3T4Ct/s1600/multilang-1.png" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
Then, suppose you are writing content in Italian and English, you should add this skeleton:<br />
<br />
<pre class="brush:javascript"><div class="lang:italian">
Questo è del contenuto in Italiano
</div>
<div class="lang:english">
This is English content
</div></pre>
<div>
</div>
<div class="lang:english">
Then, switching back to Compose mode will show you the two sentences. Replace them with the actual content you want to display in your blog post.<br />
<br />
Then, go to the Layout Editor of your blog and add a new HTML/JavaScript block on top of your blog posts:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhidYaZvXzFtjAt1WoJRvsfr-mHSYGfk_ZexZbAwZJ_XlCPdreX0rsFgwEJho_348GDPMBsNufDKWcDECMynMRHDrYpq3v9SOaCAEgcKFXBBZr4dRVXk2Dg3SsHSN4xMqbqMBJtrFs660gY/s1600/multilang-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="313" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhidYaZvXzFtjAt1WoJRvsfr-mHSYGfk_ZexZbAwZJ_XlCPdreX0rsFgwEJho_348GDPMBsNufDKWcDECMynMRHDrYpq3v9SOaCAEgcKFXBBZr4dRVXk2Dg3SsHSN4xMqbqMBJtrFs660gY/s400/multilang-2.png" width="400" /></a></div>
<br />
<br />
Enter there the following code:<br />
<br /></div>
<pre class="brush:javascript"><script language="Javascript">
function getElementsByClass(searchClass,node,tag) {
var classElements = new Array();
if ( node == null )
node = document;
if ( tag == null )
tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
for (i = 0, j = 0; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i];
j++;
}
}
return classElements;
}
function show_en() {
var it = getElementsByClass('lang:italian', null, null);
var en = getElementsByClass('lang:english', null, null);
for(i = 0; i < it.length; i++) {
it[i].style.display = 'none';
}
for(i = 0; i < en.length; i++) {
en[i].style.display = 'block';
}
}
function show_it() {
var it = getElementsByClass('lang:italian', null, null);
var en = getElementsByClass('lang:english', null, null);
for(i = 0; i < it.length; i++) {
it[i].style.display = 'block';
}
for(i = 0; i < en.length; i++) {
en[i].style.display = 'none';
}
}
</script>
<a href="#" onclick="show_en();"><img src="PATH-TO-EN-FLAG" /></a>
<a href="#" onclick="show_it();"><img src="PATH-TO-IT-FLAG" /></a>
</pre>
<br />
This adds at the top of you posts two flag images, which can be clicked, showing either italian or english content. Now, the last bit of editing entails activating either language as the default one (otherwise, you will see both languages, until one of the two flags is clicked).<br />
<br />
To do so, open you Blog's model editor and click "Edit HTML".<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisOEZM1BmxztXuEvTtpxqFTDNQUlvgG7ATY5YQ1rDUkVUmoW__zD8MVzMNptp-TOPnKtf-X8t3qvuEAG6snhgODpkPBh7A4A__yl3rSGbMQA9E6R-jTCJfnpV9mwFCA7WUNm5RopgWs-st/s1600/multilang-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="245" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEisOEZM1BmxztXuEvTtpxqFTDNQUlvgG7ATY5YQ1rDUkVUmoW__zD8MVzMNptp-TOPnKtf-X8t3qvuEAG6snhgODpkPBh7A4A__yl3rSGbMQA9E6R-jTCJfnpV9mwFCA7WUNm5RopgWs-st/s400/multilang-3.png" width="400" /></a></div>
<br />
A popup telling you about the dangers of this operation will show up. Tell blogger to take it easy, and start editing your model. You should find the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><body></span> tag, and add the following attribute in it:<br />
<pre class="brush:javascript">onload='show_en();'
</pre>
<br />
Selecting which is the default language which you want to display.<br />
<br />
For a <a href="http://live%20preview/" target="_blank">live preview</a> of how this works, point your browser to <a href="http://cranentertainment.blogspot.it/" target="_blank">CranEntertainment's blog</a>!Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com89Via Nicola Salvi, 00184 Roma, Italia41.8905198 12.494248641.5122753 11.8625346 42.2687643 13.125962600000001tag:blogger.com,1999:blog-8991232594986438469.post-71314087692574550412012-06-17T20:18:00.000+02:002012-06-17T20:31:47.521+02:00Relative Date in LaTeXIt's usual, when writing documents, to use sentences like "I have been doing something since MM/YYYY". This is no problem.<br />
<br />
If, on the other hand, you want to write a sentence like "I have been doing something for XX years and YY months", every time you update your document you have to remember to change that sentence.<br />
<br />
When writing documents in LaTeX, you can work this problem out using a relatively simple command:<br />
<pre class="brush:latex">\usepackage{datenumber}
\newcounter{dateone}
\newcounter{datetwo}
\newcommand{\difftoday}[3]{%
\setmydatenumber{dateone}{\the\year}{\the\month}{\the\day}%
\setmydatenumber{datetwo}{#1}{#2}{#3}%
\addtocounter{datetwo}{-\thedateone}%
\the\numexpr-\thedatetwo/365\relax\space years and
\the\numexpr(-\thedatetwo - (-\thedatetwo/365)*365)/30\relax\space months
}
</pre>
<br />
The package <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">datenumber</span> allows to handle dates as timestamps, therefore we can use counters to perform operations on them (namely, <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">dateone</span> and <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">datetwo</span>). We set <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">dateone</span> to the current date, and <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">datetwo</span> to the user-specified date.<br />
<br />
Then, in our document we can use:<br />
<pre class="brush:latex">\difftoday{2002}{01}{01}
</pre>
<br />
And, say, if we are on March 3rd, 2012, it will render as "10 years and 2 months".Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0Roma, Italia41.8905198 12.494248641.5122753 11.8625346 42.2687643 13.125962600000001tag:blogger.com,1999:blog-8991232594986438469.post-259074277318690022012-06-17T15:45:00.000+02:002012-06-17T20:31:47.438+02:00Multilanguage Documents with TeXToday I have been working on a LaTeX document which was supposed to produce a document in two versions, one in Italian, another in English. It was a technical report, so a lot of stuff, but not so much text.<br />
<br />
The classic way to approach this is to have the document written in one language, and then translate it into the second. This can be fair, until you have to apply changes. Editing two documents in a row can be too much effort-consuming.<br />
<br />
<div class="latex">
Luckily enough, $\LaTeX$ is a programming language, before an office automation tool. So we can use conditional variables to fulfill this task. So, the skeleton of my source looks like this:</div>
<pre class="brush:latex">\documentclass[10pt]{article}
\newif\ifit
\newif\ifen
\newcommand{\langit}[1]{\ifit#1\fi}
\newcommand{\langen}[1]{\ifen#1\fi}
\entrue
%\ittrue
\ifen\usepackage[english]{babel}\fi
\ifit\usepackage[italian]{babel}\fi
\begin{document}
\langen{This is English text}
\langit{Questo è del testo in italiano}
\end{document}
</pre>
<br />
Basically, I declare two conditional variables, \ifit and \ifen which select which language code must be generated. By uncommenting either \entrue or \ittrue, the source will produce the output in English or in Italian.<br />
<br />
To ease the task of writing the TeX source, two new commands are declared: \langit and \langen which accept one parameter (i.e., the text in the corresponding language) and output it only if the corresponding conditional variable is set.<br />
<br />
Additionally, depending on which conditional variable is set, the babel package is loaded with the corresponding language.<br />
<br />
This allows to work on one single TeX source (which decreases the maintainability effort), but allows to produce documents in multiple languages. Adding new languages is just a matter of creating new variables and commands.<br />
<br />
Another interesting this, which does not appear in this example, is the charset. Some languages have different charsets, so it would be interesting to set it accordingly. For the italian case, it would entail adding before the document's begin, the following code:
<br />
<pre class="brush:latex">\ifit\usepackage[utf8]{inputenx}\fi
</pre>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0tag:blogger.com,1999:blog-8991232594986438469.post-79281542037567823592012-06-08T17:05:00.000+02:002012-06-17T20:36:32.460+02:00Transit of VenusMy small contribution to the 2012 <a href="http://en.wikipedia.org/wiki/Transit_of_Venus" target="_blank">Transit of Venus</a>.<br />
<br />
<div style="text-align: center;">
<embed flashvars="host=picasaweb.google.com&hl=it&feat=flashalbum&RGB=0x000000&feed=https%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2F101921375630347378894%2Falbumid%2F5751680638479496337%3Falt%3Drss%26kind%3Dphoto%26hl%3Dit" height="192" pluginspage="http://www.macromedia.com/go/getflashplayer" src="https://picasaweb.google.com/s/c/bin/slideshow.swf" type="application/x-shockwave-flash" width="288"></embed></div>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0tag:blogger.com,1999:blog-8991232594986438469.post-5284312982081098272012-06-07T18:58:00.002+02:002012-06-17T20:34:17.894+02:00Write your own Kernel: BootLoader stubSince I was young, one of my dreams was to write my own operating system.<br />
It was still the DOS era, and as a young boy I started studying lot of tech stuff trying to figure out what was really happening inside my computer.<br />
<br />
Actually, at the time, it was too much 'tech' stuff for me, I didn't have the necessary knowledge to understand the subtle details behind a low-level programming approach.<br />
<br />
Then I took my Computer Engineering degree, the technical details are no longer obscure, but since then, the old dream remained just... an old dream!<br />
<br />
Yesterday, while messing up with a broken hard disk trying to recover some data, a funny idea came up into my mind, and I launched:<br />
<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">dd if=/dev/sda of=MBR count=1 bs=512 > MBR</span><br />
<br />
This dumped into a file the content of that disk's <a href="http://en.wikipedia.org/wiki/Master_boot_record" target="_blank">Master Boot Record</a> (MBR). Of course, I couldn''t resist this, and I disassembled it:<br />
<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">objdump -D -b binary -mi386 -Maddr16,data16 MBR</span><br />
<div>
<br /></div>
<div>
While staring at that code, my old dream came back to me, and so I started messing around a bit. The outcome, was a small bootloader stub, which is actually working, and which I am here describing... In the future, I will surely spend some time extending this, but this will remain just a project-for-fun!</div>
<div>
And yes, this is somewhat reinventing the wheel, but for a low-level programmer, this is really funny!</div>
<div>
<br /></div>
<div>
So, the work setting is this:</div>
<div>
<ul>
<li><a href="http://it.wikipedia.org/wiki/Intel_80386" target="_blank">i386</a>/<a href="http://en.wikipedia.org/wiki/X86-64" target="_blank">x86_64</a> target machines</li>
<li><a href="http://en.wikipedia.org/wiki/C_(programming_language)" target="_blank">C</a> and <a href="http://en.wikipedia.org/wiki/Assembly_language" target="_blank">Assembly</a> languages</li>
<li>standard <a href="http://en.wikipedia.org/wiki/GNU_Compiler_Collection" target="_blank">GNU compilation toolchain</a> (gcc, gas, ld, make, ...)</li>
<li><a href="http://it.wikipedia.org/wiki/VirtualBox" target="_blank">VirtualBox</a> for early testing, then I will switch to a legacy old machine to real hardware test...</li>
</ul>
As for VirtualBox configuration, I have set a 40MiB virtual <a href="http://en.wikipedia.org/wiki/Parallel_ATA" target="_blank">IDE</a> Hard Disk, <a href="http://en.wikipedia.org/wiki/File_Allocation_Table#FAT32" target="_blank">FAT32</a> partitioned, for future development (my legacy machine will mount a similar one), and a floppy device loading a binary raw image (the actual bootloader + early kernel).</div>
<div>
<br /></div>
<div>
So, let's now start analyzing the <a href="http://en.wikipedia.org/wiki/Booting#Boot_loader" target="_blank">BootLoader</a>'s early stub. This is a 'stage 1' bootloader which simply prints a "Hello World" message, waits for a keystroke and then reboots the system. No actual loading of any stage 2 loader, nor mode change.</div>
<div>
<br /></div>
<div>
Given the hardware architecture we are targeting, we have some constraints about the bootloader to keep in mind for writing it successfully:</div>
<div>
<ul>
<li>The bootloader is loaded by the <a href="http://en.wikipedia.org/wiki/BIOS" target="_blank">BIOS</a> (which is loaded into RAM at startup as well), given some preconditions</li>
<li>Both code and data must be placed within one sector of the booting disk (the MBR), which is 512B</li>
<li>The last two bytes of this sector must have the value <span style="font-family: 'Courier New', Courier, monospace;">0xaa55</span>, otherwise the sector will not be considered as bootable</li>
<li>The BIOS will load the bootloader at address <span style="font-family: 'Courier New', Courier, monospace;">0x0000:0x7c00</span>, so the code must be relocated to that address, otherwise it won't work.</li>
<li>The %dl register will contain the disk number, useful for reading additional data from it. Nevertheless, I am ignoring this up to this up to this stage.</li>
<li>Of course, we run in real mode, so we have 16-bit code and we can do almost everything! :)</li>
</ul>
So, our MBR will contain both code and data. in the future, it will contain some partition table as well, but since it is stored into a floppy disk, we must provide a Disk Description Table (DDT) as well, to make it a valid floppy. Additionally, the first byte of the MBR will be part of the first instruction which will get executed, so we have to properly merge these things. The beginning of our <span style="font-family: 'Courier New', Courier, monospace;">boot1.S</span> code is therefore this:</div>
<br />
<pre class="brush:asm"> .code16
.text
.globl _start; _start:
jmp stage1_start
OEMLabel: .string "BOOT"
BytesPerSector: .short 512
SectorsPerCluster: .byte 1
ReservedForBoot: .short 1
NumberOfFats: .byte 2
RootDirEntries: .short 224
LogicalSectors: .short 2880
MediumByte: .byte 0x0F0
SectorsPerFat: .short 9
SectorsPerTrack: .short 18
Sides: .short 2
HiddenSectors: .int 0
LargeSectors: .int 0
DriveNo: .short 0
Signature: .byte 41 #41 = floppy
VolumeID: .int 0x00000000 # any value
VolumeLabel: .string "myOS "
FileSystem: .string "FAT12 "
stage1_start:
</pre>
<br />
The <span style="font-family: 'Courier New', Courier, monospace;">.code16</span> and <span style="font-family: 'Courier New', Courier, monospace;">.text</span> are things to make GNU assembler (gas) produce valid code. In particular, <span style="font-family: 'Courier New', Courier, monospace;">.code16</span> tells the assembler to produce 16-bits code (the default would be 32-bits, of course!) and <span style="font-family: 'Courier New', Courier, monospace;">.text </span>ensures that we have everything into one single section (we don't actually mind which one, as they will be stripped, later on). <span style="font-family: 'Courier New', Courier, monospace;">_start</span> is an actual symbol which describes the entry point for the executable, but we will be using this in a different way. The first instruction, <span style="font-family: 'Courier New', Courier, monospace;">jmp</span>, tells the machine to skip "executing" the DDT, so we can have a correctly executing program, keeping the correct format for a floppy (of course, this bites some bytes out of the small 512B available space).<br />
<br />
The code now must setup the runtime stack, since it will allow using the "<span style="font-family: 'Courier New', Courier, monospace;">call</span>" instruction for calling subroutines. This looks like this:<br />
<br />
<pre class="brush:asm"> cli
movw $0x07C0, %ax
addw $544, %ax # 8K buffer
mov %ax, %ss
movw $4096, %sp
sti
</pre>
<br />
This creates a 4KiB stack space above the bootloader, which is (hardcoded) 8KiB large (544 paragraphs). We use the <span style="font-family: 'Courier New', Courier, monospace;">cli</span> and <span style="font-family: 'Courier New', Courier, monospace;">sti</span> couple, in order to disable and then re-enable interrupts, since it is not safe here to perform any interrupt operation, before having the stack correctly set up.<br />
<br />
Then, we display our dummy message, "Hello World", and then reboot.<br />
<br />
<pre class="brush:asm"> cld
movw $hello_s, %si
call print_string
jmp reboot
hlt
</pre>
<br />
<span style="font-family: 'Courier New', Courier, monospace;">cld</span> clears the direction flag, so that the internal implementation of <span style="font-family: 'Courier New', Courier, monospace;">print_string</span> will read the string placed into <span style="font-family: 'Courier New', Courier, monospace;">%si</span> from the beginning to the end. The final <span style="font-family: 'Courier New', Courier, monospace;">hlt</span> is actually never executed, but placing it there is a good practice, nevertheless. So, let's see how do <span style="font-family: 'Courier New', Courier, monospace;">print_string</span> function and <span style="font-family: 'Courier New', Courier, monospace;">reboot</span> subroutine work.<br />
<br />
<pre class="brush:asm">1:
movw $0x0001, %bx
movb $0x0e, %ah
int $0x10
print_string:
lodsb
cmpb $0, %al
jne 1b
ret
</pre>
<br />
This routine is actually nicely optimized in space (remember, a bootloader suffers from space!). The funny part is that its entry point is in the middle of its code!<br />
So, when we call it, a <span style="font-family: 'Courier New', Courier, monospace;">lodsb</span> instruction gets executed, which loads one byte from <span style="font-family: 'Courier New', Courier, monospace;">%si</span> into <span style="font-family: 'Courier New', Courier, monospace;">%al</span> and increments <span style="font-family: 'Courier New', Courier, monospace;">%si</span> by one: we read one character of the string from memory!<br />
<span style="font-family: 'Courier New', Courier, monospace;">cmpb</span> checks whether the byte just read is 0, i.e., if it is a NUL terminating character, the end of the string. If not, it goes executing from the <span style="font-family: 'Courier New', Courier, monospace;">1:</span> label.<br />
There, we find the <span style="font-family: 'Courier New', Courier, monospace;"><a href="http://en.wikipedia.org/wiki/INT_10" target="_blank">int $0x10</a></span> instruction, which generates an interrupt and searches into the <a href="http://en.wikipedia.org/wiki/Interrupt_descriptor_table" target="_blank">Interrupt Vector Table</a> the entry <span style="font-family: 'Courier New', Courier, monospace;">0x10</span>, which is associated with the BIOS <a href="http://en.wikipedia.org/wiki/Video_BIOS" target="_blank">teletype function family</a>. The value <span style="font-family: 'Courier New', Courier, monospace;">0x0e</span> stored into <span style="font-family: 'Courier New', Courier, monospace;">%ah</span> tells the BIOS to activate the screen printing function, which displays on screen exactly the caracter stored into <span style="font-family: 'Courier New', Courier, monospace;">%al</span>, using the old-fashioned <a href="http://en.wikipedia.org/wiki/Code_page_437" target="_blank">Codepage Font</a> (which is usually hard-coded within the BIOS itself).<br />
This process goes on until a <span style="font-family: 'Courier New', Courier, monospace;">'\0'</span> is found in the string, then a <span style="font-family: 'Courier New', Courier, monospace;">ret</span> is executed.<br />
<br />
Rebooting the system is far more easy:<br />
<pre class="brush:asm">reboot:
movw $reboot_s, %si
call print_string
movw $0,%ax
int $0x16 # Wait for keystroke
movw $0,%ax
int $0x19 # Reboot the system
</pre>
<br />
A nice string asking the user to press any key is shown, using the same function as before. Then, a keystroke is waited for, using the BIOS <a href="http://www.ctyme.com/intr/int-16.htm" style="font-family: 'Courier New', Courier, monospace;" target="_blank">int $0x16</a><span style="font-family: inherit;"> which, having </span><span style="font-family: 'Courier New', Courier, monospace;">%ax == 0</span><span style="font-family: inherit;">, activates the "<a href="http://www.ctyme.com/intr/rb-1754.htm" target="_blank">get keystroke</a>" BIOS function. The BIOS does not return from the interrupt routine until a key is pressed, and then </span><span style="font-family: 'Courier New', Courier, monospace;"><a href="http://www.ctyme.com/intr/int-19.htm" target="_blank">int $0x19</a></span><span style="font-family: inherit;"> is executed, i.e. the "bootstrap loader" interrupt.</span><br />
<span style="font-family: inherit;"><br /></span><br />
The end of <span style="font-family: 'Courier New', Courier, monospace;">stage1.S</span> goes like this:<br />
<br />
<pre class="brush:asm"> hello_s: .string "Hello World!\n\r"
reboot_s: .string "Press any key to reboot..."
. = _start + 0x0200 - 2
.short 0x0AA55 #Boot Sector signature
</pre>
<br />
The two strings which we want to display are declared, so that we can load their addresses for the printing function.<br />
Then, the line:<br />
<span style="font-family: 'Courier New', Courier, monospace;">. = _start + 0x0200 - 2</span><br />
tells <span style="font-family: 'Courier New', Courier, monospace;">gas</span>, the GNU Assembler, to move the location of the code being generated (the <span style="font-family: 'Courier New', Courier, monospace;">'.'</span> variable) 512B after <span style="font-family: 'Courier New', Courier, monospace;">_start</span>, and then 2B backwards, which is 2 bytes before the end of the MBR. At this point, we make gas emit the <span style="font-family: 'Courier New', Courier, monospace;">0xAA55</span> signature, which tells the BIOS that the current disk is bootable, and we are done: this is our bootloader stub!<br />
<br />
Now, the last part, is to actually compile this code. The GNU Compiling Toolchain is targeted at 32/64-bits executables, so by defaults it usually produces ELF Programs. Which we do not want here, as we just need a stream of bytes representing the instructions to be executed.<br />
<br />
gas alone cannot do this: it creates headers and everything and cannot be disabled. But we can rely on ld, the GNU linker, asking it to produce a raw binary. So, the two steps are:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">as boot.S -c -o boot.o</span><br />
<br />
which creates an ELF executable, containing our code. Then:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">ld --oformat binary --Ttext 0x7C00 -o boot.bin boot.o</span><br />
<br />
which, with some magic, strips every header (<span style="font-family: 'Courier New', Courier, monospace;">--oformat binary</span>) and relocates the code starting from the address <span style="font-family: 'Courier New', Courier, monospace;">0x7c00</span> (<span style="font-family: 'Courier New', Courier, monospace;">--Ttext 0x7C00</span>) for the text section, which (considering our source) contains our whole bootloader, whose first instruction jumps to the actual initialization code.<br />
<br />
Making VirtualBox launch our <span style="font-family: 'Courier New', Courier, monospace;">boot.bin</span> image, this is the actual outcome:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaPZC3oeuQLG1glaHf3CzZTkgrCb3KZ3qJHIkOkhby47UbwMV2e91FRaZpLJIZBJC1dD6XyFC2I8ScexLG1JtFlIlHlSoS8YFd-PMnUbgJG93JqiRnCJVNSRb0ImkwrFz_vQX3_poNjnlT/s1600/Schermata+del+2012-06-07+18:53:28.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="310" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaPZC3oeuQLG1glaHf3CzZTkgrCb3KZ3qJHIkOkhby47UbwMV2e91FRaZpLJIZBJC1dD6XyFC2I8ScexLG1JtFlIlHlSoS8YFd-PMnUbgJG93JqiRnCJVNSRb0ImkwrFz_vQX3_poNjnlT/s400/Schermata+del+2012-06-07+18:53:28.png" width="400" /></a></div>
<br />
<br />
So, now, the next step is to write a second stage bootloader, and make the first stage one be able to load it and transfer control to it!Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com3tag:blogger.com,1999:blog-8991232594986438469.post-79243235385444197122012-06-06T14:34:00.000+02:002012-06-17T20:31:47.531+02:00diff e patch in dieci minutiPrima situazione: stai cercando di compilare un pacchetto dai sorgenti e scopri che qualcuno ha già fatto il lavoro per te, modificandolo un po' per farlo compilare sul tuo sistema. Il suo lavoro è disponibile come "<i>patch</i>", ma non sei sicuro di come si fa ad utilizzarlo. La risposta è che puoi applicare la patch ai sorgenti originali con un comando chiamato, appropriatamente, patch.<br />
<br />
Seconda situazione: hai scaricato i sorgenti di un pacchetto open source e dopo un'oretta di piccoli cambiamenti, riesci a compilarlo sul tuo sistema. Vorresti rendere il tuo lavoro disponibile agli altri programmatori, oppure agli autori del pacchetto, senza dover ridistribuire tutto quanto il pacchetto modificato. Ti trovi quindi in una situazione in cui devi creare da te una patch, e lo strumento necessario è diff.<br />
<br />
Questa è una breve guida a diff e patch, che ti aiuterà in queste situazioni descrivendo questi strumenti e come vengono utilizzati nella maniera più comune. Ti dirà abbastanza per cominciare ad utilizzarli subito. Dopo, potrai imparare da te i vari comandi aggiuntivi per il tuo piacere personale, utilizzando le pagine del manuale.<br />
<br />
<h3>
Applicare una patch con patch</h3>
Per applicare una patch ad un singolo file, spostati nella cartella dove è situato il file ed invoca patch:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">patch < foo.patch</span><br />
<br />
Queste istruzioni assumono che la patch sia distribuita in un formato unificato, che identifica il file al quale si deve applicare la patch. Se non è questo il caso, si può specificare il file da riga di comando:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">patch foo.txt < bar.patch</span><br />
<br />
Applicare delle patch ad intere cartelle (forse il caso più comune) è simile, ma si deve fare attenzione a specificare un "<i>livello p</i>". Questo vuol dire che, all'interno dei file di patch, i file cui applicare la patch sono identificati da percorsi che possono essere diversi ora che i file sono situati sul tuo computer, piuttosto che su quello in cui la patch è stata creata. Il livello <i>p</i> dice a patch di ignorare porzioni del percorso ai file, così da poterli identificare in maniera corretta. Nella maggior parte dei casi un livello <i>p</i> corrispondente a uno funziona, quindi si può usare:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">patch -p1 < baz.patch</span><br />
<br />
Ti dovresti spostare nella cartella principale dei sorgenti prima di lanciare questo comando. Se il livello uno non identifica correttamente nessun file cui applicare la patch, verifica il contenuto del file di patch per controllare i nomi dei file. Se trovi un nome del tipo:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">/users/stephen/package/src/net/http.c</span><br />
<br />
e stai lavorando nella cartella che contiene <span style="font-family: 'Courier New', Courier, monospace;">net/http.c</span>, usa:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">patch -p5 < baz.patch</span><br />
<br />
In generale, aggiungi uno per ciascun separatore di cartella (la barra '/') che vuoi rimuovere dall'inizio del percorso, fino a che quello che resta è un percorso che esiste nella tua cartella di lavoro. Il valore che raggiungi, è il corrello livello <i>p</i>.<br />
<br />
Per rimuovere una patch, utilizza il flag <span style="font-family: 'Courier New', Courier, monospace;">-R</span>, ad esempio:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">patch -p5 -R < baz.patch</span><br />
<br />
<h3>
Creare delle patch con diff</h3>
<div>
Utilizzare diff è molto semplice, sia che si stia lavorando con singoli file, sia che si stia lavorando su intere cartelle. Per creare una patch per un solo file, usa la forma:</div>
<div>
<br /></div>
<div>
<span style="font-family: 'Courier New', Courier, monospace;">diff -u original.c new.c > original.patch</span></div>
<div>
<br /></div>
Per creare una patch per un intero albero di cartelle, fanne una copia:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">cp -R original new</span><br />
<br />
Applica tutte le modifiche che intendi fare nella cartella <span style="font-family: 'Courier New', Courier, monospace;">new/</span>. Dopo crea un file di patch con il seguente comando:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">diff -rupN original/ new/ > original.patch</span><br />
<br />
Questo è tutto quello che serve per incominciare ad usare diff e patch. Per altre informazioni, puoi sempre usare:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">man diff</span><br />
<span style="font-family: 'Courier New', Courier, monospace;">man patch</span><br />
<span style="font-family: 'Courier New', Courier, monospace;"><br /></span><br />
<div style="text-align: right;">
<span style="font-family: inherit; font-size: x-small;"><i>Freely translated from <a href="http://jungels.net/articles/diff-patch-ten-minutes.html">this original post</a>, for my own convenience.</i></span></div>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com6tag:blogger.com,1999:blog-8991232594986438469.post-65831062573969282912012-05-11T01:28:00.001+02:002012-06-17T20:31:47.502+02:00Record audio outputSo, here's the story. We live in a web-radio era / audio-streaming world.<br />
The old-days audiotape is no longer helpful in recording sounds around us.<br />
<br />
Thus, after some headache, this is my modern "Linux audiotape", which I use to record.<br />
<br />
Basically, it relies on pulseaudio (I'm running alsa with pulseaudio on my arch distro).<br />
In particular, this script queries pulseaudio to know which is the first audio sink installed in the system (that is, the first audio source that is currently being directed to the output soundcard) and creates a dummy sink which is used to take the output and redirect it into a file.<br />
<br />
Then, since we do not want to fill up our disk with raw pcm directed to the speakers, the signal is pipe'd into an ogg encoder, which silently compresses our data and stores it into disk.<br />
<br />
<pre class="brush:bash">#!/bin/bash
sinksIndex=`echo list-sink-inputs | pacmd | grep index | head -1 | sed 's/^.*index:\s\([0-9]\+\).*$/\1 /'` # Get wanted index
echo "Recording to audioRecord.ogg... CTRL+C to stop."
pactl load-module module-null-sink sink_name=audioRecord
pactl move-sink-input $sinksIndex audioRecord
parec -d audioRecord.monitor | oggenc -b 192 -o audioRecord.ogg --raw -
</pre>
<br />
The only important thing to consider, is that to record exactly what we mean to, we must stop any audio stream in the system, start the one which we want to grab, and then launch this script.<br />
<br />
This will work with youtube, webradios, audio streaming services, and so long and so forth.
To restore the audio setting, after the recording is over, you must restart pulseadio with:<br />
<br />
<span style="font-family: 'Courier New', Courier, monospace;">pulseaudio --kill</span><br />
<br />
And furthermore, the program which was generating must be restarted as well. Otherwise, no sound will be heard from your machine.<br />
<br />
And by the way, if you want to hear what's going on in your recording, you can just launch something like 'vlc audioRecord.ogg': it will play you the recording while it's still writing the file! (thank you, Unix File System!)Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com2Roma, Italia41.8905198 12.494248641.5122753 11.8625346 42.2687643 13.125962600000001tag:blogger.com,1999:blog-8991232594986438469.post-59665367984905552012-05-10T19:11:00.001+02:002012-06-17T20:31:47.484+02:00Check for logged usersAt office, we have a cluster made of several machines used for performance experiments. We are not a lot of people, so we explicitly avoided installing software for launching experiments in a controlled way.<br />
<br />
Nevertheless, seldom happens that someone remotely logs in and launches stuff, without noticing, for example, if other users were logged or where running programs, thus invalidating any output from (long) runs.<br />
<br />
So, at last, I wrote the following bash script which, upon ssh login to the servers, outputs a fancy colored message telling that someone else is logged in (if any).<br />
<br />
<pre class="brush:bash">#!/bin/bash
#for user in $(last | grep still | sort | uniq);
ME=`whoami`
for user in $(last -Rw | grep still | sed 's/ .*//' | sort | uniq);
do
if [ "$ME" != "$user" ]
then
echo -en '\E[;31m'"\033[1mWARNING:\033[0m" # Red
echo -en '\E[;34m'"\033[1m \033[4m$user\033[0m \033[0m"
tput sgr0
echo -n "still logged in since "
echo `last -RFw | grep $user | head -1 | awk '{print $4" "$5" "$6}'`
fi
done
</pre>
<div>
<br /></div>
<div>
I've simply added this script to /etc/bash.bashrc, so that every user gets a warning message, if needed.</div>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com2Roma, Italia41.8905198 12.494248641.5122753 11.8625346 42.2687643 13.125962600000001tag:blogger.com,1999:blog-8991232594986438469.post-23389883077979393262012-02-02T18:46:00.002+01:002012-06-17T20:31:47.430+02:00Etimologia del BemolleQuando si inizia a studiare musica, in un momento non meglio precisato degli studi (non meglio precisato perché nessuno, credo, è in grado di ricordarselo) si entra in contatto con le alterazioni. I <a href="http://it.wikipedia.org/wiki/Bemolle">bemolle</a>, i <a href="http://it.wikipedia.org/wiki/Diesis">diesis</a> e i <a href="http://it.wikipedia.org/wiki/Bequadro">bequadro</a> prima, i doppi bemolle e i doppi diesis dopo cominciano a comparire sempre più spesso sugli spartiti. E uno ci si abitua in fretta, stonatura dopo stonatura.<br />
<br />
<div class="latex">
E ci si abitua talmente tanto, che i simboletti $\flat$, $\sharp$ e $\natural$ diventano un'abitudine per gli occhi.</div>
<br />
Però... Perché un bemolle si chiama bemolle?!<br />
<br />
<a name='more'></a><br />
<br />
Per capire da dove esce fuori questo nome, occorre partire da una storia che risale a un bel po' di anni fa (più di quanti si creda).<br />
<br />
Fin dai tempi della musica greca, passando poi per quella romana e andando avanti fino al canto gregoriano, la musica si basava sui cosiddetti "<a href="http://it.wikipedia.org/wiki/Modo_musicale">modi</a>". Un modo non è altro che una successione ordinata di intervalli. Sui nomi degli intervalli c'è stato, nella storia un gran caos. Siccome nasce tutto dalla musica greca (di cui non ci è rimasto un gran che) i nomi dei modi sono stati sempre associati a quelli degli antichi popoli greci, anche se è molto in dubbio il fatto che quest'associazione sia corretta, ossia che il modo "dorico" fosse stato proprio della musica in Doria. Anzi, si sa che alcuni nomi sono stati assegnati proprio a caso. Ma questa è un'altra storia.<br />
<br />
Quello che si sa per certo, studiando il canto gregoriano, è che i modi erano (almeno dai tempi dei romani) talmente fissi che si potrebbe quasi associarli ad una scala. Infatti, un modo cominciava sempre dalla stessa nota. Se si cambiava nota iniziale, si stava cambiando modo.<br />
<br />
<div class="latex">
Nel nostro mondo moderno quasi tutto oramai funziona con il <a href="http://it.wikipedia.org/wiki/Temperamento_equabile">Temperamento equabile</a> (o equalizzato), in cui il rapporto di frequenze che identifica il semitono temperato è il numero (irrazionale) $\sqrt[12]{2}$. Questa scelta crea delle piccolissime imperfezioni negli intervalli, impercettibili quasi all'orecchio, che consentono però una possibilità completa di <a href="http://it.wikipedia.org/wiki/Modulazione_(musica)">modulazione</a> da una qualsiasi tonalità ad un'altra tonalità qualsiasi. Ciò piacque talmente tanto a <a href="http://it.wikipedia.org/wiki/Johann_Sebastian_Bach">Bach</a> che, nel 1722, scrisse <a href="http://it.wikipedia.org/wiki/Il_clavicembalo_ben_temperato">Il Clavicembalo ben Temperato</a>, per mostrare quali fossero le vere potenzialità di questa "nuova" accordatura.<br />
<br />
Ma tornando ai modi... Sfruttando un'accordatura temperata (ad esempio quella di un pianoforte), trovare gli antichi modi è molto molto facile. Basta infatti costruire delle scale di sette note partendo dai vari tasti ed utilizzando soltanto tasti bianchi (mi perdonino questa semplificazione i teorici della musica!).<br />
<br />
Ed abbiamo così, partendo dal re, il modo dorico; partendo dal mi, il modo frigio; partendo dal fa, il modo lidio; partendo dal sol, il modo misolidio. Proprio come in questa figura:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnBAUOlOv0-KYGoM3ZsVDPTLxiYb4volhKMJ6tq8L69yTjcocq5n-6ESNoJtek4N_DkkpDHdRQqzmkucwXmxClHCAlsywkTJwFyTAHP4fY85Zi5d_03DfqG4Wptd58ZL_aQuYnY6wydlcc/s1600/modi.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnBAUOlOv0-KYGoM3ZsVDPTLxiYb4volhKMJ6tq8L69yTjcocq5n-6ESNoJtek4N_DkkpDHdRQqzmkucwXmxClHCAlsywkTJwFyTAHP4fY85Zi5d_03DfqG4Wptd58ZL_aQuYnY6wydlcc/s1600/modi.jpg" /></a></div>
<br />
<br /></div>
Ora, questi erano i modi propri anche del canto gregoriano. Ma se quel canto affonda le sue radici nel passato, nel tempo il gusto delle persone incomincia a cambiare. E (cosa che accade anche a noi se li ascoltiamo oggi), in alcuni passaggi tendono a risultare cacofonici. In particolare, se frigio e misolidio ci suonano "arcaici" o in alcuni passaggi soltanto più tristi (sul frigio si potrebbe aprire un discorso enorme, visto che alcuni tratti si ritrovano anche nella musica popolare napoletana), alcuni ci suonano proprio "sbagliati", soprattutto gli altri due: il dorico e il lidio.<br />
<br />
Successe, allora, che nell'evoluzione del canto gregoriano, i cantori incominciarono ad abbellire questi due modi. In particolare, nel dorico cominciarono ad abbassare il sesto grado di un semitono, e nel lidio il quarto grado. Caso particolarissimo, in entrambi i modi si trattava della nota "si", che veniva abbassata.<br />
<br />
Questa "lieve" modifica (se lieve si può chiamare un abbassamento di un semitono!!!) generava un suono molto più morbido. E, sempre per caso, la nota "si" in antichità veniva chiamata "be", e per descrivere questa "morbidezza" si utilizzava l'aggettivo "molle". Quindi, il bemolle, non è altro che un "si morbido".<br />
<br />
Tuttavia, questi modi "più morbidi" venivano chiamati ancora dorico e lidio.<br />
<br />
Un bel giorno, all'incirca nel 1547, il signor <a href="http://it.wikipedia.org/wiki/Glareano">Heinrich Loriti</a> (noto anche come Glareano o Glariano o Glareanus) scrisse un libro, il Dodekachordon, in cui prese atto di quello che stava accadendo nel mondo della musica e decise che era arrivato il momento di smettere di prendersi in giro: quello che veniva chiamato "dorico" non era più dorico, e lo stesso valeva per il "lidio".<br />
<br />
Nella migliore tradizione, quindi, prese a caso altri due aggettivi derivanti da nomi di popoli greci, l'eolico e lo ionio, e traspose quella sequenza di intervalli, sempre per poter usare solo tasti bianchi. E così l'eolico partì dal la, e lo ionico partì dal do.<br />
E, senza nemmeno rendersene conto, nacquero i modi minore e maggiore. Infatti, il "la eolico" non è altro che il nostro moderno la minore eolico, ed il "do ionico" non è altro che il "do maggiore". Tant'è che il dorico con il "si più morbido" non è nient'altro che il re minore e il lidio con il be molle non è altro che il fa maggiore.<br />
<br />
Come nota storica, Glariano costruì anche il modo locrio, usando solo tasti bianchi sulla nota si. Si tratta di una tonalità "teorica", perché al suo interno contiene l'intervallo si-fa, una quinta diminuita, o <a href="http://it.wikipedia.org/wiki/Tritono">tritono</a>, che è una delle maggiori dissonanze della scala diatonica (e che tende a risolvere verso gradi vicini, una di quelle cose che se lo fate a un esame al conservatorio vi bocciano senza chiedervi neppure il nome).<br />
<br />
<div class="latex">
Poi, nel tempo, si iniziò a trasporre. Si perse sempre di più l'associazione tra modo e nota di partenza. E quindi nacquero il "do frigio", il "fa misolidio", il "si ionico" e così via. Ma per rispettare gli intervalli, non si potevano più utilizzare soltanto tasti bianchi, e per utilizzare le note proprie delle varie scale era necessario indicare sugli spartiti un abbassamento di un semitono qua e là. E per fare questo si continuò ad utilizzare il simboletto $\flat$, che nel tempo prese il nome della nota che ne aveva richiesto l'utilizzo per la prima volta: bemolle.</div>
<br />
Come ultima nota storica, arriva <a href="http://it.wikipedia.org/wiki/Guido_Monaco">Guido d'Arezzo</a>. Egli è colui che diede i nuovi nomi alle note musicali, quelli che i popoli latini utilizzano (a parte il do) ancora oggi. Cambiò infatti i nomi da C, D, E, F, G, A (il do corrispondeva alla C perché la nomenclatura partiva dal la) in ut, re, mi, fa, sol, la. I nomi li prese da <i>Ut Quean Laxis,</i> un inno liturgico dei Vespri della solennità di <a href="http://it.wikipedia.org/wiki/Ut_queant_laxis">San Giovanni Battista</a>:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTbeL1o0zWY9PT36nL8y72fpBuBXc0Uozkz8L7nuW2IK4scV5hdQC2vUshreOLHL9Y7bc_44W35FrL4wYRx5rZmc1k6Wx6azOSdfiQRbwMHVLMwmrE2dvArcNu6CrA3vMgQidC-wv8BINf/s1600/Hymne_St_Jean_Baptiste.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTbeL1o0zWY9PT36nL8y72fpBuBXc0Uozkz8L7nuW2IK4scV5hdQC2vUshreOLHL9Y7bc_44W35FrL4wYRx5rZmc1k6Wx6azOSdfiQRbwMHVLMwmrE2dvArcNu6CrA3vMgQidC-wv8BINf/s1600/Hymne_St_Jean_Baptiste.png" /></a></div>
<br />
Il testo della prima strofa recita infatti:<br />
<br />
<table align="center">
<tbody>
<tr>
<td><div style="text-align: center;">
«<b>Ut</b> queant laxis</div>
<div style="text-align: center;">
<b>Re</b>sonare fibris</div>
<div style="text-align: center;">
<b>Mi</b>ra gestorum</div>
<div style="text-align: center;">
<b>Fa</b>muli tuorum</div>
<div style="text-align: center;">
<b>Sol</b>ve polluti</div>
<div style="text-align: center;">
<b>La</b>bii reatum</div>
<div style="text-align: center;">
Sancte Iohannes »</div>
</td>
<td><div style="text-align: center;">
«Affinché possano cantare</div>
<div style="text-align: center;">
con voci libere</div>
<div style="text-align: center;">
le meraviglie delle tue azioni</div>
<div style="text-align: center;">
i tuoi servi,</div>
<div style="text-align: center;">
cancella il peccato</div>
<div style="text-align: center;">
del loro labbro contaminato,</div>
<div style="text-align: center;">
o san Giovanni»
</div>
</td>
</tr>
</tbody></table>
<br />
<br />
Il nome della nota si venne aggiunto poi in seguito nel XVI secolo dall'abbreviazione di <b>S</b>ancte <b>I</b>ohannes.<br />
<br />
Fu poi <a href="http://it.wikipedia.org/wiki/Giovanni_Battista_Doni">Giovanni Battista <b>Do</b>ni</a> che, nel 1600, sostituì ut con do per ragioni eufoniche (provate a cantare una nota lunga dicendo "uttttttttttttt").<br />
<br />
<div class="latex">
In ogni caso, Guido d'Arezzo chiamò il si di cui ho parlato tanto fin'ora "<i>b rotundum"</i>, per contrapporlo a quello dal suono più spigoloso che chiamò, appunto, "<i>b quadrum</i>". Bequadro. $\natural$. Tutto torna!</div>
<br />Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com7Roma, Italia41.8905198 12.494248641.5122753 11.8625346 42.2687643 13.125962600000001tag:blogger.com,1999:blog-8991232594986438469.post-61600057045120031672012-01-19T13:05:00.000+01:002012-07-06T11:52:04.275+02:00Installing mldonkey on FreeNAS 8.0 embeddedI have recently been able to successfully install <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><a href="http://mldonkey.sourceforge.net/">mldonkey</a></span> on my fresh amd64 <a href="http://www.freenas.org/">FreeNAS</a> 8.0.3 embedded (HP Proliant Microserver) setup. I think <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">mldonkey</span> is a piece of software that cannot be renounced, so I'm leaving here a tutorial showing the steps I followed through to have a correct working install.<br />
<br />
<span class="Apple-style-span" style="color: red;">Caveat</span>: FreeNAS USB installs give really few space available on the / partition. Consider that installing software in it can fill up all the available space, possibly resulting in system crashes. Before following this tutorial, please take into account the real amount of free space available on your / partition, considering that ~10 MB of space will be used by mldonkey software (at the time this tutorial was written!)<br />
<br />
<ol>
<li>Log as root into the NAS, either through ssh or through the console. If you log in as a regular user, type <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">su</span> and enter root password.</li>
<li>We have to install software into the / tree, so we have to make it first of all writeable:<br /><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"># mount -uw /</span></li>
<li>FreeNAS is pointing by default to a repository which <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">mldonkey</span> is not available to download from. Luckily enough, we can find a working binary in an upper level of the repository tree. So, install it this way:<br /><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"># pkg_add -r ../net-p2p/mldonkey-core-3.0.6</span><br /><br />Please notice that you have to put the current available version in order to correctly downlaod it. If errors about not finding the package are shown, point your browser to the <a href="ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-8.2-release/net-p2p/">net-p2p folder</a> in the repository and check which package is available.<br /><br />The download/install procedure will actually take a while, as installing on the USB stick is a slow process.</li>
<li>Now log into the web interface and create a new user under Account > Users > Add User<br /><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Username</span>: mlnet<br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Password</span>: *****<br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Home Directory</span>: /mnt/SHARED-DISK/mlnet/<br /><br />Where SHARED-DISK is your storage mount point.</li>
<li>I use my station as a server, so there are multiple users in it. To let all of them get access to the downloaded files, change permissions from a ssh/console shell accordingly:<br /><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"># chmod 760 /mnt/SHARED-DISK/mlnet/</span></li>
<li>Now we have to configure the downloads.ini file. First of all, we have to let mldonkey create its configuration files. Log in (from either ssh or console) as mlnet, using the credentials created at step 4.<br />Launch mldoney:<br /><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"># mlnet</span><br /><br />The program will setup and then hung, waiting for connections. Kill it with CTRL + C.<br /><br />Now cd into /mnt/SHARED-DISK/.mldonkey and edit the downloads.ini using vi, ee, or your favorite shell editor.<br /><br />Find the line:<br /><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">allowed_ips = ["127.0.0.1";]</span><br /><br />After the semicolon, add "your ip". Note that you can, for example, allow connections from a subnet in your LAN, specifying the correct subnet mask like "192.168.1.0/24"</li>
<li>Now we want to tell FreeNAS to automatically launch mldonkey at startup. We will be using rc.local to this end:<br /><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">cd /conf/base/etc/</span><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">vi rc.local</span> (this will create the file if not already existing)<br /><br />At the end of the file (or at a suitable place according to your configuration) enter the line:<br /><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">su mlnet -c mlnet &</span><br /><br />This will launch mldonkey as mlnet user and continue the startup of the machine.</li>
<li>When the machine is fully booted, access mldonkey url:<br /><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">http://YOUR-NAS-IP:4080</span><br /><br />Now, you can start using and configuring mldonkey according to your needs!</li>
</ol>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com7Roma, Italia41.8905198 12.494248641.5122753 11.8625346 42.2687643 13.125962600000001tag:blogger.com,1999:blog-8991232594986438469.post-38551485715167410942012-01-06T12:32:00.001+01:002012-06-17T20:31:47.466+02:00Epifania<div><p>Se i Re Magi fossero onorevoli<br>
Rinuncerebbero a tutti i convenevoli<br>
A Erode direbbero: "Maestà<br>
Ti diamo il Bimbo, lasciaci l'indennità!"</p>
</div>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0tag:blogger.com,1999:blog-8991232594986438469.post-79666720288106535162011-12-29T17:51:00.000+01:002012-06-17T20:31:47.535+02:00Cello WarsI just have to share this!<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.youtube.com/embed/BgAlQuqzl8o?feature=player_embedded' frameborder='0'></iframe></div>
<div>
<br /></div>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0tag:blogger.com,1999:blog-8991232594986438469.post-62912286982170668912011-12-25T11:50:00.000+01:002012-06-17T20:31:47.493+02:00Custom Facebook EmoticonsPeople wants emoticon. And whenever the chatting system does not allow to customize them, they start to complain.<br />
Think of Skype. They sometimes add 2-3 new emoticons, and people starts again ranting.<br />
<br />
Another place where I have been watching people asking for custom emoticons is Facebook. Many hoaxes came around, like "spam this page to everyone in the world and you'll receive custom smiles!", but few know that a custom emoticon system is already there.<br />
<br />
Further, we all have a custom emoticon of ourselves!<br />
<br />
Try this. I want a trollface emoticon to add into chat message. I search for a page and find this one:<br />
<a href="https://www.facebook.com/pages/Trollface/313306795360291">https://www.facebook.com/pages/Trollface/313306795360291</a><br />
<br />
Now, I note that there is a numerical code in it: 313306795360291<br />
<br />
<div class="separator" style="clear: both; text-align: left;">
If in the chat board I type [[313306795360291]], this emoticon will show up: <img border="0" src="https://graph.facebook.com/235870503108081/picture" valign="center" /></div>
<br />
If you try with a personal page, you might find a link like:<br />http://www.facebook.com/profile.php?id=NUMBER<br /><br />Again, use [[NUMBER]] and you will get that person's emoticon!Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com1tag:blogger.com,1999:blog-8991232594986438469.post-32318106375387635582011-12-18T11:01:00.001+01:002012-06-17T20:34:17.884+02:00Code Obfuscation (Example 1)Following through the series of posts about code obfuscation and unmaintainable code, I want to show here a C code snippet:<br />
<br />
<br />
<pre class="brush:cpp">#define x(y,z) z , y
#define y(z,x) x z
#define a(b,c) c##b
#define x167 }
#define x879 x167;
#define x798 '\0'x879
#define x98 {
#define _ a(ain,m)
#define __ ()
#define b(c,d) a(c,d)
#define w a(ar,ch)
w ____[] = x98 x(0154, x(0145, 0110)), 108, 111, 30+02, 87, 0x6f, 0162, 0x6c, 0x64, x798
w ___[] = x98 '%', 's', x(x798, '\n')
_ __ x98 y((___, ____),a(ntf,pri)); x167
</pre>
<br />
<br />
This is indeed a full working program, and the techniques used here to screw the code are simple enough. What's the actual purpose of this program?<br />
<br />
Compile & running it (or gcc -E) are good means to see in its internals.<br />
<br />
No further explanation is being given here, as I consider this to be easy enough!Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com5tag:blogger.com,1999:blog-8991232594986438469.post-16353061494655531822011-12-15T14:09:00.000+01:002012-06-17T20:31:47.419+02:00Drive Safely<div class="separator" style="clear: both; text-align: left;">
A recent scientific result tried to clearify everything about driving:</div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHCPOdvYwIPrcxvTXFgNHcMvDYdKZ1CmlpZBXY6YTl2v3dKjuQXymwxqitLwws5qRaLhLBEOsfAJ0V_Ecl0zUpBy_o_7msANvMTPTlixdoxUwoj9bj1ynKVgtV5Tic3S1RGSe-Isy-BVTe/s1600/drive-safely.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHCPOdvYwIPrcxvTXFgNHcMvDYdKZ1CmlpZBXY6YTl2v3dKjuQXymwxqitLwws5qRaLhLBEOsfAJ0V_Ecl0zUpBy_o_7msANvMTPTlixdoxUwoj9bj1ynKVgtV5Tic3S1RGSe-Isy-BVTe/s1600/drive-safely.png" width="600" /></a></div>
<br />
<br />
The study was to show that, unless you're in a situation where <i>three</i> to <i>five</i> minutes will make a significant different in an outcome, there's no point in speeding.<br />
<br />
But it should be noted that this graph actually suggests that you reap a pretty significant benefit from speeding if the speed limit is less than 30 mph.<br />
<br />
So the moral of the story is: <i>speed in school zones and residential areas</i>, not on the highways.Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0Rome, Italy41.8905198 12.494248641.5122753 11.8625346 42.2687643 13.125962600000001tag:blogger.com,1999:blog-8991232594986438469.post-41017096474094675102011-12-12T12:50:00.000+01:002012-06-17T20:34:17.892+02:00Converting PDF into Plain TextAt work I often receive pdf documents with no OCR information in it, and in order to modify/extract parts from them I need to convert them to plain text.<br />
<br />
As a Unix user, I love the command line, and I have been searching for something like:<br />
<br />
./pdf2text file.pdf<br />
<br />
So this is what I have written in order to provide support for this useful command line tool. Is is based on <a href="http://code.google.com/p/tesseract-ocr/">tesseract</a>, which is now under development by Google.<br />
Remember that in order to interpret documents which are non-English, data files for the language must be installed separately, as most distributions just bring the English one with the main package.<br />
<br />
As tesseract is able to work with TIFF images, the first tool to be developed is pdf2tif. If none is already available on your machine, you can use the following script which is based on <a href="http://pages.cs.wisc.edu/~ghost/">ghostscript</a>:<br />
<br />
<b>pdf2tif:</b><br />
<br />
<pre class="brush:bash">#!/bin/sh
# Derived from pdf2ps.
# Convert PDF to TIFF file.
OPTIONS=""
while true
do
case "$1" in
-?*) OPTIONS="$OPTIONS $1" ;;
*) break ;;
esac
shift
done
if [ $# -eq 2 ]
then
outfile=$2
elif [ $# -eq 1 ]
then
outfile=`basename "$1" .pdf`-%02d.tif
else
echo "Usage: `basename $0` [-dASCII85EncodePages=false]
[-dLanguageLevel=1|2|3] input.pdf [output.tif]" 1>&2
exit 1
fi
# Doing an initial 'save' helps keep fonts from being flushed between pages.
# We have to include the options twice because -I only takes effect if it
# appears before other options.
gs $OPTIONS -q -dNOPAUSE -dBATCH -dSAFER -r300x300 -sDEVICE=tiffg3 "-sOutputFile=$outfile" $OPTIONS -c save pop -f "$1"
</pre>
<div>
<br />
<br />
This script will be later invoked by out pdf2text, which will take as input a pdf file, which will create a temporary folder, convert every pdf page into a separate tif image, and then feed tesseract with them.</div>
<div>
<br /></div>
<div>
<b>pdf2text:</b></div>
<div>
<br /></div>
<div>
#!/bin/sh</div>
<div>
<br /></div>
<pre class="brush:bash">#!/bin/sh
# takes one parameter, the path to a pdf file to be processed.
# uses custom script 'pdf2tif' to generate the tif files,
# generates them at 300x300 dpi.
# then runs tesseract on them
mkdir $1-dir
cp $1 $1-dir
cd $1-dir
pdf2tif $1
for j in *.tif
do
x=`basename $j .tif`
tesseract ${j} ${x}
rm ${x}.raw
rm ${x}.map
#un-comment next line if you want to remove the .tif files when done.
#rm ${j}
done
cat *.txt > $1.txt
mv $1.txt ..
cd ..
rm -rf $1-dir
</pre>
<div>
<br />
After its execution, a .txt file with the same basename as the pdf's will be created, containing the OCR'd text in it!</div>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0tag:blogger.com,1999:blog-8991232594986438469.post-17861137838637888222011-12-03T15:23:00.000+01:002012-06-17T20:34:17.872+02:00Latex in HTML (revisited)Some time ago I <a href="http://polytimenerd.blogspot.com/2011/10/latex-in-html-with-javascript-and.html">published a post</a> where I was presenting an easy tool to be integrated into web pages which allows to render LaTeX equations just embracing the code into $ sings.<br />
<br />
I never noticed how much I used the dollar sign until I developed this script!! It has texified so much text which wasn't expected to be, that I decided to change the approach a bit. Now, Instead of parsing the whole document, I'm just parsing the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">div</span>s the class of which is "latex". <br />
<br />
So now, depending on the class of the actual container of the text I can have this behaviour:<br />
<br />
$3 + 2 = 5$<br />
<br />
or this one:<br />
<br />
<div class="latex">
$3 + 2 = 5$</div>
<br />
As easy as changing the <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">div</span>'s class. The code in the previous post has been updated accordingly!Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0Piazzale Gregorio VII, 29-42, 00165 Rome, Italy41.8994469 12.45129817.8872094 -27.9783895 65.9116844 52.8809855tag:blogger.com,1999:blog-8991232594986438469.post-25228615984071463102011-11-30T12:19:00.001+01:002012-06-17T20:31:47.435+02:00Math Exam<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj59aUVhVzXiTWrQIQFEmYxdy53xEDDV3luprOHhVYv2mLhvkr5WDVmVt8RsT4rzN2ZBEA0vUogP98Z_oiQVkJhGEMPtu_3qgBMs3WW4ysvnl5pW6_pUZoJyIsujHX9KS-qU3ds10fehm2/s1600/Math-Fail-Pics-227.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgj59aUVhVzXiTWrQIQFEmYxdy53xEDDV3luprOHhVYv2mLhvkr5WDVmVt8RsT4rzN2ZBEA0vUogP98Z_oiQVkJhGEMPtu_3qgBMs3WW4ysvnl5pW6_pUZoJyIsujHX9KS-qU3ds10fehm2/s1600/Math-Fail-Pics-227.jpg" /></a></div>
<br />Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com037067 Valeggio sul Mincio Province of Verona, Italy45.3539721 10.736490845.2647061 10.5785623 45.4432381 10.894419300000001tag:blogger.com,1999:blog-8991232594986438469.post-72611361989702912732011-11-26T20:51:00.000+01:002012-06-17T20:34:17.903+02:00Itaca<br />
<div style="text-align: center;">
Quando ti metterai in viaggio per Itaca</div>
<div style="text-align: center;">
devi augurarti che la strada sia lunga, </div>
<div style="text-align: center;">
fertile in avventure e in esperienze. </div>
<div style="text-align: center;">
I Lestrigoni e i Ciclopi</div>
<div style="text-align: center;">
o la furia di Nettuno non temere, </div>
<div style="text-align: center;">
non sarà questo il genere di incontri</div>
<div style="text-align: center;">
se il pensiero resta alto e un sentimento</div>
<div style="text-align: center;">
fermo guida il tuo spirito e il tuo corpo. </div>
<div style="text-align: center;">
In Ciclopi e Lestrigoni, no certo, </div>
<div style="text-align: center;">
ne' nell'irato Nettuno incapperai</div>
<div style="text-align: center;">
se non li porti dentro</div>
<div style="text-align: center;">
se l'anima non te li mette contro.</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
Devi augurarti che la strada sia lunga. </div>
<div style="text-align: center;">
Che i mattini d'estate siano tanti</div>
<div style="text-align: center;">
quando nei porti - finalmente e con che gioia -</div>
<div style="text-align: center;">
toccherai terra tu per la prima volta: </div>
<div style="text-align: center;">
negli empori fenici indugia e acquista</div>
<div style="text-align: center;">
madreperle coralli ebano e ambre</div>
<div style="text-align: center;">
tutta merce fina, anche profumi</div>
<div style="text-align: center;">
penetranti d'ogni sorta; piu' profumi inebrianti che puoi, </div>
<div style="text-align: center;">
va in molte città egizie</div>
<div style="text-align: center;">
impara una quantità di cose dai dotti.</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
Sempre devi avere in mente Itaca -</div>
<div style="text-align: center;">
raggiungerla sia il pensiero costante. </div>
<div style="text-align: center;">
Soprattutto, non affrettare il viaggio; </div>
<div style="text-align: center;">
fa che duri a lungo, per anni, e che da vecchio</div>
<div style="text-align: center;">
metta piede sull'isola, tu, ricco</div>
<div style="text-align: center;">
dei tesori accumulati per strada</div>
<div style="text-align: center;">
senza aspettarti ricchezze da Itaca. </div>
<div style="text-align: center;">
Itaca ti ha dato il bel viaggio, </div>
<div style="text-align: center;">
senza di lei mai ti saresti messo</div>
<div style="text-align: center;">
sulla strada: che cos'altro ti aspetti?</div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
E se la trovi povera, non per questo Itaca ti avrà deluso. </div>
<div style="text-align: center;">
Fatto ormai savio, con tutta la tua esperienza addosso</div>
<div style="text-align: center;">
già tu avrai capito ciò che Itaca vuole significare.</div>
<br />
<div style="text-align: right;">
<i>- Kostantin Kavafis</i></div>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0Rome, Italy41.8905198 12.494248641.5122753 11.8625346 42.2687643 13.125962600000001tag:blogger.com,1999:blog-8991232594986438469.post-4577299662876158772011-11-22T20:35:00.000+01:002012-06-17T20:31:47.473+02:00Il ViaggioQualche giorno fa pensavo alla bellezza di viaggiare, incontrare nuove persone e scoprire nuove culture. Poco dopo mi sono imbattuto in una copia del mio tema di maturità. Il caso?<br />
<br />
<i>Il turista non è il viaggiatore: le cose, e non gli esseri umani, sono oggetto della sua predilezione. Viaggiare dovrebbe essere tutt'altro: fermarsi più a lungo e girare di meno. Chi vuole davvero viaggiare dev'essere a conoscenza del fatto che è meglio un'esperienza spazialmente più limitata ma carica di emozioni e sensazioni, piuttosto che un gran numero di immagini che al termine del viaggio si affastellano l'una dietro l'altra nella memoria, senza quasi più un ordine logico. Il vero viaggiare è un'operazione complessa, che necessita della collaborazione e della consapevolezza del viaggiatore: non è cosa da poco, non è soltanto uno spostamento, è molto di più.</i><br />
<i></i><br />
<a name='more'></a><i>Il viaggio è perenne lontananza: dice Soldati che «mentre la meta si avvicina e diventa reale, il luogo di partenza si allontana e sostituisce la meta nell'irrealtà dei ricordi». Non potremo mai essere ovunque: saremo sempre assaliti dal desiderio di trovarci in un altro luogo, rischiando di non godere delle bellezze che ci circondano in quel momento.</i><br />
<i>Il viaggio è però anche memoria: Affinati, sul Corriere della Sera, scriveva: «quando parto cerco di trovare, innanzitutto, le ragioni del ritorno». Ci si abitua ai nuovi luoghi, si entra nella mentalità del posto che si visita, si conoscono nuove persone... È facile per l'uomo immedesimarsi in una nuova cultura, ambientarsi in un nuovo paese, e si rischia così di lasciarsi alle spalle le proprie origini, di non voler più tornare indietro. Il viaggiatore non deve mai dimenticare chi è realmente.</i><br />
<i>Il viaggio è compagnia: è avere sempre al proprio fianco qualcuno, un amico, con cui parlare, con cui scontrarsi, litigare, ridere, piangere, in cui convogliare le proprie paure, al quale affidare le proprie gioie, per avere sempre qualcuno su cui poter contare nei momenti di bisogno.</i><br />
<i>Il viaggio è strada: dover mettere un piede dietro l'altro, in salita, in discesa, con il sole, con la pioggia, d'estate o d'inverno, senza mai fermarsi, quasi in una sorta di "simbiosi mistica": il viaggiatore senza strada non è più tale, e la strada senza viaggiatore che motivo ha di essere?</i><br />
<i>Il viaggio è saper riconoscere i propri limiti: chi viaggia non può ambire a conoscere tutto lo scibile umano. Come dice Virgilio nel IV libro delle Ecloghe, «si parva licet componere magnis», possiamo paragonare l'uomo alla formica, che non riuscirà mai a consocere tutti i meandri e tutte le pieghe della corteccia dell'albero che ospita il suo formicaio: non ha abbastanza tempo, deve sapersi limitare, deve saper scegliere.</i><br />
<i>Il viaggio è fantasia ed immaginazione: scriveva il greco Kavafis, nella sua poesia "Itaca", che dobbiamo aspettarci il meglio dalla meta del nostro viaggio, senza però voler bruciare tutte le tappe per giungere subito alla fine, senza fretta: visiteremo paesi lontani, luoghi sconosciuti, vedremo popoli stranieri, animali meravigliosi, sempre pensando alla meta del nostro ulissiaco viaggio, immaginandocela bellissima. E quando giungeremo ad Itaca, forse ne rimarremo delusi, perché non è esattamente come la immaginavamo: è troppo spoglia, scarna. Ma non importa, perché ci rimane impresso dentro tutto quello che abbiamo già visto e vissuto. Forse, come dice Citati, il paese che immaginavamo giallo è verde, mentre quello che pensavamo rosso è in realtà celeste. I luoghi dei due viaggi, quello fantastico e quello reale, non sempre coincidono, rischiando di lasciarci delusi. Ma nessuno deve rinunciare a viaggiare con la fantasia, a immaginarsi paesi lontani, a sognare, perché perderebbe un viaggio anche più bello di quello reale.</i><br />
<i>Il viaggio è incertezza: secondo Magris l'Ulisse odierno non assomiglia a quello omerico, sicuro di sé e razionale, o joyciano, che dal visitare Dublino trae memorie e ricordi, grazie alle sue epifanie. L'uomo è sempre più incerto nel trovare se stesso. Il moderno Ulisse è quello del folle volo dantesco che, impavido e sprezzante del pericolo, va oltre i confini del mondo, spinto da una disperata sete di conoscenza, e ad un passo da essa, quando sta per afferrarla, arriva il nulla, viene inghiottito dalle acque e si perde nell'infinito. Oppure, meglio ancora, è come l'Ulisse di Pascoli, che ripercorre al contrario il tragitto del viaggio da lui compiuto in gioventù, per rivisitare i luoghi delle mille avventure di un tempo ma, inesorabilmente, si accorge che nulla di tutto ciò esiste e in preda alla disperazione arrivato allo scoglio delle sirene si avvicina sempre di più e più in fretta chiamandole e sperando di trovarle ma quando si accorge che nella realtà esse non esistono è troppo tardi e la nave si schianta, affonda, Ulisse affoga. Ma a cercar bene non c'è motivo di disperarsi: una risposta c'è, va solo trovata: il corpo di Ulisse, infatti, giunge tragicamente sulle rive dell'isola di Calypso, dove la donna che esisteva realmente trova il corpo e piange per la morte dell'eroe. Non tutto è un'illusione. La possibilità di trovare noi stessi c'è sempre: non dobbiamo sprecarla.</i><br />
<i>Il viaggio è purtroppo anche obbligo: migliaia e migliaia di persone sono costrette, ogni anno, ad emigrare dal loro paese e a rifugiarsi come esuli altrove. È una condizione, questa, che rende il viaggio terribile, frustrante, insopportabile. Alcuni dei "grandi esuli" della nostra letteratura ci hanno trasmesso dolorose immagini di questa condizione: Quasimodo, in Vento a Tindari, sottolinea come sia "amaro" da rompere il pane straniero («amaro pane a romepere»), mentre Dante ci dice esplicitamente «quanto sa di sale lo pane altrui». Sempre, però, anche nella sofferenza, si dovrebbe aspirare ad una condizione di felicità interiore, sorridendo e cantando anche nelle difficoltà, per evitare di lasciarsi andare e di deprimersi.</i><br />
<i>Il viaggio è, in sintesi, la vita: Todorov la definisce proprio come un «viaggio dalla nascita alla morte». È piuttosto una sorta di viaggio in treno: saliamo alla nostra stazione e ci sediamo al posto che ci è stato assegnato. Troviamo vicino a noi persone sconosciute, mai viste, e cogliamo un'occasione insignificante come un bel paesaggio che si scorge dal finestrino, per avviare una conversazione. Il treno prosegue veloce, le stazioni si susseguono, e intanto noi conosciamo sempre meglio i nostri compagni di viaggio, il carattere burbero dell'imprenditore che è seduto di fronte a noi, il fare scherzoso della signorina al posto vicino al nostro, la silenziosità del vecchietto che legge il giornale appoggiato al finestrino. E intanto la stazione d'arrivo s'avvicina. Quando stiamo per arrivare ci alziamo e prendiamo i nostri bagagli, salutiamo i nostri compagni di viaggio e ci avviciniamo alle porte del vagone. Ecco la stazione d'arrivo, guardiamo per l'ultima volta i nostri compagni di viaggio e scendiamo. Loro hanno ancora molta strada da fare: buon viaggio!</i>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0Rome, Italy41.8905198 12.494248641.5122753 11.8625346 42.2687643 13.125962600000001tag:blogger.com,1999:blog-8991232594986438469.post-28281450693126429012011-11-15T19:48:00.000+01:002012-06-17T20:31:47.446+02:0050 ways to cope with stressStress is everywhere around us. At work, in our homes, even on each word (yes, that's English humour!).<br />
<br />
Here is a list of things I find useful to fight stress away. Doing all of them every day is difficult, somewhat impossibile. But if you are interested in this post, then you should definitely give them a try!<br />
<br />
<ul>
<li>Get up 15 minutes earlier</li>
<li>Prepare for the morning the night before</li>
<li>Don't rely on your memory... write things down</li>
<li>Repair things that don't work properly</li>
<li>Make duplicate keys</li>
<li>Say "no" more often</li>
<li>Set priorities in your life</li>
<li>Avoid negative people</li>
<li>Always make copies of important papers</li>
<li>Ask for help with jobs that you dislike</li>
<li>Break large tasks into bite sized portions</li>
<li>Look at problems as challenges</li>
<li>Smile more</li>
<li>Be prepared for rain</li>
<li>Schedule a play time into every day</li>
<li>Avoid tight fitting clothes</li>
<li>Take a bubble bath</li>
<li>Believe in you</li>
<li>Visualize yourself winning</li>
<li>Develop a sense of humour</li>
<li>Stop thinking tomorrow will be a better today</li>
<li>Have goals for yourself</li>
<li>Say hello to a stranger</li>
<li>Look up at the stars</li>
<li>Practise breathing slowly</li>
<li>Do brand new things</li>
<li>Stop a bad habit</li>
<li>Take stock of your achievements</li>
<li>Do it today</li>
<li>Strive for excellence, not perfection</li>
<li>Look at a work of art</li>
<li>Maintain your weight</li>
<li>Plant a tree</li>
<li>Stand up and stretch</li>
<li>Always have a plan B</li>
<li>Learn a new doodle</li>
<li>Learn to meet your own needs</li>
<li>Become a better listener</li>
<li>Know your limitations and let others know them too</li>
<li>Throw a paper airplane</li>
<li>Exercise every day</li>
<li>Get to work early</li>
<li>Clean out one closet</li>
<li>Take a different route to work</li>
<li>Leave work early (with permission)</li>
<li>Remember you always have options</li>
<li>Quit trying to "fix" other people</li>
<li>Get enough sleep</li>
<li>Praise other people</li>
<li>Relax, take each day at a time... you have the rest of your life to live</li>
</ul>Alessandro Pellegrinihttp://www.blogger.com/profile/02638335102757891067noreply@blogger.com0Rome, Italy41.8905198 12.494248641.5122753 11.8625346 42.2687643 13.125962600000001