When you send a request via $.ajax, $.get, or $.post in jquery, you can test for the HTTP_X_REQUESTED_WITH header, looking for a value of 'XMLHttpRequest', a la:

function isajax() { return ((!empty($_SERVER['HTTP_X_REQUESTED_WITH'])) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'); }

But what happens when you're using the jQuery Form plugin? Normally, things work fine. Below the cut for a serious caveat!

Today I had the opportunity to play with event bubbling and applying generic event handlers. Quick overview on handling them (with jquery!) and which events cannot be cancelled.

Put this in your toolbox

| | Comments (0) | TrackBacks (0)

I'm going to admit to not having used this yet. But having used a lot other solutions (most recently pear Safe_HTML with additional pre/post-processing), this is a breath of fresh air: HTML Purifier

Hello again, Hello World

| | Comments (0) | TrackBacks (0)

hw.jpg

Any programmer has done this one a thousand times. But this one is more fun than I remember this being before.

MT 4.1

| | Comments (0) | TrackBacks (0)

So, I've upgraded to Moveable Type 4.1, and I'm forcing commenters to use on the of the web login services (typekey, oid, etc). If that doesn't cut down on the spammers, then it's time to drop the hammer and put in an anti-spam plugin. But at least now that I am upgraded, getting such a plugin will be easier.

If you use MySQL, note this:


mysql> create database test;
Query OK, 1 row affected (0.01 sec)

mysql> use test;
Database changed
mysql> create table foo (
-> x int,
-> y int
-> );
Query OK, 0 rows affected (0.00 sec)

mysql> insert into foo values (1, 2);
Query OK, 1 row affected (0.00 sec)

mysql> select * from foo;
+------+------+
| x | y |
+------+------+
| 1 | 2 |
+------+------+
1 row in set (0.00 sec)

mysql> update foo set x=5,y=10,x=x+y;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from foo;
+------+------+
| x | y |
+------+------+
| 15 | 10 |
+------+------+
1 row in set (0.00 sec)

mysql>

I bolded the part that bothers me. No warnings. Double-updating the same value in the same row in the same statement throws no warnings (never mind errors!). I haven't checked the ANSI standard to see if this is mentioned, but it sure is worth noting.

I have an iPhone. I'm finding myself very prone to snapping photos now, whereas before I was completely unlikely to tote a camera. I also discovered that Movable Type works just fine on the iPhone, I even posted an entry on my personal blog from it while we were at the ice cream place.

But you know what? I want to put up a photo I just blogged. But transferring a photo via anything but email is a pain. Enter perl. I whipped up a perl script to receive iphone photo email, piped via procmail, and save the photo attachment to a path, then email back the phone address with the filename it used. Just make sure you set the path in the script to somewhere down from your DocumentRoot, and then you can immediately reference the photo with an img tag.

Now I can photoblog directly from the phone, which is pretty fun.

Requires
sendmail (for the outbound msg, but I bet you could adapt any other mail program)
perl
MIME::Parser
procmail

Here's the relevent part of my procmail entry (note that photoblog is an alias that goes to my user account via /etc/aliases):

:0H
* ^TO.*photoblog@ender.com
|/home/matt/iphotoparse.pl

And the code, which you can get here: iphotoparse.pl

Happy photoblogging from the phone.

April 2008

Sun Mon Tue Wed Thu Fri Sat
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30      
Creative Commons License
This weblog is licensed under a Creative Commons License.