Motorbike vs. Car

dAVE is complaining that all I write are boring technical articles, without any human touch. So the folowing is an experiment in blogging about “human” issues. Wish me luck…

Sunday night I were coming home, and noticed that the corner of Bronson and Gladstone was blocked off – in some directions a block away. Being curious, I wandered out there, and saw half the intersection closed off by “Do Not Cross” tape, lots of police, a car stopped half way through, and a motorcycle laying on it’s side.

From chatting with the bystanders, I learned the following:
A woman driver, going from west to east on Gladstone run a red light, and was hit by a motorbike going south to north on Bronson.
Bike rider was supposedly alive when he was taken to the hospital by an ambulance, but his right knee was totalled by a bike falling onto it.

In Soviet Russia bikes had roll cages. Even motorollers had leg protection. Statistics are against bikers – biker will fall at some point. However in North America bikes are considered to be a macho thing – people ride basically in shorts and tshirts, often without helmets.

I am as pro auto-darwination, as the next guy, however think of the police and ambulance workers that will have to scrape you off ashphalt – at least wear leather coat and pants, to keep the pieces together. Have roll cages – have you thought of the nurses? Do you know how bloody hard it is to bandage someone who has a smashed knee cup? Why make someone remember you with a curse, as you are moving on in the world?

*sigh*

As an aside, again, in Soviet Russia some bikers tended to wear really narrow thin knee high riding boots. They were a sort of indicator – during death body would relax, so quite often boots would fall off, no matter how tight fitting they were. In fact rescue/ambulance workers used that as an indicator to see if they should attempt to hospitalize a victim, or if they das alles tod.

(Above photos are licensed under licensed under the Creative Commons Attribution NonCommercial ShareAlike License v.2.5. If they make someone think before running a red light, I’ll be happy).

Shellscripts: Using ANSI colors or finding duplicate files in style

… or “ASCII stupid questions, get a stupid ANSI”….

I’ve been writing Evil Shell Scripts of Doom[tm] lately, got curious in highlighting parts of the output in different color.
As both Terminal.app and xterms in Apple shipped X11 support ANSI colors, it made sense to me.

There are excellent How to Change a Title of an Xterm and Bash Prompts HOWTOs out there, to which I’ll refere my gentle reader, and thus I will just paste some example code.

Bits that directly relate to ANSI color output are all the echo -e lines, with basic logic being that echo -ne “e[1;35m” turns ON purple color, and echo -ne “e[0;m” turns it off. Of course other numeric values will generate different colors, and colors will look different on different terminals. Please refere to HOWTOs above.

Please make sure that you BOTH understand what this does, and undertand that YOU are responsible for running this. If it breaks, you get to keep both pieces, and not cry in my shoulder. The following is copyright 2005 Stany, and is licensed under… *shrug* BSD 2 clause license, in hope that this will be useful to others

(This is just some internal code that in reality just externalizes a function out of a much larger script, however might be of use to others without revealing what exactly I were working on. Note that it will leave an md5sum.out file behind, and will generate a script called “killfile” to remove duplicate if they were detected. This script doesn’t do many sanity checks, as they were job of a larger script, and will barf if subdirectories are present and matched. )

#!/bin/bash
# Checks for duplicates.  Takes one argument (optional) of the file ending,
# eg: checkdupe.sh pdf
# $Id: checkdupe.sh,v 1.2 2005/09/06 06:56:11 stany Exp stany $
MD5SUM=/opt/gnu/bin/md5sum
BASENAME=`basename $0`

checkdupe()
{
for ii in *$1 ; do
        FILESUM=`$MD5SUM $ii | awk '{print $1}'`
        NUMFILES=`grep $FILESUM md5sum.out | wc -l`
        if [ $NUMFILES -gt 0 ]; then
                OTHERFILE=`grep $FILESUM md5sum.out | awk '{print $2}'`
                 echo -e "e[1;31m`date` $BASENAME: e[1;36m$ii e[1;32mis a duplicate of e[1;35m$OTHERFILE e[0;m"
                echo "rm $ii" >> killfile
        else
                $MD5SUM $ii >> md5sum.out
        fi
done
}

if [ -e killfile ] ; then
        rm killfile
fi

if [ -e md5sum.out ] ; then
        rm md5sum.out
fi
        touch md5sum.out

checkdupe $1

if [ -e killfile ] ; then
        echo -e "e[1;31m`date` $BASENAME: Duplicates found.  Run killfilee[0;m"
        echo -ne "e[1;35m"
        cat killfile
        echo -ne "e[0;m"

fi


Sample run:

stany@gilva:~[02:58 AM]$ mkdir test
stany@gilva:~[03:04 AM]$ cd test/
stany@gilva:~/test[03:04 AM]$ echo a >foo 
stany@gilva:~/test[03:04 AM]$ echo a >bar 
stany@gilva:~/test[03:04 AM]$ echo b > baz
stany@gilva:~/test[03:04 AM]$ ../checkdupe.sh 
Tue Sep  6 03:04:45 EDT 2005 checkdupe.sh: foo is a duplicate of bar 
Tue Sep  6 03:04:45 EDT 2005 checkdupe.sh: Duplicates found.  Run killfile
rm foo
stany@gilva:~/nature/test[03:04 AM]$ ls
bar             baz             foo             killfile        md5sum.out
stany@gilva:~/nature/test[03:04 AM]$ 

Oh, and checkdupe() can be trivially fixed so that it would take any shell expandable expression as an argument to the script, and work with that. I don’t even consider it an excercise 😛

MacOSX: Trimming fat from Mach-O fat files

MacOS X uses fat files.

A fat bundle contains data for different architectures. Here are some examples:

root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:03 AM]# file *
Terminal: Mach-O fat file with 2 architectures
Terminal (for architecture i386):       Mach-O executable i386
Terminal (for architecture ppc):        Mach-O executable ppc
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:03 AM]# 

