2010-12-12

Acer again

At last I've bought it: a new Acer Extensa 5235... Once I said I won't buy an Acer again because it was unsupportive with GNU/Linux and too much sort of "Microsoft is the best, buy it with my computers", but it happened this one came without Microsoft Windows... Maybe (surely) not the best hardware I could get, but it is a lot more than I've got before, and cheaper than I planned at the beginning.

It came with "Linpus", that I wiped out after discovering a part of it (if not the whole system) was compiled in 2008, and that it was badly installed (in fact the computer started only selecting "start with the last working config" from grub menu), and that it wasted a lot of hd giving not too much... thus I've rejected the dual boot idea and reinstalled Ubuntu 10.10, and I am still "tuning" it (again:().

Having this powerful hardware, and a lot of room on the hd (going from 30 Gbyte shared among MS Windows and GNU/Linux to 250 Gbyte made me ask myself what I can do with all that free space...), I've installed many things I had not installed before, e.g. and notably FlightGear.

While installing software and software, I've realized I have badly partitioned the hd, and soon I'll have to change something; anyway this should not be an issue I hope.

Leaving some notes that could be useful:


  • To be able to control brightness from Ubuntu, I had to add acpi_osi="Linux" into GRUB_CMDLINE_LINUX_DEFAULT in /etc/default/grub (you have to escape the " and write indeed \"), and so in the same time I become aware of the fact that grub is changed: no more menu.lst, it's built on the run now...

  • If you install from "third parties" or, even worse, from files that are not .deb (like the Adobe Acrobat Reader which give an executable) and you are not able to edit your menus anymore, you could find interesting to know that the program for menu editing is called alacarte (from french à la carte, I suppose) and if you run it from the command line you'll be informed of what went bad; in my case, it happened that some directories and files in my ~/.config/menus folder had root as owner, instead of me... of course, a consequence of a badly written installer called with sudo; solved with sudo chown -R ME:ME .config/menus; check for symlinks before.

  • Webcam and microphone works without any effort, and wireless too...

  • ZynAddSubFx had problems and I've uninstalled it; though it is an interesting piece of software, I am now "devoted" to Csound and other tools, so I don't need it; however I think the knot that made it not work could be back when running other apps. I hope I am wrong.

  • Emacs started with a too high window (frame), I had to apply a fix in the .emacs; currently I've used a solution found in a blog, but I do not like it since it change the size after it was opened, so the user can see the change; however the solution tries to get the best size at "runtime"

  • Though this notebook was not sold with MS Windows, the keyboard has its logo on it... as usual, I've mapped it to Meta (mainly for Emacs usage); and of course the Menu key is bound to Compose

  • Euro and Dollar key near the "direction keys" do not work; xev does not "listen" to them; I will find a solution one day; but I find those keys mostly unuseful, it would be more interesting to map them to something more interesting than €$, even if their position suggests the binding can't be "critic"



I haven't copied data from the old good hd into this one yet, so I feel still al little bit "naked". Since the old laptop is out of order, I'll need to put its hd in a IDE-usb "bay" or something like that. I'll do.

2010-12-08

Traffic stats

I've just seen that there are stats about blog traffic! And I've just discovered a lot of traffic came from StackOverflow, a place I've almost discontinued to frequent — good place for practical solutions to practical problems, but absolutely deaf and blind for reasoning, "theoretical" analysis of hypothesis, exploring knowledge and so on (like any other Q&A site, no matter how much technical they call themselves)...

Anyway since it can produce traffic to this very "useful" blog, the piece of me allured by net popularity (!) is suggesting me not to forget the place... Now that I am thinking about it, I've left alone a war-speech about the output of a (intentionally) wrong piece of C code and distinction between "undefined" and "unspecified" behaviour in the standard paper for the language. It's enough for today, but in the weekend, if I'll own a brand new laptop, I'll poke the fire until someone can explain for real and competently why that code outputs what many people expect, as if it would be "unspecified behaviour", and what should realistically happen under the cover of the compiler in order to manifest the "undefined behaviour" — my position was that the specific code will output always what indeed it outputs, despite the "undefinition", and so, in the specific case, for the specific code, no "undefined behaviour" can manifest itself (and indeed even the unspecified behaviour would be hidden by the way the code was written, it was about passing a "problematic" argument to a printf with a format string that would take only one argument, details on SO, but I'll be back on the topic, don't be afraid).

Wo, two posts in a day, I am growing the statistics!

How many days in a month?

A coworker proposed to me a little challenge sometimes I think about. My first solution, though correct, was rejected since it used the ternary operator ?: and there's a way to succeed without.

Today is holiday here in Italy and I am using my spare time pushing the button of my almost-dead laptop just to hear the one-long-beep-two-short-beeps sequence (hoping not to hear it), then hold the button to turn it off and then stick hitting keys on the job laptop — where I am now.

After I've read a lot of pages from On the Edge - The Spectacular Rise and Fall of Commodore, almost finishing it, I decided to let my eyes be enlightened by the LCD of the job laptop, where there's nothing more interesting to do than surfing the net and using gcc (MinGW) in the unpleasant environment MS Windows XP provides.

Ok stop making the post longer than it could be...

The challenge was: using just an expression, get the number of days in a specified month (given as a number from 1 to 12). No-one told me about constraints for February so I assumed it has 28 days; moreover, initially there was no prohibition of the ternary operator...

My first solution was:

g = 31 - ((m < 9)? (m+1)%2 : m%2) - 2*(m==2);

which worked on all the system I've tested it (MS Windows, Sun Solaris on SPARC, and GNU/Linux on Intel) but obviously contains a possible bug dued to m==2 that does not need to be evaluated as 1 when true, though likely it does (As std C says, boolean expressions evaluate to 1 when true; unless we're dealing with non std compliant compiler, or if we translate the idea in other languages).

