Showing posts with label mac. Show all posts
Showing posts with label mac. Show all posts

Wednesday, October 21, 2009

Two cool (and underreported) things about Snow Leopard.

I recently upgraded my various Macs to Snow Leopard, Apple's streamlined new operating system. So far two things have caught my eye, both of them very nice surprises.
  1. System Perl is now version 5.10.
  2. The Activity Monitor now shows Safari Plug-Ins such as the disastrous resource-hog Adobe Flash as separate processes.
So now when your fans start going nuts over a YouTube video, you can see exactly who's to blame. As usual, Adobe is to blame. I have yet to try killing the Flash process to see if it can be done without affecting the rest of Safari, but I'm hopeful it might. As for the Perl, here are the geeky details:
kfrost@mbp ~/bloc $ perl -V
Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
 Platform:
   osname=darwin, osvers=10.0, archname=darwin-thread-multi-2level
   uname='darwin neige.apple.com 10.0 darwin kernel version 10.0.0d8: tue may 5 19:29:59 pdt 2009; root:xnu-1437.2~2release_i386 i386 '
   config_args='-ds -e -Dprefix=/usr -Dccflags=-g  -pipe  -Dldflags= -Dman3ext=3pm -Duseithreads -Duseshrplib -Dinc_version_list=none -Dcc=gcc-4.2'
   hint=recommended, useposix=true, d_sigaction=define
   useithreads=define, usemultiplicity=define
   useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
   use64bitint=define, use64bitall=define, uselongdouble=undef
   usemymalloc=n, bincompat5005=undef
 Compiler:
   cc='gcc-4.2', ccflags ='-arch x86_64 -arch i386 -arch ppc -g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -I/usr/local/include',
   optimize='-Os',
   cppflags='-g -pipe -fno-common -DPERL_DARWIN -fno-strict-aliasing -I/usr/local/include'
   ccversion='', gccversion='4.2.1 (Apple Inc. build 5646)', gccosandvers=''
   intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
   d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
   ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
   alignbytes=8, prototype=define
 Linker and Libraries:
   ld='gcc-4.2 -mmacosx-version-min=10.6', ldflags ='-arch x86_64 -arch i386 -arch ppc -L/usr/local/lib'
   libpth=/usr/local/lib /usr/lib
   libs=-ldbm -ldl -lm -lutil -lc
   perllibs=-ldl -lm -lutil -lc
   libc=/usr/lib/libc.dylib, so=dylib, useshrplib=true, libperl=libperl.dylib
   gnulibc_version=''
 Dynamic Linking:
   dlsrc=dl_dlopen.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
   cccdlflags=' ', lddlflags='-arch x86_64 -arch i386 -arch ppc -bundle -undefined dynamic_lookup -L/usr/local/lib'


Characteristics of this binary (from libperl):
 Compile-time options: MULTIPLICITY PERL_DONT_CREATE_GVSV
                       PERL_IMPLICIT_CONTEXT PERL_MALLOC_WRAP USE_64_BIT_ALL
                       USE_64_BIT_INT USE_ITHREADS USE_LARGE_FILES
                       USE_PERLIO USE_REENTRANT_API
 Locally applied patches:
       /Library/Perl/Updates/ comes before system perl directories
       installprivlib and installarchlib points to the Updates directory
 Built under darwin
 Compiled at Jun 24 2009 00:35:27
 %ENV:
   PERL5LIB=""
 @INC:
   /Library/Perl/Updates/5.10.0/darwin-thread-multi-2level
   /Library/Perl/Updates/5.10.0
   /System/Library/Perl/5.10.0/darwin-thread-multi-2level
   /System/Library/Perl/5.10.0
   /Library/Perl/5.10.0/darwin-thread-multi-2level
   /Library/Perl/5.10.0
   /Network/Library/Perl/5.10.0/darwin-thread-multi-2level
   /Network/Library/Perl/5.10.0
   /Network/Library/Perl
   /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level
   /System/Library/Perl/Extras/5.10.0
   .

