Avian Bone Syndrome

An exercise in futility by Daniele Nicolucci

And so our story begins…

No Comments »

Earlier today, I joined the iOS Developer Program. After paying my entry fee and patiently waiting for about an hour for the meticulous Apple Robots to type an e-mail, I am now a registered iOS Developer, ready to attack, besiege, seize and conquer the App Store. I am currently targeting iPhone/iPod Touch only, reserving plans to expand to iPad land for later, after feeling the waters.
Stay tuned for updates. I plan to start writing on this blog again soon.

And so our story begins…

Pictures from the partial solar eclipse, Jan 4 2011

No Comments »

This morning, a partial solar eclipse was visible throughout Europe. I took some pictures, and posted them.
Click on the thumbnail to read more and view it in full resolution:
Partial solar eclipse of Jan 4, 2011 from Central Italy + sunspot

Flickr is the best place to showcase your photography, here’s why

No Comments »

After a long hiatus, a few months ago I started getting into photography again. The question immediately arose: how do I share my work?

Making a website from scratch was a no-go: too much work, too little motivation.

A CMS, such as Coppermine? Not really, I have used several in the past and they felt clunkier. Plus, a personal website is very slow to gain any traction, if it ever does.

I considered going back to my first love, Pbase, only to feel as if I were walking through Pripyat.

Two options remained: DeviantArt and Flickr. I wasn’t too keen on either, given the previous impressions I had had from both. In any case, since I already had basic accounts on both, I went ahead.

Read the rest of this entry »

Printing in grayscale with AirPrint

5 Comments »

Did you all think I was dead? Unfortunately for you, I am not. I’ve just been fairly busy with work and with my renewed interest in photography. Speaking of which, all of you should follow my Flickr photostream, which I update daily.

So, you’ve got the shiny new iOS 4.2 on your iPhone 4 and you have enabled AirPrint sharing on your Mac, using either the free Hacktivator or one of the commercial packages. You are very satisfied (albeit a bit doubtful about actually using it in the future), except for one thing: it prints in color, and you really wish it could print in grayscale, because toner is not cheap.

Read the rest of this entry »

How to use resizeTo in Safari (if it doesn’t work)

No Comments »

Many people are probably familiar with the fact that most browsers allow Javascript code to be entered in the address field. That’s the magic behind bookmarklets, which simply spare the user the hassle of manually typing long, convoluted and obfuscated Javascript statements.

While it’s usually pointless to do so, there is one case in which it makes perfect sense: resizing the browser window to an arbitrary size, in order to test what a website looks like. Essentially, by setting the browser window to a size such as 1024 x 768, one can have a relatively reliable idea of what the current website would look at that screen resolution. In truth, one would have to take the graphical elements of the operating system in question, but it’s usually a fine way to get an idea.

The code to do so is very simple:
window.resizeTo(width, height);

Therefore, if we want to set the window to 1024 x 768 pixels, we type the following pseudo-address:
javascript:window.resizeTo(1024, 768);

and press enter. A few things worth noting:

  • Capitalization is important. It is resizeTo, with a lowercase “r” and a capital “T”
  • There is no space, nor any slash, after the colon
  • The width and height have to be separated with a comma, and (of course) have to be integers
  • The semicolon at the end is optional, but if you’re a programmer it will be natural to type it
  • In some browsers, you can omit the “window.” part, as the current window is implied

This is all good and great, and works in most browser.

Safari, however, only allows this intermittently. Since I spent some time making tests to figure it out, here is a tip: Safari will execute resizeTo only when there is one (and only one) tab in the window.

I’m not sure whether this is caused by a specific setting on my machines, or if it’s a default, or if it can be even changed, but I can see the point in this behavior. Since some websites have the bad habit of resizing the current window to full screen (an annoying and pointless habit, if you ask me), Safari blocks the execution of such command in order not to disrupt the concurrent navigation of different websites/pages.

It’s as if it said: “if this is your own window, do what you want with it; if not, you’ll have to respect your tab brothers.”

So, if resizeTo isn’t working for you, drag that tab out of the bar so it’s instantly opened in its own window, and try again.

Manual duplex printing on a laser printer

2 Comments »

My laser printer, a Samsung CLX-3175, does not have any tool for automatic duplex printing. Achieving such result manually is not difficult, but may take some trial and error in order to get the settings right. That’s exactly what I’ve done, and I’m writing this post as a note to myself. Should it be useful to anybody else, however, by all means let me know with a comment.

Keep in mind that this is for my own printer, and that I use OS X 10.6 “Snow Leopard.” Results may vary with different printers and/or operating systems, so make your own tests. If your printer outputs pages “face down,” this will probably work as it is. Most ink-jet printers on the other hand output prints “face up,” so some adjustments will be necessary.

