29 Nov 2007, 12:31pm
/dev/random
by

Comments Off

Remarkably Useful Shell Script

You want to find and delete all files or directories matching a specific name from a directory tree (in this case, .svn directories that shouldn’t be in the ‘exported’ version):

find . -name ".svn" -exec rm -rf {} \;

(Thanks to Zed Shaw, circuitously via dzone.com)

28 Nov 2007, 2:28pm
/dev/rails
by

5 comments

Google Map Markers in YM4R/GM

When using YM4R/GM, by Guilhem Vellut, in your Rails app chances are you’ll want to mark points on the map using custom icons. The means to do so is not readily apparent or straight-forward. I’ve found that this works well:

map = GMap.new( Constants::GM_DIV_ID, Constants::GM_NAME )

# Define the start and end icons
map.icon_global_init( GIcon.new( :image => "/images/google_maps/icong.png", :icon_size => GSize.new( 24,38 ), :icon_anchor => GPoint.new(12,38), :info_window_anchor => GPoint.new(9,2) ), "icon_start")
map.icon_global_init( GIcon.new( :image => "/images/google_maps/iconr.png", :icon_size => GSize.new( 24,38 ), :icon_anchor => GPoint.new(12,38), :info_window_anchor => GPoint.new(9,2) ), "icon_stop" )

icon_start = Variable.new("icon_start"); icon_stop = Variable.new("icon_stop")

if respond_to?( "start_lat" ) && respond_to?( "start_long" )
    map.center_zoom_init( [start_lat, start_long], Constants::GM_ZOOM )
    map.overlay_init( GMarker.new( [start_lat, start_long], { :icon => icon_start, :title => name + " start", :info_window => "start" } ) )
end

if respond_to?( "end_lat" ) && respond_to?( "end_long" )
   map.overlay_init( GMarker.new( [end_lat, end_long], { :icon => icon_stop, :title => name + " end", :info_window => "end" } ) )
end
26 Nov 2007, 11:13am
/dev/ruby
by

Comments Off

Ruby: Can a Function Know It’s Own Source File?

I got to wondering this weekend: can a function know about it’s own source file in Ruby? The reason I was wondering this is because I’ve found that when working on someone else’s Ruby source code the ease with which mixins can be made sometimes leads to code that’s very difficult to trace.

Stack a few layers of inheritance together, stick some mixins into each level and then try and locate the original location of my_obj.coerce()… I tend to have to resort to TextMate’s global Find to search through the whole project (and woe is me if it contains multiple coerce() functions in different files). True story, that example.

What I’d like, and haven’t yet been able to discern a means to do, is either:

Kernel::source_file( my_obj.coerce )

or

my_obj.coerce.source_file()

or something along those lines which would spit back:

/var/src/my_proj/modules/coercion_functions.rb

Does this already exist? Am I missing something trivial?

22 Nov 2007, 6:20pm
/dev/random
by

Comments Off

Software Drag Racing

For some reason some people keep getting their knickers in a knot over Tim Bray’s Wide Finder fun:

There is a steady drumbeat of commentary along the lines of “WTF? This is a trivial I/O-bound hack you could do on the command line, ridiculously inappropriate for investigating issues of parallelism.” To which I say “Horseshit”. It’s an extremely mainstream, boring, unglamorous file-processing batch job.

To that I say “Horseshit”. Wide Finder is software drag racing at its finest: how fast can your code go this far? “Mainstream and boring” – that’s like telling a funny car racer their job is mainstream and boring because they just drive straight and then stop.

Take a look at some of the code being produced. Things of beauty they are, going from 1:43.71 for Tim’s first Ruby version to 1.51 seconds for the current perl leader.

“Ridiculously inappropriate” Who cares? Software development could use more fun and games like this.

22 Nov 2007, 2:33pm
/dev/random
by

30 comments

Leopard: This Kitty Has Rabies

Update 2007-11-30: PC Magazine has jumped into the fray with the op-ed piece Leopard is the New Vista, and It’s Pissing Me Off, noting:

Let’s see, Tiger crashed—oh yeah, NEVER. Ten months and I’m installing everything from production-level Office for the Mac 2004 to 0.x releases of VLC, Seashore, and Ecto—even betas of Firefox and Parallels. Whatever my nerdy little heart desires. I’ve had those early apps crash, but Tiger never faltered.

A month of using Leopard with the same software I had under Tiger and the OS has dumped six times. That’s six cold reboots for Oliver. Apple isn’t even honest enough to admit that Leopard is crashing: The OS just grays out my desktop and pops up a dialog box telling me I’ve got to reboot. Like the whole thing is my fault. I even snapped a picture of it. After all, I HAD PLENTY OF CHANCES!

I think there’s one big difference between Leopard and Vista: Apple has a chance in hell of fixing Leopard. Microsoft, I think not so much.

Update 2007-11-28: Seems the primary source of the Atheros airport driver death problem has been determined, according to Apple Insider:

The exact behavior of affected systems can vary slightly, but appears to largely be connected to the computer’s power supply. While the connection remains largely stable when plugged into an AC adapter, switching to battery power renders the wireless link intermittent and in many cases drops network access entirely when idle.

