• Prev
  • Stop
  • Play
  • Next
  • Aquarium
  • Fine Day
  • Bright Green Lights
  • For Your Smile
  • Pull You Through
  • In Your System
  • subscribe
  • follow me on twitter
    • 2010-04-29T12:17 woop! virtualbox 3.2b1 has experimental support for os x guests. http://bit.ly/aBymre
    • 2010-04-29T10:12 @mathie ouch!
    • 2010-04-29T10:11 @hoyd made a quick test app once, that's about it. would be interested in doing more, however.
    • 2010-04-29T09:17 think i've found my new job http://bit.ly/bce0x5
    • 2010-04-29T08:36 back from a nice 4 hour trip to A&E. just in time to start work :/
  • elsewhere
    • github github
    • linkedin linkedin
    • delicious delicious
    • flickr flickr
    • email email

  • Home
  • Logfile
  • Work With Me
  • Open Sawrce
  • Labs
  • About
  • Sitemap
22.12.2009

tipsy 0.1.4 released

STOP PRESS: yes I'm a twit and released buggy code. Fix is in 0.1.5.

Oh well, one project release in a year isn't too bad. I've pushed a new version of tipsy which officially unleashes some changes that have been kicking about for months:

  • Tooltip text is now recomputed on every hover event - tooltip can be modified simply by setting title attribute
  • Gravity can be set dynamically via callback function
  • Tooltip text can be sourced from arbitrary attribute/callback function
  • Fallback text can be provided for any element lacking tooltip text
  • Element's original value for title attribute is stashed in original-title attribute
  • CSS rounded corners for Webkit/Mozilla
  • All arrow images contained in a single image sprite

That's tipsy "done" now. I've toyed with the idea of adding some other features but feedback indicates that people like tipsy because it's simple and free of bloat so I'll try to keep it that way.

Standard linkage: project page | github | direct download from plugins.jquery.com

read more >
11.12.2009

Normal service resumed.

Site is redesigned, redeveloped and free from the shackles of Wordpress.

I’ve released the code powering the blog element of the site on Github. “static-ish” is a curious PHP library for taking a nested directory structure of loosely marked-up text files and converting them into formatted HTML. Read more about static-ish here.

Long overdue updates to boxy & tipsy are coming “soon”.

Apologies for sending everyone’s feedreaders haywire.

read more >
23.05.2009

Finding the arity of a closure in PHP 5.3

As part of the php-helpers project I’ve been working on a small library of functional programming primitives for PHP 5.3, including all the usual suspects like map(), every() and inject(). As we know, PHP arrays are really ordered maps, and when iterating with foreach we’re sometimes interested in both the key and value and other times it’s only the value we’re after. Preferably, code written in a functional style would be consistent with this pattern, each operation employing a single function capable of intelligently passing either $key, $value or `$value` based on what the user-specified lambda expected. So is this possible in PHP?

Arity to the rescue

From Wikipedia: “the arity of a function or operation is the number of arguments or operands that the function takes.”. Bingo. If we could somehow find the arity of a given closure, we could use this to decide whether to pass $key, $value or simply $value to our anonymous function. A language like Ruby makes finding a lambda’s arity as simple as foo.arity, but PHP isn’t quite so elegant, instead requiring us to whip out a bit of reflection:

Using reflection to find the arity of a closure
  1. <?php
  2. $c0 = function() {};
  3. $c1 = function($a) {};
  4. $c2 = function($a, $b) {};
  5. $c3 = function($a, $b, $c) {};
  6.  
  7. foreach (array($c0, $c1, $c2, $c3) as $c) {
  8.   $r = new ReflectionObject($c);
  9.   $m = $r->getMethod('__invoke');
  10.   echo $m->getNumberOfParameters() . "\n";
  11. }
  12. ?>

I’ll refrain from any puns alluding to vulgarity. Anyway, this yields the desired result:

  1. jason@ratchet Desktop  $ /usr/local/bin/php closure.php
  2. 0
  3. 1
  4. 2
  5. 3

Here’s the arity() function, and the resulting implementation of every(), taken directly from functional.php:

