Archive for the 'web' Category

Craigslist suggestion: pause and resume listings

March 6th, 2007

Here’s a feature suggestion: I’d like the ability to pause and resume a post on Craigslist.

Here’s the scenario:

  • I post an ad in free stuff
  • I get 10 responses immediately
  • I want to stop getting responses until I can deal with the ones I’ve already received
  • If I delete the ad, I can’t repost it for two days (it gets flagged as spamming)

It would be nice if I could pause the ad, either until I resumed it, or for a fixed period of time (1, 12 or 24 hours).

I emailed Craig a few months ago. Perhaps if he gets more requests, they’ll implement this.

JavaScript date validation

March 2nd, 2007

I was searching the web for JavaScript date validation code. All I found were lots of really bad ideas. Some were quite complicated. John Gang was on the right track. I didn’t see Chris Hogben’s article initially, but he used the right algorithm.

Still, nobody offered the complete solution. Given a date string YYYY-MM-DD, is the date valid?

The smart way to do this is to (a) parse the date string with a regular expression, (b) construct a date object and (c) compare what you got out of the date object to what you put in. To make this really convenient, we’ll use JavaScript’s proptotype functionality to extend the String class, making this available to any string:

String.prototype.isValidDate = function() {
  var IsoDateRe = new RegExp("^([0-9]{4})-([0-9]{2})-([0-9]{2})$");

  var matches = IsoDateRe.exec(this);
  if (!matches) return false;
  

  var composedDate = new Date(matches[1], (matches[2] - 1), matches[3]);

  return ((composedDate.getMonth() == (matches[2] - 1)) &&
          (composedDate.getDate() == matches[3]) &&
          (composedDate.getFullYear() == matches[1]));

}

Here’s the method in action:

var a = "2007-02-28";
alert(a + (a.isValidDate() ? " is a valid date" : " is not a valid date"));

My Toronto Star crossword puzzle fetcher

December 26th, 2006

On weekday afternoons, the Toronto Star publishes an eight-page PDF edition, “Star PM.” I download this for one reason: the free crossword puzzle.

But sometimes I forget to download this, and since there’s no archive, I lose the opportunity to do that day’s crossword. So I wrote a script to automatically fetch today’s Star PM and save it to my hard drive. Then, I went one better. Using the CoreGraphics Python module, I remove pages 1-7 of the PDF, so I store only the crossword puzzle. Then, it prints the PDF to my default printer.


## Toronto Star crossword puzzle fetcher
##
## Paul Schreiber <misc at paulschreiber dot com>
## http://paulschreiber.com/
## 1.0 -- 26 December 2006
##
## Licensed under a CreativeCommons-Attribution License:
## http://creativecommons.org/licenses/by/2.5/
##
## Usage: starpm.py <directory to store crossword puzzles>

MySpace and its shit-ass design

August 29th, 2006

Sean Bonner rips into MySpace, calling out its poor usability (far, far too many clicks to do anything). Sean was inspired by Evan Williams’ analysis of how MySpace gets so many page views. Evan was in turn building on Mike Davidson’s analysis. Mike’s characterization of MySpace as an “Unnecessary Click Factory” is spot-on.

Oh, and Mike also shows you how to make a profile that looks anything but shit-ass. Well done!

the magic growing text box

April 17th, 2006

Here’s a text box that grows as you type to hold just the right amount of text:

<textarea name="foo" rows="1" cols="20" onkeypress="resizeme(this);"></textarea>

<script type="text/javascript" charset="utf-8">
// <![CDATA[
function resizeme(t) {
	var characterCount = t.value.length;

	// assuming proportional font
	var columnCount = Math.floor(t.cols * 1.25);
	var height = t.rows;
	var newHeight = 1 + Math.floor(characterCount/columnCount);

	if (newHeight != height) {
		t.rows = newHeight;
	}
}
// ]]>
</script>

Here it is in action:

Using CURL in PHP

April 4th, 2006

In Python, to read a URL, I do the following:

import urllib
data = urllib.urlopen('http://foo.com/').read()

PHP links against cURL, which lets you accomplish the same thing … in five lines of code.

If this is something you plan to do more than, say, once, you’ll want an easier way of doing this. Here’s the function I use:

function readUrl($url) {
	$curlHandle = curl_init();
	curl_setopt($curlHandle, CURLOPT_URL, $url);
	curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1);
	$data = curl_exec($curlHandle);

	if (!$data) {
		print curl_errno($curlHandle) . "  " . curl_error($curlHandle);
		curl_close($curlHandle);
		return false;
	}

	curl_close($curlHandle);

	return $data;
}

(keywords: curl php wrapper example)

the importance of net neutrality

April 3rd, 2006

the execs at the telcos (perhaps the same people whose secretaries print their emails — who knows) have this great idea to make money off the internet: meter everything.

their argument is that google is getting a “free ride” on their network. well, no, they aren’t. they are paying for bandwidth at their end, and you, the end user, are paying on your end as well.

that’s like at&t saying they should get 5% of the profits of every telemarketing call. sigh.

for a great overview of this, listen to Burnie Burns’s SXSW keynote and read Brad Templeton’s essay. (Scot Hacker has notes from Burnie’s talk.)

Better Google Finance URLs

March 26th, 2006

It would be nice if Google Finance allowed you to use easy-to-type URLs, i.e.
http://finance.google.com/goog

Which could redirect you here:
http://finance.google.com/finance?q=goog

Perhaps something like:
RedirectMatch /([a-z]{4}) http://finance.google.com/finance?q=$1

flickr: toys and inspiration

February 21st, 2006

fun flickr toys that let you make calendars, billboards, fortune cookies and more out of your photos.

fantastically beautiful high speed photos of water, sparks and motion. and lightning.

Apple Store bookmarklet

November 21st, 2005

Remix: this movie + WordPress’ PressIt bookmarklet = Apple Store bookmarklet

javascript:if(navigator.userAgent.indexOf('Safari') >=0){
Q=getSelection();
}else{
Q=document.selection?document.selection.createRange().text:document.getSelection();}
void(window.open('http://store.apple.com/1-800-MY-APPLE/WebObjects/AppleStore' +
'?productLearnMore='+encodeURIComponent(Q)));

(I’d make it draggable, but WordPress auto-curly-quoting is being too clever.)

Update: the movie is from Jon Rentzsch.