In any case the steps for my own printer are very, very easy (once you’ve figured them out correctly):

  1. Print all odd pages in normal order
  2. If the total number of pages is an odd number, take the last sheet and put it away for the time being
  3. Take the (remaining) sheets and put them back into the tray after rotating them 180°. Do not flip them in any way!
  4. Print all even pages in reverse order
  5. If you put the last sheet away in step 2, put it back at the end of the stack
  6. There is no step 6

Enjoy. :)

Prettifying URLs with fake subdirectories using mod_rewrite

No Comments »

Lately, I have been trying to define a common basis for most of my web projects, since I often end up reinventing the wheel every time. I have tried a few PHP frameworks, but none of them tickled my fancy, but I have complicated tastes. I am known for reimplementing something from scratch rather than wasting time adapting other people’s code to my needs, and it’s often much faster too.

Therefore I have been working on JBFW, my very own PHP/Javascript framework. One of the key components of it is pretty URLS and a centralized index.php to handle most of the things.

If you access http://mysite.com/news?lang=en, the server will transparently route that to http://mysite.com/index.php?pagename=news&lang=en. At that point, index.php runs the news module if it’s present, and then loads the news template (possibly showing the result of what was done in the module, if it was called at all.) I find that it’s a very slick and modular way of handling things, as static pages only need new templates and boom, they are live, with the rest of the framework readily accessible.

The mod_rewrite configuration for such a behavior is as follows:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?pagename=$1&%{QUERY_STRING}

This means: if the requested filename is not a directory and is not a file, route the request as described (knowing something about regular expressions, or being proficient in creative swearing — which goes hand in hand with regexp — comes in very handy at this point.)

I used a similar, but coarser, approach on my own main website, http://www.nicolucci.eu. There, I even used fake subdirectories, so that http://www.nicolucci.eu/photography/book/glimpses will have it show the photography-book-glimpses template. Neat, but doesn’t work with real subdirectories. It’s not a big problem on that site, but when you need to have a separate administration section, you need real subdirectories. The problem is that, using the approach I described above, http://mysite.com/admin/login into http://mysite.com/index.php?pagename=admin/login, and while the correct function could be run in PHP by mangling the request as it’s done for the “top level” modules, it could quickly turn into a nightmare.

The solution is to add another set of mod_rewrite rules, as follows:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((.*)/)+(.*)$ /$2/index.php?pagename=$3&%{QUERY_STRING} [L]

Yes, that’s incredibly messy, and I’m pretty sure that there is a better way to do it. However it works, and for now I’m going to concentrate on finishing the website and go back to it later. What this does is: if the request has one or more blocks ending wish a slash (the directory), followed by something else (the file name), it is routed to index.php inside that directory, using the file name as a parameter to pagename, plus the original query string as usual. The [L] at the end tells mod_rewrite: please refrain from doing any other change, this is flaky enough. This ensures that http://mysite.com/admin/login effectively calls http://mysite.com/admin/index.php?pagename=login.

Note that this is another block of RewriteCond and RewriteRule, and goes before the original one. I tried to put them together, since the conditions are the same, but after fifteen minutes of trying all combinations I gave up. I’m sure I was one attempt away from getting it right.

A very clever thing (ok I’m kidding, it’s a side effect I hadn’t fully realized but I’m glad it’s there) is that addresses such as img/logo.png are not rewritten because those files do exist. It would probably make sense to exclude common file extensions, such as image files and javascript, from this kind of mangling; or even better, make it only work when the “file name” part does not have a dot in it. I’ll find a way to do it, at some point.

To finish up, an extra little trick that can come in very handy when you want to make sure that certain files are not downloadable by anybody:

<Files ~ "\.sqlite3$">
Order Allow,Deny
Deny From All
</Files>

Make sure that there are no spaces on either side of the comma in the first line. I was quite frustrated because I kept getting the infamous error 500, and there it was.

I hope this spares someone from wasting as much time as I did with this kind of thing!

Fix broken IMAP attachments in Mail.app

No Comments »

I have recently started getting broken images in Mail.app. Often, when someone sent me relatively big pictures (over 1 MB in size), the image ended up being corrupted, with a smaller file size that one would expect. This results in a picture that’s visible up to a certain point, and then rest is usually filled with solid grey by the viewer.

While this could happen because the attached image is indeed broken — that is, if the sender is attaching an image that’s already corrupted on his/her machine —, it’s unlikely that the file gets mangled during the transit. To begin with, the base64 encoding adds lots of CRC (1/3 of the file size, and this alone explains why it’s a very bad idea to send big files through e-mail). In addition to that, no MTA will accept a malformed message: MIME parts must be completed with an extra boundary marker, and the infamous dot on its own line has to be there to commit the DATA part. Using a webmail system makes it even more difficult to corrupt a file in transit, because there is the extra uploading step that ensures that the attachment reaches the server before the message is constructed and finally sent.

If none of this makes sense and you want to know more, please refer to RFC 2821, but the point is that it’s virtually impossible for several people to send corrupted images. It’s way more likely that the problem lies within the recipient’s client.

