Posts RSS Comments RSS 129 Posts and 25 Comments till now

Flash for mac is bad for your HTTP_HOST

I’ve been testing the super awesome swfupload code for some projects at work.  I have nice progress bars working and you can queue up multiple files.  It’s sweet.  I tested out my code in Opera, Firefox, Safari 3, IE 7, etc on Windows and Linux.  Working great.

Of course, an hour before an important meeting is when we discover it doesn’t work on any mac browser.  The flash debug output shows our site initialization code is just throwing a fit.  No DB access settings can be found.  Doesn’t make any sense why an HTTP request from flash on a mac would break our app.

Here’s the basics of how our our setup switches dev/production settings:

  1. if ($_SERVER[‘HTTP_HOST’] == ‘example.mydesktop’) {
  2.     // LOCAL DEV SETTINGS
  3. } else if ($_SERVER[‘HTTP_HOST’] == ‘example.com’) {
  4.     // PRODUCTION SITE SETTINGS
  5. }

It makes considerations for www. etc. The problem in this case is that flash is adding :80 to the HTTP Host header. Instead of

GET /path/to/file HTTP/1.1
Host: example.com

Flash for mac likes to add

GET /path/to/file HTTP/1.1
Host: example.com:80

This will cause ‘example.com:80′ to show up in the php $_SERVER['HTTP_HOST'] variable. You can see how this would break simple host detection.

Scrabble word search

While playing scrabulous online recently, I found myself needing a site to search for words that start or end which what I have in my scrabble letters.  I didn’t find anything good so I decided I would write my own. Not sure how to exactly describe the feature, I decided to call it scrabble lookup.  You search for any part of a word, and it gives you lists of all the words that start with that phrase or end with that phrase.  The lists show the length of the word and points earned, assuming no multipliers.  It takes into consideration the maximum number of letters in scrabble which means that some words you would need the blank letters to spell.

And yes, there are words that end in q.

Greasemonkey script for twitter

A few weeks ago I was thinking about how hilarious it would be to view twitter pages with OMG: prepended to all the messages.  I’ve had a post-it note attached to my monitor ever since that has 3 words: twitter greasemonkey omg.

I present my first greasemonkey script: twitter omg.

To be honest, I’ve never actually installed greasemonkey before.  Writing the script was quite fun.  I’ll be looking for opportunities to make a script that is actually useful…

I love code snippet challenges

I stumbled upon a blog with a random code snippet challenge. Here was the problem at hand:

Given a String (x) containing only characters a-z, write a function (f) that returns a base 10 integer, which converts the String as if it were a base 26 numeral. Function f is bijective.

I wanted to give it a stab in javascript not because it sounded particularly difficult but to play with different javascript code styles.  Here’s my 4 versions:

  1. function f(i) {
  2.  
  3.     if (!i) { return 0; }
  4.  
  5.     var parts, n, pow, val;
  6.     parts = i.split();
  7.     parts.reverse();
  8.  
  9.     val = 0;
  10.     pow = 1;
  11.     for (n = 0; n < parts.length; ++n) {
  12.         val += pow * (parts[n].charCodeAt(0) - 96);
  13.         pow = pow * 26;
  14.     }
  15.  
  16.     return val;
  17. }

The first one turns the string into an array and reverses it before doing the math loop. My next try eliminates the array and iterates backwards over the string.

  1. function f(i) {
  2.  
  3.     if (!i) { return 0; }
  4.  
  5.     var n, mult = 1, val = 0, offset = 96, base = 26;
  6.  
  7.     for (n = i.length - 1; n > -1; n–) {
  8.         val += mult * (i.charCodeAt(n) - offset);
  9.         mult = mult * base;
  10.     }
  11.  
  12.     return val;
  13.  
  14. }

Here I’m playing with chaining array functions. While I don’t create an array, this is very similar to the first try.

  1. function f(i) {
  2.  
  3.     if (!i) { return 0; }
  4.  
  5.     var mult = 1, val = 0, offset = 96, base = 26;
  6.  
  7.     i.split().reverse().forEach(function(el) {
  8.         val += mult * (el.charCodeAt(0) - offset);
  9.         mult = mult * base;
  10.     });  
  11.  
  12.     return val;
  13.  
  14. }

Finally, recursion instead of an iterative loop.

  1. function f(i, mult) {
  2.  
  3.     if (!i) { return 0; }
  4.     if (!mult) { mult = 1; }
  5.  
  6.     var offset = 96, base = 26;
  7.     return mult * (i.charCodeAt(i.length - 1) - offset)
  8.              + f(i.substr(0, i.length - 1), mult * base);
  9.  
  10. }

Checkout the test output of my functions. Works in Firefox 1.5+ or other browsers that implement more modern javascript functions. Shouldn’t work in IE.

Quick www. survey

I’ve been trying to pay attention to sites that either add a www or remove www from their domain. For example http://www.reddit.com/ turns into http://reddit.com/ or http://cnn.com/ turns into http://www.cnn.com/.

I’ve been defaulting any new domains I setup to remove the www.  Remember,  www. is deprecated.

Here’s a quick survey of some popular sites:

adobe.com adds www
amazon.com adds www
bbc.co.uk adds www
bloglines.com adds www
blogspot.com adds www
cnn.com adds www
engadget.com adds www
facebook.com adds www
forbes.com adds www
google.com adds www
last.fm adds www
microsoft.com adds www
mozilla.com adds www
msnbc.msn.com adds www
myspace.com adds www
politico.com adds www
salon.com adds www
techcrunch.com adds www
w3.org adds www
washingtonpost.com adds www
whitehouse.gov adds www
wired.com adds www
   
creativecommons.org removes www
digg.com removes www
gizmodo.com removes www
news.yahoo.com removes www
reddit.com removes www
slashdot.org removes www
tinyurl.com removes www
twitter.com removes www
wordpress.org removes www
   
blogger.com no change
boingboing.net no change
boston.com no change
delicious.com no change
flickr.com no change
geocities.com no change
gmail.com no change
imdb.com no change
nytimes.com no change
prweb.com no change
technorati.com no change
youtube.com no change

Belchin’ Waffles is back!

It’s been a year or so since the domains dropped off the face of the Internet (I moved and was too lazy to put them up).  They’re back!

The Original Belchin’ Waffles Zine: http://belchinwaffles.com/

Friend message board (the original twitter, lol): http://friends.belchinwaffles.com/

Douchey party pictures, etc: http://friends.belchinwaffles.com/gallery/

Next Page »