Archive for February, 2009

I've got a cheap website that doesn't let me use cron to schedule tasks (like database backups), so I had to do it myself. I found pseudo-cron, which looks cool but has some bugs and was more complicated than I wanted, so I wrote a simple PHP script to do what I wanted.

Continue reading ‘Scheduling tasks with PHP’ »

I use an AT&T 8525 smartphone (it's the HTC Hermes TyTN) that a friend recommended (some friend!). I've been pulling my hair out with its daylight savings bug—events have the correct time in Outlook on the computer, but are an hour off or worse on the phone. Outlook stores events in UTC and displays them in the local time zone. Events that take place during daylight savings time occur one hour earlier UTC, but Outlook knows that. Windows Mobile 6 doesn't. Why would a Microsoft programmer creating a calendar program care about daylight savings time? It only affects half the year! So all appointments during DST are listed on the phone as one hour earlier. Worse, all-day events are stored as midnight-midnight, with an extra flag marking them as all day long. The bug shifts the event to 11pm the day before, still marked as an all day event, so Easter Sunday falls on Saturday on my phone!

Solution: Follow the instructions at Microsoft's website: The phone resets itself without warning; that's OK. The times are still messed up. Open Outlook and make sure your contacts and calendar are correct. Now open Active Sync and select Delete Mobile Device from the File menu. This means that everything on the phone that syncs (Calendar, Contacts, etc.) will be erased and recopied from the computer (Microsoft neglected to provide a way to just sync with "computer overwrites handheld" for just the calendar, the way Palm does). Connect the phone. A "Connected" message appears in Active Sync, then the whole program disappears. Disconnect the phone and reconnect. A "Connected" message appears in Active Sync, then the setup wizard starts, and you can sync as usual. Pray that all your critical appointments will be copied correctly (this took 2 hours with my data). The phone calendar now has the correct days for all-day events, but the times are still off. Changing the date to a day in DST (under Settings/System tab/Clock and Alarms), however, corrects the times, both during DST and regular time. Changing the date to the correct date does not lose the correction. Restarting the phone makes it forget the correction, so you have to do the change date hack again.

Liberally mutter or curse while performing this arcane art.

Bottom Line solution:

  1. Don't buy Microsoft products
  2. If you must buy Microsoft products, don't depend on them
  3. If you must depend on them, keep multiple backups and count the days until you can justify buying an iPhone

All I wanted to do was back up the Young Israel databases, some way more amenable to automation than phpMyAdmin. There are lots of PHP-based solutions on the web, but all seem based on mysqldump. I implemented one and found myself faced with an eyeful of אריאל מאיר יעקב בן דוד אברהם where the Hebrew names should be. Turns out this a known bug; mysqldump can't handle Unicode. There are reports of workarounds, but I spent 8 hours not getting anything to work.

So I had to write my own backup, going through each database on a server then each table in the database, writing the appropriate INSERT INTO commands (thank goodness the SHOW CREATE DATABASE and SHOW CREATE TABLE commands work correctly). It wasn't terribly miserable (not nearly as miserable it was trying to use someone else's tool that doesn't work), and now I get my  אריאל מאיר יעקב בן דוד אברהם just fine, and the backup works. I import the generated file into my local copy of mySQL and it regenerates the databases.

Continue reading ‘The Agony of Unicode (and backing up mySQL)’ »

I don't like writing function(){$(this).doStuff()} for callbacks and wanted some more elegant way of binding objects to functions. I could always use something like Prototype's bind, but I don't want to modify built-in types (because John Resig says not to) and I generally just want to bind plugins to jQuery objects, so it ought to be a plugin. Inspired by Ariel Flesler's jquery.sugar and John Resig's ultrachaining.

So we have $.later and $.fn.later. $.later() returns a chainable function that is bound at call time to this. $.later().css('color', 'red').append('<span>more</span>') is the same as function() { $(this).css('color', 'red').append('<span>more</span>') }. $(selector, context).later() is similar, but binds to $(selector, context) at call time: $('p').later().css('color', 'red').append('<span>more</span>') is the same as function() { $('p').css('color', 'red').append('<span>more</span>') }

Download the code.



	<div id="example1">
		Example 1: 
		<span>Click Me</span>

	$('#example2').click($('.example:last').later().animate({fontSize: '+=2'}, $('.example:first').later().fadeOut().fadeIn()));

	<div id="example2">
		Example 2: 
		<span class="example">Click Me</span> | 
		<span class="example">Watch Me</span>

One thing that bugged me about my textpopup plugin was that the popup would not necessarily be visible on screen. datepicker moves the widget to a visible spot on screen, which I find very disconcerting. Ariel Flesler's scrollTo was my inspiration, but it scrolls an element so that its top left corner is at the top left of the screen. I want to scroll as little as possible to have the element in its entirety visible. Thus $('#myelement').scrollIntoView().

Download the code.

See the demo.

Continue reading ‘New plugin scrollIntoView’ »