Saturday, November 29, 2008

Giving up on a local WordPress install on Mac.

Summary

WordPress is nice, but setting up a local instance in a nonstandard environment is more trouble than it's worth. WordPress was designed for shared-hosting environments that have a classic "LAMP" application stack preconfigured (Linux+Apache+MySQL+PHP). It was specifically not designed to run on a wide variety of server environments.

Fortunately, for the kind of work I want to do (blog template design) there are acceptable workarounds. But this latest encounter with the MySQL and PHP ecosystems has left me, once again, sorely tempted to just build my own blogging system.

Read on if you want to geek out on some of the details. If you just want the conclusion, it is: use a standard virtual machine (VM) or set up a sandbox blog in a shared environment. Either one of those will work well enough, and the VM approach is probably the closest you'll get to a "safe" install. Unless you're being paid for the setup time, I strongly advise against trying to make it work locally in anything but a stock configuration.

Motivation

A while ago I set up a blog with a friend of mine: Migratorium. It's an outlet for our travel writing, or at least it will be.

It runs on WordPress in a shared-hosting environment over at Dreamhost: bang, meet buck, at least for small projects. I really like the WordPress user interface, but even with great templates like veryplaintxt I quickly became frustrated with the design possibilities.

In short, you have to learn some PHP (painful but not so hard) and the arcane, under-documented WordPress templating system (ditto) in order to do any meaningful design. Since I already know HTML, CSS, Perl, and Template Toolkit, I thought I'd be much happier building my own sites using those technologies. And it would keep me away from PHP, which I dislike, and MySQL, which I abhor.

Then I thought about setting up an RSS feed. No biggie, just another afternoon. Then I thought about setting up a decent editing UI. No biggie, just another weekend. Then I thought about making it easy for my non-computer-geek friends to use. Uh-oh... that started to sound like real work.

So I decided to make at least one serious effort to teach myself enough WordPress Templatese to either do serious design in that ecosystem or give it up from an informed position. And for that I need a local copy of WordPress in which to hack the templates.

Technical Goals

I'm doing this on an Intel Mac running the latest version of Leopard (OS X 10.5.5 as of this writing). I use lighttpd as my local web server and would prefer to use that, but I will use the built-in Apache if I must. I have MacPorts installed, but I would prefer to run this under the system default PHP. I also want this to run on SQLite if at all possible, since I want to hack templates, not databases.

Trying to Get There

  1. I checked Google first.

    Oh-oh. The first thing I found is that only MySQL is supported, as WordPress doesn't have a database abstraction layer. That's a shame, but it seems like an absolute.

    There is one plug-in that gets you close: PDO, but its limitations make it sound just about as onerous for my purposes as MySQL itself.

  2. Install MySQL

    OK, let's see if this can be done with minimal exposure to MySQL. 2 tablespoons has some instructions for getting MySQL running under MacPorts. That almost worked, but not quite. Following more info under the comments I found I had to set the socket file in /opt/local/etc/mysql5/my.cnf:

    [mysqld_safe]
    socket = /tmp/mysql.sock
    [mysqld]
    socket = /tmp/mysql.sock
                
    I also had to create the run directory:
    sudo mkdir -p /opt/local/var/run/mysql5
                
    Now I was able to start the system, but everything complained about the socket file location. I fixed that in my aliases in .bash_profile:
    # evil mysql is required for local wordpress
    alias mysql5='mysql5 --socket=/tmp/mysql.sock'
    alias mysqladmin5='mysqladmin5 --socket=/tmp/mysql.sock'
    alias mysqlstart='sudo /opt/local/bin/mysqld_safe5 &'
    alias mysqlstop='/opt/local/bin/mysqladmin5 -u root -p shutdown \
    --socket=/tmp/mysql.sock'
                
    Backgrounding your startup command with & is a Very Bad Practice but it seems like that's what mysqld wants; I may be using the wrong command altogether. Also note that you will almost certainly have to set that socket location explicitly in other commands/configs as well. Once you have the above aliases in effect don't forget to set your MySQL "root" password (not to be confused with the system root password). Press RETURN at the Password prompt, or enter whatever the previous password was.
    mysqladmin5 -u root -p password MYSECRETPW                
                

    At this point I'm able to connect to the database server with mysql5 and issue some simple commands, so I consider it done-ish after about two hours of work. Further tweaks will be listed below.

  3. Pour another glass of tasty Basque wine; do not give up yet!

    This little exercise is already confirming my various prejudices against MySQL and PHP and all sloppy engineering everywhere in the universe. But man, I do love that editing UI. Must... persist! Thank you Xarmant Txakolina!

  4. Install PHP from source. Ouch.

    I'd actually gotten far enough to have the PHP running, more or less, though without valid HTTP headers and without a successful database connection. And then I hit the php-cgi wall. Turns out you have to install from source, the standard install doesn't work properly with lighttpd.

    Fortunately Simplistic Complexity had a helpful blog post.

    Unfortunately that doesn't work with MySQL installed via MacPorts.

    I tried a few of the obvious tweaks to the make process and realized I would have to reinstall MySQL. And that's where I hit the wall.