Implementation of arity() and every()
  1. // returns the arity of the given closure
  2. function arity($lambda) {
  3.     $r = new ReflectionObject($lambda);
  4.     $m = $r->getMethod('__invoke');
  5.     return $m->getNumberOfParameters();
  6. }
  7.  
  8. function every($iterable, $lambda) {
  9.     if (arity($lambda) < 2) {
  10.         foreach ($iterable as $i) $lambda($i);
  11.     } else {
  12.         foreach ($iterable as $k => $v) $lambda($k, $v);
  13.     }
  14. }

The lack of closures in PHP has long been one of the language’s most frustrating shortcomings when compared to its rivals, and their addition is – at least for me – the most exciting change in 5.3. While PHP will probably never be regarded as a “beautiful” language, closures allow us to write code which is both more flexible and concise by making it possible to define behaviour directly in the context it is being used, rather than having to implement it elsewhere in auxiliary classes or functions. Get on the bandwagon!

read more >
24.03.2009

From the I'm Working Too Late Department...

read more >
14.01.2009

PHP 5.3 namespace/exception gotcha

A quick heads-up for anyone who’s playing with PHP 5.3 and making use of namespaces and exceptions.

If your source file defines a namespace, all references to classes outside that namespace must be fully qualified and have a leading backslash (unless aliased by the use keyword). Unlike some other languages, PHP does not fall back to perform a search of the root namespace when a class is not found in the current namespace, and this can lead to subtle bugs in circumstances where non-existent classes may be safely referenced. While attempting to instantiate a non-existent class will always cause a fatal error, “passive” references such as those in catch clauses or instanceof expressions are permitted because the missing class could be later loaded, either explicitly or by way of an autoloader. So the following code snippet will not work as intended:

  1. <?php
  2. namespace test;
  3.  
  4. class Foo {
  5.   public function test() {
  6.     try {
  7.       something_that_might_break();
  8.     } catch (Exception $e) {
  9.       // won't be caught
  10.     }
  11.   }
  12. }
  13. ?>

In this code, the class name Exception actually resolves to test\Exception, and while this class does not exist it is still possible to refer to it without crashing your program. The exception goes uncaught, and possibly appears somewhere else further up the stack, leaving you bemused and with a precious few minutes less of your life left to make millions of money and drink beer. Instead, you must do the following:

  1. <?php
  2. namespace test;
  3.  
  4. class Foo {
  5.   public function test() {
  6.     try {
  7.       something_that_might_break();
  8.     } catch (\Exception $e) {
  9.       // this will work
  10.     }
  11.   }
  12. }
  13. ?>

I doubt this situation will improve as we get closer to 5.3 final; in order to fall back to the root namespace you would first have to exhaust the current namespace and this would necessitate the triggering any defined autoloaders and maintaining a list of namespaced classes known not to exist (which could of course change if the class was later dynamically generated via eval()). I’m not too familiar with PHP’s internals but consulting the autoloader every time a class is passively referenced would probably be prohibitively costly.

read more >
01.10.2008

jQuery Javascript Console Bookmarklet

jQuery console is a short bookmarklet that, when activated, loads jQuery into the current page (from Google’s hosted AJAX libraries) then overlays an interactive Javascript console permitting the evaluation of arbitrary expressions. Successive clicks will toggle the console’s visibility. It’s useful for using jQuery to quickly manipulate pages that don’t already include the library or for adding rudimentary console features to browsers other than Firefox.

Quick action shot:

WordPress doesn’t seem to let me paste the code inline so you’ll need to click the link below then drag the jQuery console link into your bookmarks bar:

jQuery console download page

As usual, sources at github.

read more >
21.09.2008

boxy 0.1.4

Somewhat delayed but hopefully worth the wait, boxy 0.1.4 is ready. Boxy is a Facebook-style dialog library for jQuery with a rich API for manipulating windows. It’s also pretty well documented.

