Archive for the ‘Web’ Category

Short and sweet OAuth

Friday, January 22nd, 2010

I recently grew quite frustrated when I had to update Emend’s Twitter bot to use OAuth.

There are, of course, readily available implementations of OAuth in python, even some specifically engineered for App Engine with lovely persistence and caching and KILL ME NOW.

I gave up after a couple hours of staring at this nonsense. I grew so displeased because my app doesn’t need 95% of what these libraries offer. I only need to sign requests with a fixed oauth_consumer_key, oauth_consumer_secret, oauth_token, and oauth_token_secret. However, this simple task would require me to subclass or instantiate several object with Culver’s library, and I can’t even begin to fathom what I’d need to do with Knapp’s offering.

(Aside: if you want to authorize and build access tokens for your app, I highly recommend this excellent OAuth test client)

I finally teased apart the core function of signing requests, thanks in large part to the great reference example. If all you need is to access a protected resource, this will get the job done with a single function call, no object-orientation required.

Source code and unit test of short and sweet OAuth.

IPA TTS bookmarklet

Tuesday, October 6th, 2009

I present the IPA (International Phonetic Alphabet) TTS (text-to-speech) bookmarklet. (Source)

Bookmarklet: IPA TTS (drag to your bookmark bar)

How to use: select any text that contains IPA and click on the bookmarklet. Wait a second for the iframe at the bottom of the page to load.

Try these examples: /ˌɪntəˈnæʃnəl/, /ˌɪntɚˈnæʃnəl/

Custom Wikipedia CSS & Javascript for iPhone

Saturday, August 2nd, 2008

This afternoon I made a custom stylesheet and script to format Wikipedia nicely for me when I am logged on from my iPhone. If you have a Wikipedia account, you can easily use them by adding them to your own monobook.css and monobook.js. Screenshots below.

Hidden Categories in Wikipedia

Saturday, July 12th, 2008

While searching for a list of unwatched articles in Wikipedia (which isn’t published as far as I can tell), I found the category of hidden categories. Interestingly, the “hidden categories” category itself is not a hidden category[1].

[1] Wikipedia Signpost: Role of hidden categories under discussion

What’s wrong with Yelp?

Saturday, May 3rd, 2008

Imagine for a moment that you were a point in multidimensional space, and your nearby neighbors in this space are people that share your preferences for restaurants, bars, and clubs. In this model, a bar you like is very near to you (e.g., by a Euclidean metric), while some place you hate is far away.

This model rules Yelp. A review on yelp is a measurement of the distance between the reviewer and the reviewed. The review will be favorable if and only if the reviewer is nearby the reviewed in the model.

A restaurant (e.g., Bite) gets good reviews because the people that review it know or can guess, before they go there, that they will like it. If they didn’t, the place wouldn’t have such stellar reviews.

So why do some places get terrible reviews? I see cases that would cause this. First, if a new nightclub (e.g., Universal) is still “figuring itself out,” it might attract a lot of people expecting one thing and getting another. In other words, they are not near the place in the model, but they visit it anyway because they think they might. Likely, because the place is so new, many people are testing it out, so you can expect the reviews to be unfavorable, even by the people who are supposed to like it, because the presence of outsiders ruins the whole experience.

In another case, a super-exclusive bar might only cater to a very narrow range of clientele. In other words, you have to be unusually close to this bar in the model in order to like it. Perhaps it only supports one or two cliques of regulars, and everyone else is shunned.

In this example, the radii correspond to the ability of a bar or restaurant to support a wide or narrow section of people.

Dangers of anonymous function closures

Monday, April 7th, 2008

John Resig’s jQuery uses a standard technique of anonymous function closures to namespace its internal functionality.

(function(){
  // jQuery stuff goes here...
})();

This is all well and good until you want to inline this code under some of your application code, as I did while working on Eventful’s MySpace application. Consider this example, written in standard Javascript style.

var foo = function(bar) {
  console.log("foo");
  return bar;
}

(function(){
  console.log("bar")
})();

What do you expect this code to print? If you say “bar”, you’re wrong. It prints “foo bar” because in this context the anonymous function closure becomes a call to the function that prints “foo” and returns the function that prints “bar”, which is then called.

Most of us probably wouldn’t notice what just happened because we are so used to Javascript interpreters automatically inserting semicolons after function definitions.

The danger is assuming, as John Resig and hundreds others have, that your anonymous function closure is the first token in a new line. In my case, it wasn’t. The solution? Either start meticulously sprinkling semicolons in your application code, or just add a single semicolon before your parenthetical block, guaranteeing it’s the first token in the line.

;(function(){
  // jQuery stuff goes here...
})();

Reversed Blogs

Wednesday, August 9th, 2006

Take a regular blog, and flip it around. What do you get? A reversed blog, of course, where vistors write questions or comments and the author anwers. Sounds stupid, but I think people could get a lot of fun and use out of this. I see this manifesting as a single site with multiple instances (e.g. blogger or livejournal), funded by ads, and configurable to control who can ask questions, who can answer, and so on.

Here are a few examples. A couple’s answers their friends’ questions. A researcher’s or expert’s revblog answers questions from others in her field. A CEO’s revblog answers his company’s employees. Changing the parameters around may allow anybody to ask and answer (a forum) or only the author to ask (a traditional blog), but keeping in the spirit of “questions” and “answers.”

For instance, imagine this were a reversed blog where I come up with silly ideas and you tell me if they suck or not. Would that be a good idea?

WikiSyntax

Sunday, August 6th, 2006

I’m working on a Greasemonkey script to add syntax highlighting to Wikipedia in Firefox. The trick is to replace the edit page’s textarea with an editable iframe as the page loads, then you can do crazy fun stuff with the document which I will refrain from mentioning because it’s much too nerdy.

At first I thought an extension was the way to go, but its turns out extensions are aimed at tweaking Firefox’s interface, not fussing with the page. Greasemonkey is perfect for the job, since it basically just executes a script on every page that matches a given pattern. Plus, users don’t have to go through the hassle of downloading crap and restarting the application.

WikiSyntaxThis screenshot shows link underlining, headers, and boldface (i.e., embiggening). I haven’t figured out how to handle styling as the page is edited, though, but once that’s out of the way the rest should just be a matter of regex hacking.

Here is a quick WikiSyntax demonstration.