TextMate and Logitech Control Center (LCC)

If Logitech’s control center decided to start messing with TextMate, getting weird errors such as those found here, below is simple fix:

Delete the “LCC Scroll Enhancer Loader” folder from `/Library/InputManagers`; it also wouldn’t hurt to delete the LCC scroll enhancer bundle from `/Library/Application Support/Logitech`

Unless you are very picky about scrolling, and Apple’s built-in scrolling options aren’t good enough for you, then this solution is much more sensible than removing LCC altogether. As a quick note, you’ll know if you’re having this particular problem if you see “May 13 13:56:02 hostname <Application>[287]: LCC Scroll Enhancer loaded” in /var/log/system.log, for every application you open.

Thanks to max.goedjen and the folks over in this Growl Discuss thread. If you’re like me and just searching for just TextMate… you might not have found this.

Advertisements
TextMate and Logitech Control Center (LCC)

PHP4 + PHP5 compatible overloading

While I don’t necessarily enjoy PHP, it’s not such a terrible language. At least for version 5. Lately I’ve been working on a project called ‘migrations’ which is essentially a PHP utility to generate / track / apply changes to a database in a similar fashion to the migrations system in Ruby on Rails. Of course, it’s got more magic than migrations (only because we know we’re going to use subversion) and it’s got to work with PHP4.

Let’s get back to the subject though. When writing any type of class that needs to be polymorphic or ‘dynamic’ in a sense that method calls can be made when a pre-defined method doesn’t exist, then ‘overloading’ is the magic PHP provides to satisfy your needs. As a note, polymorphism is simply the ability of a method to take varying parameters or by which a different method will be executed based on the types and/or quantity of methods required. For example, you could have a different method defined for function($array) than function($string). PHP doesn’t care about types and so doesn’t support polymorphism per se but by using overloading you can essentially accomplish the same thing. In my case however, I’m simply wanting to allow execution of non-existent methods against on object. The purpose is that I want to be able to log each method call and it’s result in order to track what’s going on. You’ll quickly see what I mean in the examples.

PHP5 Basic Example:

class dynamicClass {
    function __call($method, $arguments) {
        trigger_error('Call to undefined method ' . __CLASS__ . '::' . $method . '()', E_USER_ERROR);
    }
}

Now have a class in PHP5 with overloading enabled. Without trigger_error, PHP will always think that you’re calling a valid method! In PHP5, there is no way to tell the interpreter the called method is invalid and you are responsible for triggering an error.

PHP4 Basic Example:

class dynamicClass {
    function __call($method, $arguments, &$return) {
        if($method == __CLASS__)
            return true;

        trigger_error('Call to undefined method ' . __CLASS__ . '::' . $method . '()', E_USER_ERROR);
    }
}

 
In PHP4, overloading was experimental for awhile and is now not well documented because it changed so much in PHP5. The first two lines of the __call method exist because the class doesn’t have a constructor defined but we don’t want to return false or null – if we do – PHP will throw a warning that we made a call to an undefined method, as it tries to call the non-existent constructor. Without overloading PHP4 ignores non-existent constructors, however, since we’ve overloaded and the constructor doesn’t already exist – PHP4 hits __call. This is different from PHP5 wherein PHP5 will not try to make an overload call for any constructor. This is likely because in PHP5 constructors or pseudo-static methods (they are not called within the context of an object even though the constructor has access to the object – this is why you get to use the $this variable even in a static context – if you couldn’t PHP5 constructors wouldn’t work ;) )

So between these two examples we can see some obvious limitations.

  1. don’t use overloading for anything regarding constructors
  2. php4 uses &$return declaration for return, php5 uses return()
  3. php4 is the exception, not php5; php5 autoload will work just fine
  4. in php4, you’re class is limited to being declared from within an eval() block

This makes for complications if you want to create a class with overloading which will work both in PHP4 and PHP5. There is the safe way, not-so-safe way, and the somewhat-safe way that’s a little slower! First, I’ll show you the not-so-safe way which I’ll be using simply because this is a utility and not something I expect someone to modify and secondly because integration tests tell me if/when something breaks. If you don’t write tests I would highly recommend the ‘safer’ way.

File – dynamicOverloaded.class.php:

class dynamicOverloaded {
    function __call($method, $arguments /*PHP4, &$return*/) {
        /*PHP4if($method == __CLASS__) return true;*/

        // You're overloading logic

        $return = $resultFromYourMagic;
        return ($return ? $return : true);
    }
}