Hitting the Wall

Having spent most of the day on this and gotten very close, I had to ask myself: Is it worth it to push on through?

Since I make software for a living I'm always tempted to put on my Big Fat Engineer's Hat and complain about the quality gaps in whatever piece of software I'm pounding my head against at the moment. But that wouldn't be even close to fair in the WordPress case: here is a product I really like as long as I don't have to look under the hood; and its content-management UI is frankly more usable than any equivalent thing I've ever built, and even if it is finicky on the server side I think the proof of its value is in the client experience.

I love WordPress for its content-management UI, and there's no special reason why its installation prerequisites or developer documentation should be tailored to my needs. If I cared that much I could contribute to the project, or fork it, or write my own.

So in the interest of fairness to a justly popular blogging system, and also in the interest of my own sanity, I gave up on my little snowflake of a local WordPress installation.

Instead, I'll try it their way and see if I can make some headway with the templates. A lot of generous people have given a lot of their time to this open-source product, and I still hold onto the hope that I can more easily beef up my WordPress templates than use (or write) a different blogging system.

To be continued (perhaps virtually).

I think the most sensible thing to do now is install a VMWare image with a recent version of WordPress. It looks like rPath has one.

That has the advantage of still being more or less "local" even if a bit resource-intensive; and if it doesn't work, it's always possible to just set up a sandbox WordPress account with an obfuscated URL.

I'll be sure to update the blog with the results of that operation when I have time for it.

Wednesday, June 25, 2008

Printing with TextMate, vim and Friends.

TextMate and vim are my favorite text editors. Unfortunately, TextMate has very little support for printing. It's a nightmare, really, and unlikely to be fixed any time soon. The author simply isn't particularly interested in printing.

Fortunately, vim is really good at printing, at least to PostScript, and does syntax highlighting better than just about anything else. And fortunately, TextMate is designed to let its users easily hack together their own supplementary solutions, called Bundles.

My solution to the printing problem is, in short:

  1. Print from vim to PostScript.
  2. Convert the PostScript to PDF.
  3. Open the PDF in Preview.
  4. Do all this with the standard command-P shortcut.

First, here's the bundle item:

    [ -n "$TM_FILEPATH" ] && \
    PDF_FILE=~/Desktop/`basename "$TM_FILEPATH"`.pdf
    PS_FILE=/tmp/`basename "$TM_FILEPATH"`.ps
    vim \
        "+set number" "+syntax on" "+color slate" \
        "+set printoptions=number:y" \
        "+set printfont=courier:h9" \
        "+hardcopy > $PS_FILE" "+q" \
        $TM_FILEPATH &>/dev/null && \
        ps2pdf $PS_FILE $PDF_FILE && \
        rm $PS_FILE && \
        open $PDF_FILE