Amusingly, I proved confirmation of this myself moments ago when I accidentally knocked out the mag-safe connector and… my access died and then my machine kernel panic’d (the mag-safe connector remains one of my favourite laptop features of all time, honest).

——————–

After a month of using Leopard it saddens me to say that this is the first release of any Mac OS that makes me regret having installed it. I’d roll back to Tiger in a heartbeat if I could. If you haven’t updated yet and you’re on the fence I recommend waiting at least a couple more point releases before taking the plunge because this OS crashes, and when it goes, it goes hard.

Empirical evidence speaks louder than anecdotal so here’s the crash report windows for the latest four application deaths: Airport (the first two, from different crashes – a seemingly common occurrence), Front Row, Software Update and Transmit (you’ll note that three out of four of those are Apple apps).


airport_crash airport_crash2 frontrow_crash software_update_crash transmit_crash

The net result has been a whole lot of these, roughly once every two days:


os_crash

(Yes, all of these crash reports have been dutifully submitted to Apple.)

Ordinarily I’d be tempted to write it off as an isolated occurrence, perhaps something to do with this machine, but I see the same sorts of things happening on my iMac. Eventually it dies a hard, slow death the worst being the complete unresponsiveness of all applications.

Every now and then on launch an application will bounce for a long, long time and then fail to start though the icon appears in the Dock – evidently inhabiting some sort of semi-started purgatory. After that no applications can be quit or launched successfuly. I suspect this is the result of a failure within launchd somewhere but the net effect is that the OS becomes useless.

My gut impression is that Apple bit off more than it could chew with Leopard and made too many fundamental changes to the internals that haven’t been tested nearly enough. The things I really like about Leopard, like Spaces and Time Machine, are stand-alone applications at best and not fundamental improvements to the state of the art worthy of this grief.

The net result is a half-baked, rather unstable OS that I just cannot trust. My laptop and the iMac are now backed up to different external drive hourly by both Time Machine and SuperDuper!.

As such I’ve geared myself up to set aside a day next week to do a complete clean re-install of everything to see if that helps.

I cannot tell you how much it saddens me to be cursing the daily operations of my Mac as much as I would a PC.

Update:
Seems some commenters have some strong feelings about how it is in effect my fault these are happening so I thought I’d link to some other folks noticing these issues. Share the comment rage people, don’t waste it all on one blog.

100+ messages about the Atheros kernel panic situation.

Another thing I’ve noticed is that program stability in Leopard is definitely not up to what I’ve come to take for granted in Tiger, and I’ve had a more application crashes in two days than I’ve probably experienced in the past six months with Tiger. Some might dismiss this as less than optimum program optimization for Leopard, but that doesn’t explain the Finder locking up, and Pixelmator 1.0.2, another app. that has proven crash-prone in Leopard, was just released last week. And those aren’t the only ones that have crashed. I’m becoming a lot more re-acquainted with the Dreaded Spinning Beach Ball of Death than I ever wanted to be.
- Learning to Love Leopard

Anyway after this installation everything seemed fine and Apple had just released the 10.5.1 update. Then the lock ups started, intermittent keyboard lock ups, programs just stopped responding (force quit wouldn’t quit them), trying to mount DMG’s or extract zips failed with all manner of errors. Bizarrely enough a reboot resolved all of these- until they started to happen again. The my iDisk started to complain, by complain I mean I noticed it wasn’t doing what it should. Finally this was just one hard reboot too many for Leopard and I got a massive corruption of the drive – it would crash as soon as it tried to load the boot loader.
- Leopard – My painful experiences… So far

Fight!

19 Nov 2007, 10:51pm
/dev/random
by

1 comment

Parallels and Leopard: Rough Going Until an Update Arrives

Evidently some internals in Leopard changed that prevent the current version of Parallels Desktop for Mac from functioning completely properly. Failure tends to involve nasty kernel panics and, when Parallels does work, the Spinning Beachball of Death when one tries to quit.

Parallels support recommends this as a solution for the time being:

Hello,

Parallels allocates Virtual Machine’s RAM as one integral file. Consequently when your Mac’s RAM is too defragmentated (when too many applications are launched) then there could be not enough space in one sector for this file. And it causes this error when you are trying to start your virtual machine. But when you try to start it again – it may cause kernel panic or “grey screen of death”.

So the solution of your problem is following:
- Reboot your Mac, do not launch any applications except Parallels
- try to load Windows then
- You will need to decrease amount of virtual RAM for your VM if the problem still occurs.

Best regards,
Alicia.

which, while effectively turning Parallels into the equivalent of BootCamp, doesn’t fix the beachball issue, it does seem to fix the kernel-panic-on-startup issue.

Parallels techs are working on the issue:

Dear all,

We are sorry for the inconvenience caused. We are working hard to fix the issue but for the moment we can’t offer you a solution alternative to the one given by Alicia.    

Patiently looking forward to it.

Update: A number of users are reporting that turning off Spaces seems to help some of the issues. I, however, like Spaces too much to do something so drastic.