My second solution is:

g = "103012310321"[m-1] - 18 - (m&2);

This one is maybe tricky but is more robust (provided m is in [1,12] and we are on a system using ASCII), and can be easily modified in order to yield 29 for February. Moreover, what it makes me like it is that it uses something rarely many non-expert programmers are aware of about C (I mean using "array notation" for a literal string). The practice could be marked as bad, but it is great when codegolfing!

About codegolfing... If I am not wrong, that code in GolfRun would be "103012310321"m(=18-m2&- but currently I can't test it since my already-compiled (for GNU/Linux) work-in-progress GolfRun interpreter is on the Real Out-Of-Work Laptop, though I could checkout the SVN repository on this machine and try to compile it with MinGW on MS Windows — what a pity it uses Gtk+ and GMP extensively and I want not to go into the trouble of having them properly installed (ready for development usage) on this hateable system.

The third solution to the challenge that comes into my mind is about looking at the bits. The previous solution already does it... a bit! But the idea can be extended; for this purpose I've made the following table


XY ABCD
31 1F 1 11 11 1 0001
28 1C 1 11 00 2 0010
31 1F 1 11 11 3 0011
30 1E 1 11 10 4 0100
31 1F 1 11 11 5 0101
30 1E 1 11 10 6 0110
31 1F 1 11 11 7 0111
31 1F 1 11 11 8 1000
30 1E 1 11 10 9 1001
31 1F 1 11 11 10 1010
30 1E 1 11 10 11 1011
31 1F 1 11 11 12 1100


We have four bits in input and we need to "produce" just 4 "patterns" (two bits) in output. The boolean table old school (and semplification thereafter) will give us a solution (paper and pen here for a while...) (^ stands for an overbar on the following letter, i.e. for the logical not):


^X = A + B + ^C + D
^Y = ^A^D(B + C) + AD^B



That gave me the code:


g = 28 |
((((((((~m)>>2)&((~m)<<1)&((~m)>>1))^1) &
(((~m)^2)&((~m)>>3))) |
((m>>3)&((~m)>>2)&m&1))^3)&3);


I am rather dissatisfied with this: surely it can be optimised someway, e.g. by doing simple observations like: no need to handle higher bit in logic since it needs just an exception (when m is 2); try to work in "positive logic"; mix ideas from the previous solution with the "gate logic" stuff... Anyway, for now it is enough, I have to go and do better things: I have a button I must push.

2010-12-04

Bye bye TM250

Maybe 1 post per month is a very low activity for a personal blog, should I be more chatty? Ok, let's say so: car broken, a lot of money to make it work again but this is not hard to handle. The thing that is hard to handle is to accept that my laptop is old, and it started to stop working. Well, not exactly. It's hard to accept the fact that it indeed works still well, except for a small detail that makes it unworking most of the time. If the diagnosis is right, it is about the BIOS EPROM... CPU is ok. Hard disk is ok (good! no data loss for now), LCD works, fan spins, some keys is a little bit deaf but not too much, and I have an external usb keyboard... RAM is ok (I went from 256M to 1G, remember?), gfx card is ok... everything's ok, but that little piece, which decided to fool me (if the diagnosis is right, again).

It happened one day when instead of seeing the Acer logo screen, and then the Grub boot loader, a long annoying beep followed by two short beeps greeted me... What's up? A lot of BIOS says graphics card problems this way. But a deeper seek made me informed about the fact that 1L-2S is (should be!) a problem in the flash of the BIOS... Likely.

Somewhere I've found a solution: reflashing the ROM, twice or three times to be "safer", and everything should go... Not so for me (or this was not the problem...?) When luckly the PC started, after 20 or so attempt, I tried the procedure. It seemed ok for a while: turned off, restarted (after minutes), and it was ok. Hurrah... but then I waited longer and the problem showed itself again.

This time it took longer before a turn-on attempt was successful. Reflashed (using provided software) the Phoenix BIOS 1.15, ten times or so, but likely this won't solve... Now I am using the laptop, since I only rebooted between MS Windows and Ubuntu, never turned it off (yet...). And it's all ok. I know tomorrow it won't boot, I will try and try, and at some point I'll give up. And I will decide to buy a brand new laptop... In italian there's the slang local verb "rosicare"; it should exist a synonym I can then translate into english, but in this moment it comes not into my mind... it is the feeling you can taste e.g. when you are so close to a goal and then, suddenly, a small stupid detail goes wrong and you lose the goal.

My pre-euro-era laptop still works... except for that stupid detail that if fixed would make this piece of hardware last for many years still ... one year would be enough for me!

Useful post, isn't it?