Dec 06 2007

mod_rewrite & PHP: How to match urlencoded plus sign (+ = %2B)

Tag: Apache, PHP, Programmingjs @ 9:37 pm

I ran into trouble when trying to pass a urlencode()‘ed plus sign into a web address being processed by mod_rewrite.

$url = ‘http://www.server.com/browsealpha/name+has+plus+in+it/’;
$url = urlencode($url); // http://www.server.com/browsealpha/name%2Bhas%2Bplus%2Bin%2Bit/

This $url variable gets echo()’d as a link in a page, so once it’s clicked and loaded in the browser, I then needed mod_rewrite to translate that to the actual URL, which is:

http://www.server.com/browsealpha.php?name=name%2Bhas%2Bplus%2Bin%2Bit

Here is the RewriteRule I was using to match:

# match any name containing any combination of letters, numbers, and the % sign (to match urlencoded URLs)
RewriteRule ^browsealpha/([%\w]*)/?$ /browsealpha.php?name=$1 [QSA,L]

This rule should match http://www.server.com/browsealpha/name%2Bhas%2Bplus%2Bin%2Bit/ but for some reason it wouldn’t work. After hours of frustration, I found a few threads mentioning the need to urlencode the string twice, like so:

urlencode(urlencode($variable));

IT WORKS!!! Apparently this is because mod_rewrite automatically decodes the urlencoded URL, so if you pass in %2B, PHP sees it as %2B0. If you double encode, mod_rewrite decodes the first one, and PHP receives the second one (which is now %2B, which is what we want).

—————-
Now playing: Autechre - 444
via FoxyTunes

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Dec 04 2007

jQuery: How to set one <select> element to the value of another (using onchange equivalent)

Tag: JavaScript, Programming, jQueryjs @ 5:33 pm

Say you have an HTML <select> form element and you want to set another <select> element equal to the first one when it changes. Here’s an easy way to do so with jQuery:

$(’#id_of_select1′).change(function() {
    var select1_value = $(this).val();
    $(’#id_of_select2′).val(select1_value);
});

—————-
Now playing: Drexciya - Astronomical Guidepost
via FoxyTunes

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Dec 04 2007

jQuery: How to get the ID of your current object.

Tag: JavaScript, Programming, jQueryjs @ 4:14 pm

Say you want to know the ID of your current jQuery object. You can achieve this easily using jQuery’s attr() method:

var current_id = $(this).attr(’id’);

This will only work provided that you have a valid jQuery object $(this) that you are working with, eg:

$(document).ready(function() {
  $(’input.text’).focus(function() {
    $(’input.text’).removeClass(’onFocus’); /* remove focus state from all input elements */
    $(this).addClass(’onFocus’); /* add focus state to currently clicked element */
    var current_id = $(this).attr(’id’);
  });
};

Using the code above, you will now know the ID of the currently focused input element. This can come in handy later on if you want to perform further actions on the element.

—————-
Now playing: Amon Tobin - Precursor (feat. Quadraceptor)
via FoxyTunes

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Nov 29 2007

Thunderbird HowTo: Show email count in folder pane.

Tag: Mozilla, Thunderbirdjs @ 4:18 pm

If you’d like to see a count of how many emails are contained in each folder in Thunderbird, here’s how:

  1. Tools > Options > Advanced > General
  2. Check “Show expanded columns in the folder pane”
  3. Click OK to accept changes.
  4. At the top of the folder pane, click the column selection icon (Thunderbird Folder Icon) and select the columns that you would like to see. You can choose to display Total, Unread, and/or Size.

—————-
Now playing: Physics - First 7″ - Side 2
via FoxyTunes

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Nov 28 2007

Crusty Old White Dude Ratio: Democrats vs. Republicans

Tag: Politicsjs @ 6:14 pm

Using the pictures below, I’ve calculated the crusty-old-white-dude ratio for both the Democrats and Republicans in the 2008 Presidential Campaign debates:

Democratic crusty-old-white-dudes: 5/8 = 62.5%
Republican crusty-old-white-dudes: 10/10 = 100%

Click photos for bigger versions:

Democrats:
Democrats
Republicans:
Republicans
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Nov 28 2007

Squarepusher Q&A

Tag: Musicjs @ 5:42 pm

Squarepusher Q&A
Came across this pretty fuckin-a-awesome Q&A session with Squarepusher on the BBC site. At some points he comes across as a rambling human thesaurus, at others an enlightened philosophy Ph.D., and still others the manical musical genius we’ve grown to love. I’d love to sit next to this dude in a pub and chit-chat for hours over some cold ones. Choice quote:

I’m interested to further my knowledge in [the cocktail] department, but as I live in a tiny Essex village with one pub that struggles to serve a decent pint of beer, my day-to-day chances of achieving this seem slim.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Oct 30 2007

iPod stuck with Apple logo on screen

Tag: Apple, Hardware, Tech, iPod/iTunesjs @ 12:12 pm

My 3G iPod got stuck with the Apple logo on its screen. The way to fix this is to put the iPod into Disk Mode and restore it from there. Here is how:

  1. Reset the iPod by holding down the Menu and Play buttons simultaneously.
  2. As soon as it reboots, hold down the Fast Forward and Rewind buttons simultaneously.
  3. Your iPod will now be in “Disk Mode” and you should be able to plug it into your computer, open up iTunes, and restore your iPod.
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

« Previous PageNext Page »