or even:

stany@gilva:/System/Library/Frameworks/Accelerate.framework/Versions/A[02:07 AM]$ file Accelerate 
Accelerate: Mach-O fat file with 3 architectures
Accelerate (for architecture i386):     Mach-O dynamically linked shared library i386
Accelerate (for architecture ppc):      Mach-O dynamically linked shared library ppc
Accelerate (for architecture ppc64):    Mach-O 64-bit dynamically linked shared library ppc64
stany@gilva:/System/Library/Frameworks/Accelerate.framework/Versions/A[02:07 AM]$ 

In order to operate on fat bundles Apple provides a utility called lipo.

If you are in a situation where you are limited by processor architecture – for example, if you never expect to use internal hard drive of your iBook in firewire target mode to boot up an i386 system – it is possible to remove the extra “fat” from fat binaries, to save some disk space.

Here is an example:

root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:09 AM]# mv Terminal Terminal.bak 
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# ls
Terminal.bak
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]#lipo Terminal.bak -remove i386 -output Terminal
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# ls -la 
total 2296
drwxrwxr-x   4 root  admin     136 Sep  6 02:10 .
drwxrwxr-x   7 root  admin     238 Aug 31 00:07 ..
-rwxr-xr-x   1 root  admin  386472 Sep  6 02:10 Terminal
-rwxrwxr-x   1 root  admin  783784 May 14 22:22 Terminal.bak
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# file *
Terminal:     Mach-O fat file with 1 architecture
Terminal (for architecture ppc):        Mach-O executable ppc
Terminal.bak: Mach-O fat file with 2 architectures
Terminal.bak (for architecture i386):   Mach-O executable i386
Terminal.bak (for architecture ppc):    Mach-O executable ppc
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]#

A quick test confirms that Terminal.app continues to run as before, however to make sure that everything is kosher I would probably want to correct permissions on the new binary to match what it was on the original.

Disk space saving will not be big, as an average .app consists of many other objects besides the executable itself, so this is probably not a very big issue. If one tries to remove a non-existing architecture from a binary, lipo will complain:

root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:18 AM]# 
lipo Terminal.bak -remove ppc64 -output Terminal
lipo: -remove ppc64 specified but fat file: Terminal.bak does not contain that architecture
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:19 AM]#

Another interesting option to lipo is -detailed_info:

stany@gilva:~[02:22 AM]$ lipo -detailed_info /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate 
Fat header in: /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate
fat_magic 0xcafebabe
nfat_arch 3
architecture i386
    cputype CPU_TYPE_I386
    cpusubtype CPU_SUBTYPE_I386_ALL
    offset 4096
    size 8488
    align 2^12 (4096)
architecture ppc
    cputype CPU_TYPE_POWERPC
    cpusubtype CPU_SUBTYPE_POWERPC_ALL
    offset 16384
    size 8564
    align 2^12 (4096)