You maybe asking yourself now “wtf” or “how is that supposed to work?” and you would be right – it’s not going to work yet. In order to make this work, you can’t require() or include(), or otherwise execute this file. Unless of course, the version of PHP is >= 5, in either case, the following code will do the trick.

The not-so-safe way:

if(substr(PHP_VERSION, 0, strrpos(PHP_VERSION, '.')) < 5)
    eval('?>' . preg_replace('|/\*PHP4(.*?)\*/|', '\\1', file_get_contents('path/to/dynamicOverloaded.class.php')) );
else
    require_once('dynamicOverloaded.class.php');

As with any php script, you have to include it. But in this case we’re eval()’ing the contents of the file instead of including it when using PHP4. Before eval we’re stripping /*PHP4 */ comments and leaving the code within it intact. The result? It’s like pre-compile macros for PHP. This is called the not-so-safe way primarily due to all of the limitations and bugs from eval().

But what is the safe method, and what if I’m doing something eval() doesn’t like?

In this case, you want to change your code to check for the version of PHP – create one class called yourClass.class4.php and yourclass.class.php; if using PHP4… you get the idea. Make your require() statements dynamic. The class4.php script will have the same code but you’ll remove the /*PHP4 */ comments before you save the file (leave the code between the comment markers in place). As you can see the real trick is to have your classes declared in separate files. The problem with this and the reason it’s not called “safe” is because you’re going to have to keep your changes to the class synchronized across both files at all times! While annoying, you can be happy know that you’re not eval()’ing code or executing temporary files.

But what if I don’t want to have to keep changes synchronized between class files and I don’t mind it being a tiny bit slow?

Before requiring the class file so you’ll want to name the base class yourClass.classX.php with the /*PHP4 */ blocks of code in it – before performing require() you literally ‘compile’ the class by running the preg_replace and saving the result to a temp file on disk; then require() the tmp file and delete the tmp file. Now obviously there can be some risks associated with executing a file which is written to disk by the executing process (esp if it’s a web server) but you can do a few things such as making the file name random to mitigate risks. Whatever you do, be sure the temporary location is relatively safe (consult chmod man page) and that above all the generated script is deleted after it’s executed.

PHP4 + PHP5 compatible overloading

Top Ten – No Background iPhone Processes

