How to Play Tetris, Pong and Other Hidden Games on Your Mac

"Did you know that you can play Tetris on your Mac? Of course you did, you can play lots of games. But did you know that there’s already a Tetris game built in? In fact, if you know your way around Emacs, you can play a whole bunch of awesome retro games like pong and snake."

Actually macosxhints.com had an article about this years before "the media" picked up on the topic. Smile But obviously this has been around even longer. Wink

Various reasons for the failure of an umount command

An umount command usually fails with the following message:
umount: /mnt/test: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

The referenced blog post lists most reasons for an umount to fail. The use of lsof and fuser is quite common knowledge. However the use of the -v option with lsof is not. Eg. if you try to umount an NFS exported directory and run lsof and fuser, both will produce nothing. But the umount still fails. If you run fuser with the -v option, it'll point out the culprit, namely the kernel's NFS code holding locks on the given partition (as explained here):
# fuser -v -m /mnt/test
                      USER        PID ACCESS COMMAND
/mnt/test:            root     kernel mount /mnt/test

animate.css - "plug&play" CSS3 animations

"animate.css is a bunch of cool, fun, and cross-browser animations for you to use in your projects. Great for emphasis, home pages, sliders, and general just-add-water-awesomeness."

ext4 partition size / free space discrepancies

Up til now I thought that large discrepancies between the total size of a filesystem and the free space reported by the operating system is due to the reserved blocks. But as it turns out, there's another space hog: the inode table.

How to export the list of apps from Google Play (Store)

It's quite simple. When you visit the "My Android Apps" page in the Play Store, one of the loaded URLs (https://play.google.com/xhr/myappslibrary?device=somealphanumericstring) contains the HTML code of the "Apps installed on ..." and "Other apps in my library" sections. It's a JSON formatted record and has an "installedAppsHtml" and a "notInstalledAppsHtml" element with the respective HTML codes.

How do I get a list of the packages that "provide" something (using dpkg or APT)

If you run apt-cache showpkg on a meta package, the "Reverse Provides" section will list all of the available packages that fulfill the given role. Using awk you can easily print out the list of packages that provide the given meta package.
Eg.
$ apt-cache showpkg telnet-client | awk '{if (f==1) print $1}/^Reverse Provides:/{f=1}' | sort
heimdal-clients
inetutils-telnet
krb5-clients
telnet
telnet-ssl

ACL permission mask problems on linux

Using ACLs on linux can be confusing at times. Setting ACL permissions is quite straightforward (using the setfacl commandline utility), but you might find that your permissions are not always honored. The culprit behind this is the mask.

How to compare two images pixel by pixel

The task might seem trivial, but I can assure you it's not. Smile Every image manipulation program handles file formats a little differently, so if you take an image file (let's assume it uses a lossless format, eg. PNG) and simply save/export it with two different programs, but using the same (lossless) format, the two resulting files will be most probably different in size (and obviously in content too). The question is: how do you know whether the two images are the same or not? The size of the two files can differ for a number of reasons and not just because of the difference of the image data. Eg. modern file formats allow a lot of metadata to be stored with the image. Some file formats allow the use of more than one compression algorithms (eg. TIFF files can use a number of -lossless- compression algorithms).

How to compile ffmpeg (with support for most of the popular codecs) for Mac OS X

OSX Expert's guide on how to compile ffmpeg for the Mac is pretty detailed and a huge help. However since it was written some time ago, quite a few things changed. This post provides an -at the moment- up-to-date version of OSX Expert's instructions. I still use a Snow Leopard (10.6.8) with Xcode 4.2, so small adjustments might be necessary for more recent Mac OS X and/or Xcode versions.

Using sed with curl to grab the filename from the Content-Disposition header

The answer to the Stackoverflow question sounds like this:
Do two requests: a HEAD to get the file name from response header, then a GET:
url="http://www.vim.org/scripts/download_script.php?src_id=10872"
filename="$(curl -sI  "$url" | grep -o -E 'filename=.*$' | sed -e 's/filename=//')"
curl -o "$filename" -L "$url"

It assumes a pretty simple format for the Content-Disposition header, which is most of the time not true. Meanwhile curl has a new option called --remote-header-name (or just -J), which does exactly what we intend ... ie. takes the filename for the --remote-name option from the Content-Disposition header. Actually even this option of curl was flawed at some point. So to be sure you might take the matter into your own hands and use a proper sed command to fetch the filename from the Content-Disposition line:
url="http://www.vim.org/scripts/download_script.php?src_id=10872"
filename="$(curl -sIL "$url" | sed -r -e 's/^ *Content-Disposition[ \t]*:[ \t]*[^ \t;]+;[ \t]*filename[ \t]*=[ \t]*("(([^"]|\")*)".*|([^; \t\r"]+)(([^;\r]*[^; \t\r]+)*)[ \t]*(;.*|[\r]?)$)/\2\4\5/' -e 't' -e 'd')"
[ -n "$filename" ] && curl -o "$filename" -L "$url" || curl -OL "$url"

You might have noticed that my regular expression allows for some irregularities in the Content-Disposition header (eg. HTTP headers should not start with a whitespace ... unless it's a folded header which started in a previous line). That's totally intentional.

Syndicate content Syndicate content