With OS X’s Mail.app, these problems happen when there is some communication failure during the download of the message. Essentially, if the download gets interrupted for any reason, Mail.app may be unable to notice and will be perfectly happy with the broken file. There are two ways to fix this:

  • The hard way: go to ~/Library/Mail, and for each INBOX you may have, delete anything inside the Attachment folder
  • The easy way: select your Inbox folder within Mail.app and simply run Mailbox → Rebuild

That should take care of the problem. Note that the Rebuild procedure will redownload every message from the server again with all the attachments, essentially resynchronizeing the local cache with whatever is on the server, fixing any discrepancies. It may take some time, but you can keep an eye on the progress by opening the Activity window (Window → Activity, or ⌘0.)

iPhone 3G comes back to life after installing iOS 4.1

No Comments »

As I had predicted, Apple introduced iOS 4.1 at the iPod event last Wednesday. It is officially scheduled for release on September 9th, but there are ways to download the Gold Master that was seeded to the members of the Apple Developer Program. I am not one — not yet, anyway — but I couldn’t take it anymore.

The installation was extremely simple, with no remote activation or anything like that. This is because the GM is essentially the very same that will be pushed to the masses in a week. I simply pressed the option key while clicking on ‘update’ in iTunes and I got a dialog window to choose the .ipsw file from the disk. After that, it took its sweet updating time and lo and behold, my two-year-old device was running the latest incarnation of iOS.

I am extremely pleased to report that my iPhone 3G has come back to life. After using it extensively, to the extent of purposefully opening all sorts of apps in rapid succession to make it crumble, it stood strong. I can assure you that this is not placebo: it’s pleasant to use again. Most importantly, it doesn’t randomly freeze for a random amount of time in a random fashion in random apps. Sometimes it does take its time when the lock screen comes up (perhaps it does some cleaning when it automatically locks, and it reloads something?), but other than that, it’s completely different from 4.0.x.

Mind you, this is still a two-year-old phone and there have been two major revisions since it came out, so do not expect The Flash in your iPhone (hey! that’s a geeky double-entendre! neat!), but it’s definitely a major improvement. One disappointment stands, though: 3G units just don’t have the hardware to run the Epic Citadel demo, but — once again — is anybody really surprised by that?

The real irony is that my iPhone 3G was such a pain to use in the past couple of months (especially with the annoying freezes) that I honestly can’t even say whether 4.1 makes it as fast as 3.1.2, or if it’s still slower than that. All I know is that it’s faster than 4.0.2, and that’s all I care about.

Twitter’s RSS feeds are broken, and will stay broken

8 Comments »

What happens when Twitter switches from basic authentication to OAuth? Clients that relied on the former will stop working, until an update comes to add support for the latter. This has been called the OAuthocalipse and aside from minor glitches with some programs, it happened without much of a problem, much like the infamous millennium bug (ah, those were the good times: free Kevin!)

One of the lesser used functions of Twitter has been brutally smashed by the switch to the safer authentication method, however, and in a way it’s quite ridiculous. I’m talking about RSS feeds that are — or should I say were — generated from the timelines and so on. It was probably not very used, given the plethora of dedicated Twitter client, but as a very basic user who is mostly in read mode, I really appreciated it. Of course, to get a feed of your own timeline you had to log in, and how do you do that? With basic HTTP authentication, of course. Not anymore.

Now, I’m sure that some RSS aggregators will implement OAuth. Whether the one I use will do that or not is still unknown. In any case, all of this is ridiculous for two reasons:

  1. RSS is strictly a read-only system, so adding an extra layer of complexity (in that it has to be implemented from scratch whereas basic authentication is handled by virtually all HTTP libraries and frameworks) takes time and ultimately money. The result is that many clients will be able to happily access all sorts of password-protected feeds except Twitter’s.
  2. Twitter still shows an RSS badge in most pages’ sidebar, and carries the appropriate meta tags in the <head> section to advertise the feeds to the browser. As if that were not enough, one’s own friends’ timeline (ie. the “main page” you see when you log in) has three alternate feeds: your timeline, your mentions and your favorites. Needless to say, none of them work. So why keep them up?

I’m not the only one with this problem. Commenter #8 on this post, Dan Lyke, says:

I’m now considering whether I want to bother keeping my Twitter presence at all. Sure, I could write a Twitter reader of some sort that changed things into RSS, or run an app just for Twitter, but in a few hours Twitter has gone from being a part of my usual work flow to a freakin’ hassle.

I feel exactly the same way, and to me Twitter wasn’t even “part of my usual workflow.” I seldom write and I just use it to get updates from very few users / companies. I guess I’ll check it much less now that I have to open up the page, as I have no intention of using yet another program just for that. When I have some time I’ll probably end up writing a thin wrapper around OAuth to get an RSS feed out of my timeline, but right now I’m not thrilled about this.