And here's a screenshot to make it even easier:

TextMate Bundle

To get this working on your own Mac, you need to install the xpdf package from MacPorts, and then find a suitable color scheme for vim printing if you don't like the default. There's a great write-up on that last bit over on the Vim Tips Wiki. Once you've installed/tweaked/tested your scheme, just replace the "slate" reference in the bundle text above.

LIMITATIONS, QUIRKS AND BUGS

  1. This prints in 9pt Courier, with line numbers and wrapping, because that's how I think code should be printed.
  2. Only saved files are printed; your "buffer" is not. I may change that later.
  3. It will probably break if the slate color scheme is not installed. That was the best scheme installed by default on my Mac, hence the choice.
  4. The PDF is saved to your Desktop, overwriting any like-named PDF, e.g. MyModule.pm.pdf. I like having the thing on my desktop, but I may make it clobberproof later.
  5. YMMV, it's probably buggy, and so on. If you aren't comfortable hacking UNIX, don't try this at home. I actually don't think it's good enough yet to submit to the bundle repository, so don't make any assumptions.

Monday, December 03, 2007

Firefox 2.0.11.12.13.14... still a shit-show.

The well-heeled open-sourcerers over at the Firefox Corporation have been releasing ultra-minor updates at a furious pace lately. Just days on the heels of 2.0.10, they shot me 2.0.11. And just minutes after that, my MacBook CPU spiked to >=100%, fans whirring, on a total of 8 open tabs, none of them exotic, in a single window. And the icing on this particular turd-cake: I use a Flash blocker because Adobe can't clean up Macromedia's code enough for it to run properly on a Mac. Yes, I click every single little Flash animation that I actually want to see, and yes, it's a pain, but it generally saves me from force-quitting my browser. So if Firefox blows so hard lately, why do I still use it as my primary browser? One word: Firebug. It's still the best JavaScript developer's tool anywhere... possibly the best client-side web developer's tool, period. The fact that a lot of the dumber webmasters of the universe still don't support Safari is a growing annoyance now that I'm one of the many people browsing via iPhone. Using Firefox as my primary browser was generally a safer bet. And yet, lately, with every expectation that 2.0.12 and 2.0.13 will be buggy as well, But is it buggy enough to make me give up my Firebug? It might be, at least for everyday browsing. I finally got around to AppleScripting command-number shortcuts for tab selection in Safari (a thing Apple, for some reason, doesn't get), so it's really just an acclimation question. Besides, Firefox renders fonts in Ugly-Sans no matter what you do. PS, why am I being so hard on the poor Firefox crew? Because when you make 74 million bucks a year and you're the number-one browser for even semi-clueful people around the world, you can afford to spend on engineering and QA. And you have, frankly, having built that lucrative business on the goodwill and technical help of your users, an obligation to not screw it up.

Friday, July 20, 2007

Firefox goes to 11.

It's pretty well known that Firefox 2 for the Mac has some CPU and memory issues. It's also pretty well known that Adobe's Flash Player for Mac is a bloated, processor-hogging swine that wouldn't know an optimization if it were bit on the ass by one. In case you have a Mac and were wondering why everything would slow down and your browser might even lock up if you were on a page with more than one YouTube video, that's the reason. But today it got out of control. I loaded a background tab that probably had a bunch of Flash embedded in it, but I'll never know as the app locked up so fast I couldn't get to the tab. And then I saw why: Firefox was using over one hundred percent of the CPU! It was fluctuating between 102% and 104%. Before any of you heavy math types get all huffy with your talk of impossibility, let me just say that my iPhone was docked at the time, and I think its processor can probably just about handle an extra 5% of my Macbook.