First of all I have to say I loathe the idea that Apple is not allowing background processes (per their documentation). Not to say Apple won’t change those provisions, but as-is, I don’t agree with disallowing background processes. On to the list (no particular order):

  1. mac worms (the kind that would spread across macs and iphones)
  2. making your iPhone a social communications device, for free
  3. p2p could be used to download and share music, for free
  4. battery life decreased more than 60 seconds
  5. turning iphone into free wifi hotspot takes away from ATT/Starbucks hot spot access
  6. cause ATT to discontinue distributing Apple revenue (due to #2, #3, #5 above)
  7. it would compete with Apple’s upcoming “iGPS”
  8. the SDK is really only for making games; Apple makes the real apps
  9. the device would be considered a weapon and be disallowed exportation
  10. iPhone can be used as a guidance control system for ballistics
Personally, I think if Apple were smart, they would realize how much running down a battery would cause folks to buy extra chargers for their car and work place. Oh well.
Top Ten – No Background iPhone Processes

OpenSolaris: Just call it “Open Source”

Genetic Open Source doesn’t sound too bad.

When it comes down to it, nobody knows what Sun is doing with OpenSolaris. No different than any other company which must reinvent itself every five years, Sun is changing the way they do things. What’s different is that open sourcing a product creates an irreversible social event in the lifecycle of the product being released.

What’s difficult is that we’re all so used to Apache, BSD, Mozilla, and MySQL – other open source systems which have been around for more than a decade. Not only do these products have maturity in their communities but the products themselves are mature. While Sun has a mature product with OpenSolaris, the product is a newborn to open source.

Let’s also not forget that Linux is still just a kernel. OpenSolaris should be considered with regard to suse and redhat rather than Linux. And while yes, kernel development is being done with OpenSolaris, that is not relevant to the inevitable result of a community developing an Operating System and not just the kernel.

Sun is putting their OS out there and saying “hey, we’re putting our code where our mouth is, now you can too”.

If it’s anything like Mozilla, let’s not forget Firefox was a rebel project (called Phoenix); as such, I doubt we can expect anything out of OpenSolaris from Sun, the company. The best we can expect will be from a side project which Sun may or may not take under it’s wings. Neither was possible before.

Regarding TCO report and Suncritters, let’s not forget that, Sun has to make money too. The only thing RedHat has that Sun doesn’t is experience with an open source operating system. One question worth asking in that context is, what type of support did RedHat provide when it first started? The answer is free and by mailing lists; then RedHat became commercial (<1yr) and of course has 24/7 support now. OpenSolaris is a new OS for Sun, relative of course – Solaris has been around awhile, but as an OS built through-and-through by a community, it’s new. In fact, as you’ve pointed out – OpenSolaris doesn’t have a large community yet other than Sun engineers – why are your expectations so high (link)?. Moreover, TCO analysis is all crap with regard to open source and ‘end users’ typically don’t understand any better. How many folks who download open source actually modify the code? Last, the linked survey is from 2005 and not to be a chump, but, Open Source has exploded and changed dramatically since that survey. Firefox wasn’t even big yet and MySQL 5 was still beta.

Organic or not, marketing or not, community or not, OpenSolaris is still an open source Unix operating system. Open sourcing code is great, no matter how it’s done.

Let’s just call OpenSolaris “Open Source”.

OpenSolaris: Just call it “Open Source”

Coding like it’s 1999

Here is my top ten list of “How to code like it’s 1999”:

1. using PHP < 5.3 (4 was beta in 1999)
2. making use of perl for *anything* (see #4)
3. template engines (scope and variable interpolation exist for a reason)
4. Perl6 (active 1999 mailing list)
5. Java Web Applets
6. SELECT * FROM (seriously, get ORM, select only what you need, or quit your day job.)
7. lisp (like a hero from a classic book, tragic)
8. non-functional redirect pages (hello js or location header; good-bye bad knocking off a lame phpbb feature)
9. ActiveX plug-ins (who developers sites with IE, anyways?)
10. SOAP (all your interoperability are belong to SOAP)

In short, if your core application for which your business and revenue suffers any of the above atrocities, step back for a minute and ask yourself if you really know any better? If you don’t, hire someone who does – FAST!

Coding like it’s 1999

Re: What Sun was trying to do with OpenSolaris

 

OpenSolaris vs Conceived Intentions

As from /., Ted at thunk.org has compiled a rant postessay” with regard to Sun’s OpenSolaris community.

About Ted:

I’m a systems programmer working at IBM. This allows me to get paid for what I used to do for fun, which is definitely neat hack. I’ve worked on the Linux kernel since 1991, and am probably the first Linux Kernel developer in North America. I am currently on the board of the Free Standards Group, as well as Usenix, where I organize the annual Linux Kernel Summit, which brings together the top 75 Linux Kernel Developers in the world every year. The Kernel Summit takes place in Ottawa, Canada, right before the annual Ottawa Linux Symposium.

Ted mentions Roy’s watching the ripples post, which is a great infomercial on day.com and it’s “open source” developers and their “closed source” CRM; criticizing Sun is all the rave and there are no substantial suggestions for what Sun should do with regard to Sun’s community. I won’t bother mentioning Ted is a Linux developer working for IBM and complaining about Sun. While entertaining, I would much rather see fights between the PostgreSQL and Sun’s MySQL folks just because I like to mis-pronounce PostgreSQL and MySQL is quirky.

I really don’t understand the blanket criticism. Somebody please let me know. Comments about trademarks = delete. It’s Sun’s toy, ok? If they want to share it, it’s up to them as to how and who they want to share it with. If Sun screwed you in some way, their execs are being open source media whores, or you’ve just gotten shit from Sun (and I don’t mean a 1996 newsgroup post), then please do tell your story. Complaining about Sun not liking your idea is about as entertaining as adopting a new Linux task scheduler or arguing over the transactional functionality of MySQL TRUNCATE command.

Open Source (Linux) vs. Open Source (Sun)

Let’s get back to the topic of “open source” – the synthetic kind. Since blog posts are essays now, and comments are syntactic qualifications which require research and justification, I’m going to throw a new term out there. Please use wikipedia, google, or anything else you would like to verify this newfound term, invented right here, and today – “Synthetic Open Source Community“.

Personally, I think non-organic is a little raw and vague – is it alien, poison, silicon-based? Synthetic works because while we’re not dealing with chemicals, we are dealing with “Computer Science” and we might as well qualify open source developer contributions in tandem with corporate oversight as flaming a chemical process.

So let’s not call Sun’s OpenSolaris community non-organic, we’ll call it synthetic. Right now Sun is trying to get bang for their buck and they’re going to use “open source” to do it. Linux is “open source” and OpenSolaris is “open source”; in that aspect, OpenSolaris is ‘just like’ Linux. Not really, but where do you see any Sun exec expressing and/or advertising Solaris this way anyways?

If you’ve run across some poo-poo posts on OpenSolaris, I recommend two posts (below) by Stephen at RedMonk. He concisely sums up presents both “sides” of the “just like Linux” adjunct. The other place to look are the opensolaris mailing list archives. I would recommend `-trademark -legal` when searching so you get posts about OpenSolaris and not the trademark whining.

Linux vs OpenSolaris…Again: The Q&A

An OpenSolaris by Any Other Name: The Q&A

Re: What Sun was trying to do with OpenSolaris

Safari Crash / Bug Webkit # 16196

I’ve been seeing this type of crash fairly often in Safari now. Not necessarily the same situation every time, but the culprit is almost always Javascript – not bad javascript – Safari just doesn’t like it. 

Here’s a stack trace:
0   com.apple.WebCore             	0x9535ff20 WebCore::ApplyStyleCommand::splitTextElementAtStartIfNeeded(WebCore::Position const&, WebCore::Position const&) + 32
1   com.apple.WebCore             	0x9535f02c WebCore::ApplyStyleCommand::applyInlineStyle(WebCore::CSSMutableStyleDeclaration*) + 396
2   com.apple.WebCore             	0x9535bcac WebCore::ApplyStyleCommand::doApply() + 284
3   com.apple.WebCore             	0x952e5eb8 WebCore::EditCommand::apply() + 168
4   com.apple.WebCore             	0x952e66cc WebCore::CompositeEditCommand::applyCommandToComposite(WTF::PassRefPtr) + 44
5   com.apple.WebCore             	0x9535baf8 WebCore::CompositeEditCommand::applyStyle(WebCore::CSSStyleDeclaration*, WebCore::Position const&, WebCore::Position const&, WebCore::EditAction) + 120
6   com.apple.WebCore             	0x9535b5fc WebCore::ReplaceSelectionCommand::completeHTMLReplacement(WebCore::Position const&) + 700
7   com.apple.WebCore             	0x95358240 WebCore::ReplaceSelectionCommand::doApply() + 11600
8   com.apple.WebCore             	0x952e5eb8 WebCore::EditCommand::apply() + 168
9   com.apple.WebCore             	0x953f0d0c -[WebCoreFrameBridge replaceSelectionWithFragment:selectReplacement:smartReplace:matchStyle:] + 236
10  com.apple.WebKit              	0x94b1a82c -[WebHTMLView(WebHTMLViewFileInternal) _pasteWithPasteboard:allowPlainText:] + 220
11  com.apple.AppKit              	0x918b9358 -[NSApplication sendAction:to:from:] + 104
12  com.apple.Safari              	0x00037870 0x1000 + 223344
13  com.apple.AppKit              	0x91954990 -[NSMenu performActionForItemAtIndex:] + 408
14  com.apple.AppKit              	0x919546c0 -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 228
15  com.apple.AppKit              	0x91954388 -[NSMenu performKeyEquivalent:] + 744
16  com.apple.AppKit              	0x91952e6c -[NSApplication _handleKeyEquivalent:] + 456
17  com.apple.AppKit              	0x91889a94 -[NSApplication sendEvent:] + 3548
18  com.apple.Safari              	0x00032fb0 0x1000 + 204720
19  com.apple.AppKit              	0x917f6ed4 -[NSApplication run] + 776
20  com.apple.AppKit              	0x917c792c NSApplicationMain + 440
21  com.apple.Safari              	0x00002d10 0x1000 + 7440
22  ???                           	0x00000ffc 0 + 4092

For anyone blogging and trying to paste content into the blogger Compose post window, good luck in Safari!

Looks like WebKit folks are working on it, there’s an Apple bug filed as well. This bug leads to crashes. If it’s happening for you, know that you are not alone or crazy. Writing browsers ain’t easy!
I heart WebKit team.
Safari Crash / Bug Webkit # 16196