architecture ppc64
    cputype CPU_TYPE_POWERPC64
    cpusubtype CPU_SUBTYPE_POWERPC_ALL
    offset 28672
    size 8488
    align 2^12 (4096)
stany@gilva:~[02:22 AM]$ 

writing a script that processes the output of:

 find . -type f  -perm -55 -exec file {} ; | grep i386 | sed 's/.for arch.*$//g'

while stripping out the arch, AND not screwing up the system is left as an excercise for the reader. 😛

Rendering a manpage

This is more of a general unix hint, that is not really MacOS X specific.

If you have a manpage that you want to look at, that is not in $MANPATH, (Something that got installed by hand into a custom directory, for example something that was built and installed using
./configure –prefix=/opt/packagename && make install ), yet you know where it is (for example because you did run /usr/libexec/locate.updatedb as root at least once since and now can use locate), you can use nroff to render the man page into text:

stany@gilva:~[12:06 AM]$ ls -la /opt/gnu/man/man6/figlet.6 
-r--r--r--   1 root  501  21054 Sep  3 17:41 /opt/gnu/man/man6/figlet.6
stany@gilva:~[12:06 AM]$ nroff -man /opt/gnu/man/man6/figlet.6 | head -20
FIGLET(6)                                                            FIGLET(6)



NAME
       FIGlet - display large characters made up of ordinary screen characters


SYNOPSIS
       figlet [ -cklnoprstvxDELNRSWX ] [ -d fontdirectory ]
              [ -f fontfile ] [ -m layoutmode ]
              [ -w outputwidth ] [ -C controlfile ]
              [ -I infocode ] [ message ]


DESCRIPTION
       FIGlet prints its input using  large  characters  (called  ``FIGcharac-
       ters'')made  up  of  ordinary  screen  characters (called ``sub-charac-
       ters'').  FIGlet output is generally reminiscent of the sort of  ``sig-
       natures''  many people like to put at the end of e-mail and UseNet mes-
stany@gilva:~[12:06 AM]$ 

Kermit the Blog: That’ll be… Aw, heck. No charge.

Over on the Kermit the Blog he’s having one of those days. Another friend gets free computer help, and now he’s wondering if he’s too nice or just a sucker.
Kermit the Blog: That’ll be… Aw, heck. No charge.

My take:

One of my clients, who runs a very successful jewellry business, explained it to me: When you charge little or nothing then there is no associated value. Which means there is no way to compare what you are really giving them to anything else they are familiar with.

So the next time you get a call to a ‘family or a friend’s’ house to fix something, interrupt them and tell them up front: “I am no longer able to help you for free. $$$ an hour, minimum one hour. When should I come by to fix things?”

Then things get really interesting! 😉

As he says “What’s your take?”

Turning a man page into a PDF

In the end of a series of comments on Mike Harris’s article about Remind:

[minor edits by davidr]


#!/bin/sh

manpage to PDF generator

2004-08-02, Christopher Hansen

http://emilyandchristopher.com/

Usage: pdfman command

Creates command.pdf in current directory.

mandoc=/usr/bin/env man -w $1
grcmd=/usr/bin/env grog $mandoc
/usr/bin/env $grcmd | ps2pdf - > $1.pdf

To use it, select and copy the previous 11 lines. Then type the following into a Terminal window:

pbpaste > pdfman
chmod +x pdfman
cp pdfman ~/bin/

Now, if you type “pdfman remind” in a Terminal window, you’ll end up with a file called remind.pdf.

43 Folders Mike Harris looks at Remind

Thanks Christopher!

The Case for PowerPC based Amiga Hardware

My friend Michael got his article published …

His perspective on why the new Amiga hardware is based on the PowerPC chips instead of Intel.

“Synopsis:
The economic well being of the Amiga market demands a system that is not in direct competition with the Wintel world. Running on Intel hardware will jeopardise the viability of OS4 by placing it into direct competition with Windows. Intel derived hardware raises issues of support costs and financial return for the vendor.”

The Case for PowerPC

QuickTime (Part 3)

Background

I have an iBook G4, that has a 32 meg Radeon 9200 mobile video card, that is below the minimal requirements for CoreImage. Technically CoreImage is supposed to be scalable, and if it can’t do a particular efffect on the video card GPU, it should try doing it on AltiVec unit of the processor, and, in event that the system lacks an AltiVec unit, it should fall back to the CPU.

