More details to come…
The driveway project
Aug 17
So, being a very happy Apple customer it saddens me to no end, the problems I have with iTunes and having its database on my Apple Time Capsule (NAS).
Having a Macbook Pro I’m sorta limited on disk space so I don’t wanna have all my music and podcasts and iTunes University stuff (there’s some GREAT stuff on iTunes University, check it out, and it’s free!) on my Macbook disk so I thought “Well, why not just put it all on my Time Capsule, lots of space there, all Apple stuff too so it should work fine!”…. and there it began, my “no end of pain”.
I did the transfer of the data completely according to the book and I have everything the way Apple wants it (synch db, copy imports, manage names, etc) but the bastard just keeps mucking up the whole frikking time!!! 🙁
It looses the network connection for a moment and then suddenly iTunes decides that my whole library is GONE, “Wooops, better silently change the iTunes directory to the default Music folder”…. Unaware that iTunes made this clever move, I innocently want to sync my iPhone, because that is what we responsible users do, iTunes then goes… “Wow, he seems to have empty his whole library, and since we are sync’ed I’d better wipe his whole iPhone without asking first”…. NO, NO, NO YOU BASTARD!!!
So painstakingly I put it all back, which takes hours, but then all my data that I have put in my Apps are…wait for it… wait for it…. GONE!!!! AAAARRRGGGHHH!!! THIS IS NOT HOW IT IS SUPPOSED TO BE!!!
Not only is there the above problem, additionally it starts adding any stuff to this “new” iTunes folder which it silently changed to which I have to fiddle over to the correct place later on when I realize what has happened. And every time I change back it has to “Check my iTunes library” which takes forever, THEN it asks me to “Update all the frikking songnames and whatever frikkin else” so it loops over all my stuff and “changes” it to the correct names, which I have already told it to do 70 times, so they bloody well should be correct by now… SIGH!
The best way I have found of preventing this STUPID silent moving of the iTunes folder is to create a write protected link in the Music folder to the correct place on my Time Capsule, then at least I find out about it and can prevent it from happening, then it usually reports something along the lines that my iTunes folder is write protected and gives up… HA!!! GOT YA!!! 😛
My latest hoe is that it hangs when i sync my iPhone, it does all its stuff and then when you figure it is finished, it just hangs on “Syncing iPhone”… buhuuuu!
Apple! Fix! Now! This is not funny anymore, it wasn’t even funny from the start and it is beneath you!!
A real Turing Machine
Apr 28
Isn’t this too cool!!??
I want one!
So, curious on the iPhone OS 4.0 I wanted to testrun it on my iPhone 3GS, downloaded the upgrade from Apple, “option clicked” restore and browsed to the “iPhone2,1_4.0_8A230m_Restore.ipsw” file and off we go…
Well I don’t know about this beta, it wasn’t very stable for sure, the worst problem being not able to read mail properly. Also all my contacts disappeared when I upgraded, not very impressive (my songs where still there though curiously enough). Weren’t too impressed with the multitasking, I ended up seeing “warning low memory” a couple of times and having to go in to the “task manager” and kill some apps, hopefully this is some we won’t see in the production version because then Apple is seriously going in the wrong direction!
Another thing that bothered me a bit, I have very frequently used the “home button double click” mapped to the iPod and that will likely disappear now with the “task manager” mapped to “home button double click”. Too bad, fortunately it seems to still work when the screen is locked…
Nevertheless, soon got tired of the bugginess and wanted to downgrade back down to 3.1.3… not soo easy it turns out…
First tried the normal “Restore procedure”, no luck, just got something along the lines of “Cannot download software” (no error code) and then it just referred me to this Apple page.
So then I tried the “option click” restore and choose the “iPhone2,1_3.1.3_7E18_Restore.ipsw” file, iTunes went off and fiddled around with the iPhone for a while, but ended up with
.
I fiddled around with various variants of this for a while trying both the 3.1.3 version and the 4.0 version but no luck.
What’s worse I had obviously ended up in what is called the “Apple Logo or Recovery Mode loop”, i.e it is now impossible to boot the phone it just keeps coming back to recovery mode and when plugged into iTunes, it will just ask you to restore and we have already concluded that didn’t work for me, so what now??
Found this and this page and combining the two did the magic. Like it says on the first page, it can take several tries before it works, for me it took two times before I finally managed to get it back to 3.1.3.
So, the inevitable finally happened to our old Windows HP Laptop, it crashed… We have been waiting for it to happen, it is, after all OLD, but I must say it has done a really good job hanging in there this long.
Yep, we have been making backups, but not as regularly as with the Mac and the excellent Time Machine of the simple reason that it is more of a hassle doing it under windows.
So, although most files where backuped there where still some missing. So what to do? The machine didn’t even boot so no way of getting in and copy files to a USB stick. Considered trying a repair with the Windows XP CD, but I don’t really trust them not to do stupid things so discounted that option.
Having done this stuff before I remember beeing really happy with the System Rescue CD (SRCD), I consider it to be, by far, the best in the category! This is one excellent package! Its a Linux Live CD with all the stuff you’ll ever need, including a really good website. So downloaded that and burnt it to a CD and stuffed it into the old HP.
Linux booted with no problem, next step is to find the hard drive:
fsarchiver probe simple
showed it to be: /dev/hda1 with an NTFS filesystem, this used to be an issue, but not anymore. So mounted the hard drive with: ntfs-3g -o ro /dev/hda1 /mnt/windows The /mnt/windows exists from the start so no need to create that directory, the “-o ro” option mounts it read only so we can’t misstakenly remove or change anything on the drive, that feels good in these situations.
Ok, so the machine is up and running and we have access to all the files on it, good. My plan now was to backup the files and then try to reinstall Windows. So how to backup the files? Initially I figured I’d copy them over the network using sftp which was the suggested approach on the System Rescue CD website. So I got the network up and running by connecting a network cable and issuing dhclient eth0. No problem. ifconfig showed that the network was up and running and the ip-address I got. OpenSSH is already up and running on the crashed machine so I started cyberduck on my Mac and used sftp to connect to the crashed machine.
I then started copying the files I wanted, but unfortunately it would take about 13 hours. I didn’t really file like waiting that long, so in parallel I started looking for a USB drive. I found an old one with 220 GB free and connected that to the crashed machine. USB is of course supported by SRCD, so again, I ran fsarchiver probe simple to find the USB drive, it showed up as /dev/sda1 with a vfat filesystem on it.
So mounted that one with mount -t vfat /dev/sda1 /mnt/backup again the /mnt/backup already existed so no need to create that either.
Now I got a small issue, since normal users don’t really know (and shouldn’t need to know either) alot about filesystems they are blissfully unaware of the issues that can occur when you create files with the swedish characters “å”, “ä”, “ö” and the like in the filenames so they tend to do just that. Now when I tried to copy files and directories with the above mentioned swedish characters (“åäö”) in them I got some error along the lines of “Could not create file, Illegal argument ” and I suspected that the “åäö”‘s were the issue. It turns out that I needed to unmount the “/mnt/backup” and mount it with mount -t vfat -o iocharset=utf8 /dev/sda1 /mnt/backup instead, then it worked fine, I’m not sure why this was since it says that “iso8859-1” is the default which certainly is capable of representing “åäö”, but maybe it was due to how the USB drive had beed formatted or something.
Ok, so now we are capable of handling “åäö”, so it is time to start copying the files. Next question, what to use to copy the files…? This might sound like a silly question but anyone that has tried to copy large amount of files with windows explorer knows what kinds of problems you can have. For example a file somewhere in the middle of the copy process is broken or some other error occurs and the file copying stops dead in its track somewhere in the middle of everything and you have no idea what is copied or not and you basically have to try to find the offending file, remove it and start over, and again… and again… 😛
Now, there are a couple of options on Linux:
cp – The ordinary copy program
dd –
tar-
dar-
rsync- A very competent file sync program from the Samba team
I ended up using rsync mainly since “cp” doesn’t show any progress, tar, dar creates an archive which I didn’t really want, other than that I have very high confidence that rsync will “do the right thing”.
To use rsync to just do a simple copy and show progress I use the following command: rsync -avh --progress /mnt/windows/Documents\ and\ Settings/Tess ./ (I had already cd’d to /mnt/backup/). As you can see I copied the “Documents and Settings/
When all files where copied with rsync (40 GB) the sftp had managed to copy around 17% (6GB). Ok, so what’s next?
If I need to reinstall Windows, “My Documents” might be whiped, don’t want that, so while still running SRCD I moved everything in the “Documents and Settings/<username>/Mina Document/” folder to “c:/bak”, which is /mnt/windows/bak on the SRCD (the “bak” folder was not there so I created that first with mkdir /mnt/windows/bak.
Ok, after having secured the files I feel more confident starting to experiment with the machine. I then booted from a Windows XP Professional CD and chose the “Repair using the Recovery Console”. Then I tested the boot configuration with the command bootcfg /list it turns out that it is broken. “Dir” did not work either probably because the “Recovery Console” didn’t manage to find any “Windows Installation” to “log in” to. None of the “/rebuild”, “/scan”, “/add” options worked, so at this stage I wanted to delete the boot.ini file. I first had to make it deletable at all using the commands:
attrib -H C:\boot.ini
attrib -R C:\boot.ini
attrib -S C:\boot.ini
Now was able to delete the boot.ini, my first and so far only mistake, I should of course just have moved it to some other filename.
At this point I tried to boot the system in safe mode. And this time it actually managed to boot it using “Safe mode”, the first time since the crash. After rebooting it can now boot normally even though it prints a message that it cant find a boot and informs that it uses “c:\..something..windows..something”, pretty remarkable…
The final step was using the Windows XP (pro) CD to create a new boot.ini file. After this and a reboot it was again back to normal… let’s see how long it will make it!
Voddler does it again!
Apr 1
Jag hade bestämt mig för att inte ta upp det här men nu kan jag inte låta bli längre! Voddler har lyckats med konststycket att göra ett dåligt userinterface ännu sämre!
Tidigare kunde man styra eländet med tangentbordet, jag ska inte säja att det var snabbt och effektivt och en njutning på något sätt men det gick iallafall. Nu har man tagit bort den möjligheten, eller nästan, nu är det nån slags misslyckad blandning. Supersegt och konstigt. Har dom implementerat det i sirap eller?
När jag i början lyckades att få igång en film så var jag åtminstone ganska imponerad av dom som jobbade med streamingdelen, tyckte att det funkade hyfsat bra, men även det fick sig en törn häromveckan då vi hyrde Transformers. Filmen gick inte spela upp den för fem öre, det hackade och formatet på filmen var helt åt skogen. Efter en havtimmes fipplande och frustration gav vi upp, vi tittade aldrig klart på filmen, Voddler totalsabbade vår kväll. Tack för det, och dessutom fick man betala för det. BLÄ!!
Nåja, tebax till det sugiga userinterfacet. När man startat dyngan så är det svart… svart… svart… svart… svart… sådärja… sen måste man välja användare.. varför det, vi har bara en användare, varför bara inte “logga in” med den direkt. Om man har fler användare så sure, låt oss välja issåfall då. Efter det kommer det upp tre alternativ “Movies”, “Documentaries” och “Quit”…. Jaha…? Tidigare var dom i samma, varför krångla till det? “Documentaries” kan ju vara en genre helt enkelt.
Ok, man klickar på “Movies”… Nåt börjar ladda…ladda….ladda…ladda… Men vafan, laddar dom ner hela internet eller? Nej, det är inte mitt bredband… Vi snackar 18 iconer som dom ska ladda ner, men det verkar som dom laddar ner själva filmerna och cachar dom oxo… (I wish!) Klickar man på “Movies” -> “All” får man upp…. (drumroll) “No result”… Suck. Klickar man på “Premium” händer… … … … jusst det, ingenting!! Inser man efter ett tag för vid det här laget är man ju så van att vänta…
Sen har dom tydligen bara skitfilmer i sitt utbud för alla verkar ha betyg 1 stjärna, lite märkligt då jag själv har betygsatt åtminstone ett par filmer med 3’or. Fast det kanske inte är betyget på filmerna utan betyget på Voddler klienten. Inte för att Headweb är eoner bättre men det får nog bli det i fortsättningen. Trist, det hade varit trevligt att köra en tjänst utan att behöva använda browsern som ui.
(Det är Mac klienten som diskuteras, man kan ju hoppas att PC klienten är bättre…)
Ok, this is sooo cool! 🙂 For us who love Perl and often have the feeling of “If I could just filter this emacs buffer through Perl, how happy I would be!” here’s a tip:
Step 1: Mark the buffer (or the parts of it that you are interested on running through Perl).
Step 2: Type M+| (“Escape” + “|” (vertical bar) on your normal keyboard) or
Step 2 (alt): Issue the “shell-command-on-region” elisp function
Step 3: Enter your perl magic, for instance ‘perl -ne “print if /gnu/”‘ to remove all lines which does not match “gnu”
Step 4: Be amazed!
Now, the result will end up in the minibuffer if it can fit on one line, otherwise a new “shell command output buffer” will be created and hold your stuff.
I often find myself wanting to pass a regex as and argument to some function or another with the initial idea of passing the regex either as a string or a compiled regex (see the qr operator) and I invariably end up with problems. One example is for instance when I pass it as a string I mess up quoting ? / * . etc..
Another example of problems with this approach is the following, imagine that you have written a function to take a regex and you imagine searching all cells in an Excel sheet for cells matching this regex, as follows:
sub find_in_worksheet {
my $regex = shift;
my $workbook = shift;
my $worksheet_name = shift;
my $worksheet = $workbook->worksheet($worksheet_name);
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
if( $cell->unformatted() =~ $regex ) {
return ($row, $col);
}
}
}
return undef;
}
That works fine, until inevetably you want the cell contents NOT to match the regex… *sigh*, what now…?
Well it turns out that a much more fruitful (and a more general) approach is as follows:
sub find_in_worksheet {
my $predicate = shift;
my $workbook = shift;
my $worksheet_name = shift;
my $worksheet = $workbook->worksheet($worksheet_name);
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
for my $row ( $row_min .. $row_max ) {
for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
if( $predicate->($cell->unformatted()) ) {
return ($row, $col);
}
}
}
return undef;
}
You would call this functions as follows:
my ($row, $col) = find_in_worksheet( sub { $_[0] =~ /regex to match cell contents/ } , $workbook, $worksheetname);
See the “sub { $_[0] =~ /regex to match cell contents/ }” part? There’s the magic. Now if you later on figure out that you want the cell contents NOT to match, you just call the method thusly:
my ($row, $col) = find_in_worksheet( sub { $_[0] !~ /regex to match cell contents/ } , $workbook, $worksheetname);
Volá!
Now you can even change the code for the predicate to something completely different, maybe not even involving regexes… for instance:
my ($row, $col) = find_in_worksheet( sub { $_[0] == 10 } , $workbook, $worksheetname);
This is just a small example of the power of using “sub’s” as arguments to functions and the very nice syntax in Perl for achieveing it. It also carries the benefit of giving you compile time checking of your regex! (Yes, Perl is a compiled language!)
Perl date difference
Feb 24
As a followup on date calculations, here’s small one to calculate the number of days between two dates, the same disclamer as for the previous post applies, so, without further ado, here goes:
# Given two dates, calculate the number of days between them
sub diff_dates {
my ($sec1,$min1,$hour1,$mday1,$mon1,$year1) = @_[0..5];
my ($sec2,$min2,$hour2,$mday2,$mon2,$year2) = @_[6..11];
my $time1 = timegm($sec1,$min1,$hour1,$mday1,$mon1,$year1);
my $time2 = timegm($sec2,$min2,$hour2,$mday2,$mon2,$year2);
my $diff_seconds = $time1 - $time2;
my $daydiff = $diff_seconds / 24 / 3600;
return int( $daydiff );
}

