RSS feed

Nutsmuggling

A man peeing on the roof #1

Once upon a time, and a very good time it was, I was sitting at my desk, in front of my laptop, diving into some research. Those were the PhD years, and I was probably meditating on orality or on one of Joyce’s masterpieces.
My desk sits in the corner of my living room; at its left there’s a big window, from which a lot cold penetrates first into my room and then into my bones. Yet, thanks to this window I have witnessed a number of small piecés of the theatre of the everyday, taking place on Vicolo Mustacchi, which I like to refer to as Desolation Row.1

Moustache Alley

I could tell you about the woman left by her lover, quarreling over the phone. I could tell you about the drunkard swearing and singing, or about the verbal fight between the patriarch of the Naples tribe and the local car repairer. But I will tell about something more amazing.

Looking out from the aforementioned window you see the last floor a building and, more importantly, its roof. On the roof, a velux.2

On February 16th 2006,3 the velux opened, a head popped out. A body followed. It was a man working on the flat maintenance. The man climbed out the velux and started walking on the roof. He looked around, and choose a corner. He started to pee. As soon as he finished, he want back into the apartment through the velux.

‘Course, I can’t say I seen London, and I ain’t never seen no queen in her damn undies as the fella says.4

But I’ll tell you, after seeing this man peeing on the roof I decided I had to put to paper what could end up being just a mere shadow of the event I had just experienced. The limerick seemed a fit medium. I composed four of them, here’s the first.

There was an old man quite aloof
Who liked to go peeing on his roof.
But the prospects were bleak,
For the roof it did leak
On the flat of this man quite aloof.

More to follow…

Notes

  1. No, we aren’t selling postcards of the hanging. Yet. []
  2. Not sure we use the same name on both sides of the Atlantic. In any case, I am talking about one of those dormer-windows. []
  3. My Adium logs are almost a diary, I realised. []
  4. If you don’t get this quote I am certainly not going to help you. []

Simple pluralization with jQuery

Don’t you hate it when a html form shows something like this?

test-blog-add-new-wordpress-1.png

I understand we’re in a territory that most people would label as “cosmetics”, but I was taught better than this, and the idea of writing “1 days” still makes my stomach ache.

The most obvious solution is to follow the traditional paper forms convention and write something like “day/days”, but can we really stop automation?

So here’s my solution. It’s a simple one, based on the wonderful library that is jQuery.

First, add a couple of spans after your input, one for singular, one for plural.

<input id="interval" name='interval' size='2' value=''></input> 
<span class='interval-desc' id="interval-singular">day</span>
<span class='interval-desc' id="interval-plural">days</span>

Then, put this script somewhere in your <head>:

// Make sure the src attribute points to
// the actual location of jQuery
<script type="text/javascript" src="jquery.js"></script> 
<script type="text/javascript">
//<![CDATA[     
$j=jQuery.noConflict(); 
 
function updateIntervalDescriptor () { 
   $j(".interval-desc").hide();
   var number = "-plural";
   if ($j('input#recurrence-interval').val() == 1 
     || $j('input#recurrence-interval').val() == "")
       number = "-singular"
var descriptor = "span#interval-" + number;
   $j(descriptor).show();
}     
 
$j(document).ready( function() {
   updateIntervalDescriptor(); 
   $j('input#recurrence-interval').keyup(updateIntervalDescriptor);
}
//]]>
</script>

The concept is pretty straighforward. If your input contains a value bigger than 1, or no value, the “day” span is shown, otherwise the “days” span is shown. It’s really a no-brainer, but I thought I’d share it, for the love of grammar :)

Of course you can use the same rationale to make your forms more dynamic. The original script behind this post changes the text according to frequency, so you have day/s, week/s and month/s. Once you grasp the basics it’s pretty easy to automate your forms this way.

As a side note, you may have noted this line:

$j=jQuery.noConflict();

This is to stay on the safe side and avoid potential conflict with other libraries. In my case, I acquired this habit after starting coding wordpress plugin; Wordpress, at least up to 2.5, uses both Prototype and jQuery; both libraries use the $ selector.

Update

Gary Jones suggests an even simpler way to pluralize through jQuery.
I do favour myself his method, which is more synthetic than mine.

My example was actually born stripping heavily from production code. For the sake of focusing, I decided to take out most of the context. In the original code, part of Events Manager 2.0, I don’t use “day” but a localised string, introduced through

_e('day', 'dbem');

I prefer not to mingle javascript and PHP when not strictly necessary. Moreover, the string displayed depends also on a frequency selector, so I have also ‘weeks’ and ‘months’, and a more complicated id structure. That is why I went for a longer approach and more spans. If your needs aren’t that complicated, go with Gary’s tip.