12 Nov 2007, 6:38pm
/dev/random
by

8 comments

Leopard Also Breaks PHP

Today I got back to work on an old open-source PHP project called Drop Bocks, a simple file upload utility. Imagine my surprise in discovering that what used to work flawlessly under OS X 10.4 dies an ugly death under OS X 10.5:

Fatal error: Call to undefined function imagecreatefromjpeg()

It seems that in addition to damaging any installation of MySQL and Apache the upgrade to 10.5 also over-wrote my PHP install with an inferior, no-GD included version, which is a big feckin’ problem Apple.

Some googling turned up the following simple (<- that's sarcasm) solution to fix Apple's installation fubar:

Okay, here is the complete instruction on how to do this. Michel L already posted a very good message on how to build PHP with GD enabled, so i just combine all the answers in one step-by-step guide.

1. Download the Apache2 source from http://httpd.apache.org/download.cgi (latest version is 2.2.6) and extract it.
2. Open Terminal and go to that directory. If you extract sources into your Downloads folder, type “cd ~/Downloads/httpd-2.6.6″ and hit return
3. Type “./configure –enable-layout=Darwin –enable-mods-shared=all” and hit return
4. Wait for the process to complete and then type “make” and return
5. Wait for the process to complete and then type “sudo make install” and return

Now you have Apache2 built and installed and it should run perfectly.

Then, follow the Michel L instructions. I will copy them here with several modifications:

Install libjpeg ***
Get latest Stable SRC:

http://www.ijg.org/files/

tar zxvf jpegsrc.v6b.tar.gz

cd jpeg-6b

cp /usr/share/libtool/config.sub .

cp /usr/share/libtool/config.guess .

[Update: WordPress fiddles with double-dashes so the compiler flags in the following statements are incorrect (ie: –sysconfdir=/etc should be preceded by two dashes, not one). In the comments Mark has posted a corrected version down in the comments that you should follow. I'd correct them in the article but they are in fact correct in the article content; it appears WordPress mucks with them elsewhere, alas. - Chris]

env CFLAGS=”-O -g -arch i386 -arch ppc” LDFLAGS=”-arch i386 -arch ppc” ./configure –prefix=/usr –sysconfdir=/etc –localstatedir=/var –mandir=/usr/share/man –enable-shared –enable-static

make

sudo make install

sudo ranlib /usr/local/lib/libjpeg.a

Install libpng ***
Get latest Stable SRC with config script

http://www.libpng.org/pub/png/libpng.html

tar jxvf libpng-1.2.22.tar.bz2

cd libpng-1.2.22

env CFLAGS=”-O -g -arch i386 -arch ppc” LDFLAGS=”-arch i386 -arch ppc” ./configure –prefix=/usr –sysconfdir=/etc –localstatedir=/var –mandir=/usr/share/man –disable-dependency-tracking

make

sudo make install

sudo ranlib /usr/local/lib/libpng.a

The same procedure with PHP sources, and configure line should look like this:

./configure –prefix=/usr –sysconfdir=/etc –localstatedir=/var –mandir=/usr/share/man –infodir=/usr/share/info –with-apxs2=/usr/sbin/apxs –with-curl –with-gd –enable-exif –enable-fastcgi –enable-zip –with-jpeg-dir=/usr/src/libjpeg –with-ldap=/usr –with-kerberos=/usr –with-zlib=/usr –enable-ftp –enable-sockets –with-iodbc=/usr –with-config-file-path=/etc –with-openssl –with-xmlrpc –with-xsl=/usr

If you have MySQL installed, add the following options to the PHP configure command (let’s assume you have your MySQL in /usr/local/mysql directory):
–with-mysql=/usr/local/mysql –with-mysql-sock=/var/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config

Then, run “make -j3″

And then, as usual, “sudo make install”

Note that PHP configure and build processes will take much time even on fast machine.

After all, go to “System Preferences > Sharing” and uncheck “Web Sharing” checkbox, then wait a bit and check it again. Now you should have your Apache+PHP up and running.

Screw that. From now on I’m using my Ubuntu machine for all PHP development until Apple finally starts shipping a decent development install or at the very least ships an OS that won’t fuck with mine.

4 Nov 2007, 1:30am
/dev/random
by

2 comments

Write the Code, Not the Comments

Long, long ago, eons ago back in 2005, Wil Shipley wrote a poignant piece of programming advice, this fragment of which sprang to my mind just this evening I was digging back through an old bit of my own code:

Write all your code “clean,” the first time you write it. Make classes for everything. Use enumerated types. Don’t take shortcuts. Don’t have any part of the code where you say, “Oh, yah, I just glossed over that for now.” You are NOT going to go back and fix it. Seriously, how often do you say to yourself, “I think I’ll dive into this messy code today and try to make it nice and pretty without adding any functionality?”

- Free Programming Tips are Worth Every Penny

The trigger for this memory? An old comment I’d left, presumably for a smarter, less time-pressed self:

<%# TODO: For the love of all that is sacred, make this recursive! %>

I should have listened to me back then. If I had I wouldn’t be up at 1:30am refactoring to do exactly that.