Changelog:

  1. Fixed issue with multiple visible modals
  2. Moved modal opacity value from CSS to code to appease IE (not ideal)
  3. Moved default options to Boxy.DEFAULTS for application-wide configurability
  4. Added custom callback for attaching behaviours to dialog content
  5. Added Boxy.alert() for displaying simple messages
  6. Added Boxy.confirm() helper
  7. Added support for unloading/removing boxy instances: boxy.unload(), boxy.hideAndUnload(after), constructor option ‘unloadOnHide’
  8. Boxys created with Boxy.ask() or its derivatives now unload themselves on dismissal
  9. Fixed centering issue in IE6 (non-standards compliant mode)
  10. Added afterShow callback, fired whenever boxy becomes visible
  11. Added Boxy.load() for manually loading boxy content via AJAX
  12. Moved WRAPPER to from Boxy.prototype to Boxy to improve app-wide configurability
  13. Complete rewrite of $.fn.boxy; see elsewhere for explanation
  14. Removed ’single’ plugin option
  15. Added option to link each boxy instance to the DOM element which triggered it; this is automatically severed when boxy is unloaded
  16. Added option to filter AJAX content using jQuery selector
  17. Fixed positioning bug with Opera
  18. Added beforeUnload callback
  19. Added Boxy.isModalVisible() for testing if a modal dialog is currently visible
  20. Added afterHide callback
  21. Added afterDrop callback
  22. Modal shading now resizes with browser window
  23. Added clickToFront option, bringing a dialog to front when clicking anywhere within it
  24. Added Boxy.linkedTo() to get boxy instance linked to a given element via ‘actuator’ option
  25. Added boxy.toggle() to toggle between visible/hidden

There’s also a new test and examples page that gives all of the major features a workout.

This will be the final release before 1.0; from now until then I’ll be concentrating solely on fixing bugs and stabilising the API. I think I’ve managed to accommodate most feature requests in one way or another.

Linkage: project page | github | direct download from plugins.jquery.com

read more >
14.09.2008

Two Quick jQuery plugins before bedtime

Just a couple of extractions from recent projects that may be useful to somebodies.

First up is an automatically growing textarea. This implementation is borrowed from Facebook and uses an off-screen auxiliary <div> to calculate the required dimensions of the textarea. Usage is simple:

Autogrowing textarea example:
  1. $('textarea').autogrow();

Next is a cookie-based style switcher, the obvious use of which is toggling between small/medium/large text. Quite why the browser supplied zoom features are insufficient is a mystery to me, but hey ho, the client is always right.

Cookie-based style switcher example:
  1. cookieResize('#sizer a', 'medium');

The first argument is a selector matching the resize/style-switching links. When the user clicks any of these its CSS class will be applied to document.body - this class name will also be stored in a cookie for retrieval on successive page views. The second argument is the default class to use if no cookie is present.

No official plugin pages for these; just copy and paste into your project…

Linkage: auto-growing textarea | cookie-based style switcher

read more >
09.08.2008

boxy 0.1.3 released

I’m pleased to announce the release of boxy 0.1.3. This is mainly a bug-fix release but there are a couple of new features in there as well.

Changelog:

  • Fixed CSS class name in middle-bottom cell of wrapper markup
  • Pressing escape now closes modal dialogs (as long as dialog is closeable)
  • Added getter and setter for dialog title
  • Title text is now wrapped in <h2></h2>
  • Title parameter now works when passed to plugin
  • Close text is now configurable via closeText constructor parameter
  • Titlebar text is “unselectable” while dragging
  • Close event is rebound correctly if boxy has been cloned
  • Fixed bug where border would compress when dragged offscreen
  • Dialog can now be centered on a single dimension
  • Numerous code cleanups

Linkage: project page | github | direct download from plugins.jquery.com

Thanks to everyone who submitted bug reports and patches.

read more >
08.08.2008

Boxy Google Group

Just a quick heads-up; a couple of people have enquired about a discussion place for Boxy so I’ve set up a new Google Group.

0.1.3 release is coming soon.

read more >
Page: 1 2

Archives

  • December 2009 (2)
  • May 2009 (1)
  • March 2009 (1)
  • January 2009 (1)
  • October 2008 (1)
  • September 2008 (2)
  • August 2008 (2)
  • June 2008 (2)

Friends

  • Magic Lamp
  • Garage Duo
  • Atom
  • Drew not Weird
  • Enthusiastik
  • Fusible Front
  • Jam Hot
  • John Disco
onehackoranother.com © 2008 - 2010 Jason Frame. All rights reserved.