Lovedeity has also a point reminding me that many languages have more complicated rules for plural. When I find a French localiser, I’ll have to look into this.

Thank ye all folks, we’re having a nice discussion here!

Add a page to the main menu block: add_object_page

This short post documents a menu hook that’s not in the official Wordpress Codex.

As you might know, plugins developer have use the add(_something)_page family of functions to hook up their own pages to the existing Wordpress Menu.

This one will come in handy to those who need their plugin to be prominent.

 add_object_page( $page_title, $menu_title, $access_level, $file, $function = '', $icon_url = '')

This function is in `wp-admin/includes/plugin.php.

add_object_page list your page in the main block, after “Comments”.

Of course think twice before using it. As the name suggests, just “objects” are supposed to go in this area of the menu. I would define objects as entities, models in the MVC paradigm. Objects are basically the “content, the ‘c’ of a CMS.

In my case, I am going to add here my Events. If you think about it it makes sense, a user manages his posts, media, links, pages, comments and events.

Test Blog › Eventi — WordPress.png

As you see, I’ve added a number of submenu items to this menu. This is the way you do it:

add_object_page(__('Events', 'dbem'),__('Events', 'dbem'),MIN_CAPABILITY,__FILE__, dbem_events_subpanel);
add_submenu_page(__FILE__, __('Add new'), __('Add new'), MIN_CAPABILITY, 'new_event', "dbem_new_event_page");
add_submenu_page(__FILE__, "Venues", "Venues", MIN_CAPABILITY, 'venues', "dbem_venues_page");
add_submenu_page(__FILE__, "People", "People", MIN_CAPABILITY, 'people', "dbem_people_page");

__FILE__ identify my object page; the “Add New” submenu page references the same __FILE__ element. This way Wordpress knows he has to attach this second new page to the first one. The same applies to the “Venue” and “People” pages.

The clog icon that you see is the Wordpress predefined one for new “top level” pages. As the function header shows, you can easily add your own icon; this is a nice touch from the Wordpress development team.

By the way, this is the first glimpse of Events Manager 2.0; more to come, quite soon.

Wordpress.org stats weirdness: “Region A – Region B”

This is what I got today in my Wordpress.com stats pic, instead of the usual visits graph:

Weird blog stats-1.png

This is most certainly a default picture shown when the Flash graph cannot load.1

The good news is the issue is easy to solve:
* deactivate the Wordpress.com stats plugin
* reactivate it
* re-insert you API key, making sure to associate the new stats to the old blog

Ta dah!
That worked for me at least; you might have to restart your browser and epmty your cache.

This issue affected only Safari in my case; elsewhere people reports the same oddness in Firefox.

This bug seems occasional, and this explains why it looks pretty much undocumented.

I hope these tips helped you to push the Region A – Region B graphs out of the window.

Notes

  1. Yes, the graph is made in Flash, as I had the doubtful pleasure to find out when trying to access the stats through my iPhone. []

viewWillAppear: not being called inside a UINavigationController

I just stumbled on a small problem that gave me a great headache. I changed the view hierarchy to implement flipping preferences on the back of my App’s main view. Accordingly, I had to move some stuff out of the nibs and into the code. Iin other words, some heavy refactoring, and without testing (I know, bad bad me).

So basically I now have a root UIViewController which has a UINavigationController as a subview; this, in turn, loads a number of UIViewControllers to navigate my items hierarchy.

Today, while working on cosmestic/usability improvements, I realised that something was definitely not working. When moving back and forth in my items, data were not refreshed. This pointed to one culprit, viewWillAppear not being called in the UIViewControllers.

After some googling I found out that if you add a UINavigationController as a subview of a UIViewController subclass, you must explicitly call its viewWillAppear method from its container; otherwise, they won’t be called, and when moving back and forth in the navigation tree, your UIViewControllers’ viewWillAppear: methods won’t be called.

It’s quite simple; assuming that projectNavigationController is a navigation controller added as a a subview of this UIViewController subclass, just make sure you add this simple call:

-(void)viewWillAppear:(BOOL)animated { 
	[super viewWillAppear:animated];
	[projectNavigationController viewWillAppear:animated];
}

Of course the same applies to your other viewWill/Did methods

-(void)viewWillDisappear:(BOOL)animated { 
	[super viewWillDisappear:animated];
	[projectNavigationController viewWillDisappear:animated];
}
-(void)viewDidAppear:(BOOL)animated { 
	[super viewDidAppear:animated];
	[projectNavigationController viewDidAppear:animated];
}
-(void)viewDidDisappear:(BOOL)animated { 
	[super viewDidDisappear:animated];
	[projectNavigationController viewDidDisappear:animated];
}

It’s quite simple, but wasn’t obvious for me at first.