In reality lack of CoreImage support doesn’t cramp one’s style all that much. I miss some graphical features of the GUI, which is cosmetics. However, occasionally it interferes with productivity, and pisses me off.

Consider the following example:

QuickTime 7 Pro and video adjustments

QuickTime have been coming in “free” and “pro” variety for a long while. The features that 29.95 USD Pro version has are numerous, but amongst the most notorious are:

  • ability to save some of the streamed media to hard drive
  • ability to export files to different formats
  • ability to do some rudimentary merging of video tracks using cut and paste
  • ability to adjust brightness, tint, contrast and colors of the video
  • ability to correct audio balance, etc.

All of the above features work reasonably well under QuickTime Pro 6.5.2, although color corrections are rather clunky and are represented as a slider on screen. However you can see the adjustments as the movie plays. Here is what it looks like (220K).

Tiger came with QuickTime 7, and once I entered the QT7Pro license key, one of the things that didn’t work on my iBook was color corrections. Apple-K presented me with options to modify the audio settings, but not the video settings.

Technically you can get video adjustments to work by performing the following steps: Export -> Options -> Video Filter and doing a bunch of adjustments there, however there is no fun in waiting for a few minutes in order to see if your guesswork was correct.

This is Broken[TM].

So I did some digging. Inside QuickTime Player.app there are two files: AvControls.nib and AVcontrolsMinimal.nib. One gets used when the system detects CoreImage supported video card, and the other one when it doesn’t.

My hypothesis was that if I were to swap the two around, I’ll get access to video controls:

First I copied QuickTime Player to a different directory, and then dropped to command line:

stany@gilva:~[05:11 PM]$ cd /Applications/extras/QuickTime Player.app/Contents/Resources/English.lproj/
stany@gilva:/Applications/extras/QuickTime Player.app/Contents/Resources/English.lproj[05:11 PM]$ ls -dal AV*
drwxrwxr-x   5 root  admin  170 Jun  5 08:09 AVControls.nib
drwxrwxr-x   5 root  admin  170 Jun  5 08:09 AVControlsMinimal.nib
stany@gilva:/Applications/extras/QuickTime Player.app/Contents/Resources/English.lproj[05:11 PM]$ 
stany@gilva:/Applications/extras/QuickTime Player.app/Contents/Resources/English.lproj[05:14 PM]$ sudo /bin/bash
Password:
root@gilva:/Applications/QuickTime Player.app/Contents/Resources/English.lproj[05:14 PM]#  
mv AVControls.nib AVControls.nib_ && mv AVControlsMinimal.nib AVControls.nib && mv 
AVControls.nib_ AVControlsMinimal.nib
root@gilva:/Applications/QuickTime Player.app/Contents/Resources/English.lproj[05:14 PM]#

After adjustment, on a non-CoreImage enabled system Apple-K menu looked like this.

Sadly, under Tiger the sliders for video correction still do not work, as they are dependent on CoreImage. However, I wonder if they do work on Panther (10.3). If they do, then likely this is the solution that would work for folks who haven’t upgraded yet. You see, there might be a reason to be a struggler. Comments, please.

Lastly, I wanted to give my modified version of QuickTime Player.app a different version string, so that I could see it when I ctrl-click on the movie, and select “Open with”. In order to do that, I ctrl-clicked on the QuickTime Player.app, and selected “show package contents”. Inside Contents folder, I’ve opened version.plist and Info.plist in Property List Editor. In Info.plist Root, I’ve changed CFBundleGetInfoString so that I know it was changed by me when I get info on the application, CFBundleShortVersionString and CFBundleVersion both to 7.0.1-stany and saved Info.plist. In version.plist I’ve modified CFBundleShortVersionString and CFBundleVersion to match the changes I did in Info.plist, leaving the rest of the properties the same.

Now, If I ctrl-click on a file QT recognizes, and scroll to “Open with”, it looks like this.

Last paragraph is the usual step needed to change a version of any application as recognized by the operating system. I should probably do something like this to all of those pesky Real Players, that I’ve been dealing with.

In closing, inside Info.plist it’s also possible to adjust the filename extensions and the icons that QuickTime is supposed to be able to handle. So you can rename your .mp3 files to, say, .jd, and associate just QT with these files (Barring presence of resource fork, etc, of course).