Tuesday, December 15, 2009

A IE, you never cease to amaze and surprise me!

A relatively little known, and even less appreciated, way of doing a for loop in javascript works as follows:
for (key in array) {
   var element = array[key];
   ...
}
You might recognize this as essentially the equivalent of the foreach loop in php and other languages. It's a very useful structure when dealing with associative arrays, or just to save yourself some typing. But along with obscure functionality sometimes "quirks" from time to time. Notably, as usual, in Internet Explorer.

While at work today I was looping through some form elements, in the event the page the script would run on had multiple forms. Though my test page only had a single form element in it, IE gave me multiple additional elements, such as the letter p, and the number 13...

Worse still, it did the same for the form.elements array within an inner loop. I did some investigation and found that this is a bug in IE, and has been around for a while now.

So thank you IE8, for showing us yet again that as far as you've come, you're still the bottom of the proverbial browser barrel.

Also, thank you Doug for also writing a post on this issue... albeit over 3 years ago :P I just felt I should share the fact that this is still very much an issue which IE has, even in its most recent version.

Friday, December 11, 2009

Fun Fact #372

Remember, Javascript, like most languages, short-circuits when dealing with if statements.

What does that mean?

Well for example, when running an OR evaluation with two functions, such as
if(doThis(var1) || doThat(var2){ alert("Woot!"); }
If the first function is true, the second function will not execute.

Something to keep in mind for future reference if you're wondering why your function's not running.

Friday, August 7, 2009

This City is Endless

A rough approximation of my walk today, though out of order for the purposes of Google Maps.

E to D, train to A, Matt got onto the subway to meet Brett at B, and I walked to C for the heck of it, and then D to catch the bus, for a total of about 6 miles, not including wandering around J&R for like an hour, or the walk from 49th street, where I got off the bus, to Bryant Park.


View Larger Map

Saturday, July 18, 2009

Palm Pre: First Impressions

So I've had my Palm Pre for about 4 days now, replacing the dinosaur of a Motorola which I used prior, who's screen had cracked and which crashed and froze on an almost hourly basis.

The main appeal of the Pre, for me, was WebOS. As a web programmer, dangling the carrot of coding embedded apps with my existing skill set is a tempting one (and the same reason that I kinda liked Konfabulator/Yahoo! Widgets). But I'll get to my experience thus far developing for it in another post.

The physical phone itself is very nice, especially when it's closed. It's just satisfying to hold, and doesn't feel bulky at all, even in your pocket. The screen is only a tiny bit smaller than the iPhone, a difference which I can more than live with, and I like having a physical keyboard. I dislike the portrait keyboard though. Every time I use it I can't help but feel a little cramped, and I have small hands to begin with. A Landscape slider would've been way more comfortable. The keys themselves feel a bit too soft too. I'd have preferred harder keys, as I fear these will wear down much faster, since the portrait slider configuration means they're smaller, and I have to hit them with my fingertips. The Ringer Off switch is great though, especially for movies and for the bus (I don't like waking sleeping people on the express bus with my phone, I think it's rude).

The multi-tasking is, by far, the best part about the phone in my opinion. The ability to smoothly move to, use, and control apps feels very satisfying and almost cathartic. Synergy, which was also heavily touted, falls flat in my opinion though. Don't get me wrong, I loved just inputting my Google account info and being done, but as others have mentioned in reviews, it imports ALL of your Google and Facebook contacts, and only merges them on name, not on other reasonable data (like screenname). For me, the biggest annoyance was that it imported my AIM buddy list, which has 200 buddies, half of which are either inactive or I no longer speak to. There's no option to disable this either. If you sign into AIM, your buddy list is just dumped into the phone. I've already organized my Google contacts, and culled my AIM buddy list as a result, and I'm just not going to add my facebook account, but I'll get to that in a second.

You see, my primary problem with the Contacts list is the inability to organize contacts by group. So while even 7 year old phone have friends, family, etc groupings, the Pre does not, even if they exist in your Google contact list. I can only group contacts by Company, and even then, I can't collapse that group, so I have all my former coworkers taking up tons of space at the top of my contacts list, with no way to move them out of the way or close the group if I don't use it often. Don't get me wrong, I could just search for my contact, but I don't always want to have to open the keyboard to do so, especially when the fix for saving much of the room would simply require replacing the "divider" widget, with the "collapsible divider" widget. It's literally a 2 second god damned job.

There's more but that's all I really wanted to talk about at the moment. I just finished working on version 0.1 of the app I'm writing today, so I'm kinda happy about it so far. I'll describe it a bit later on when I have some more free time.

Sunday, June 7, 2009

A Javascript-less Image Viewer

So a while back, I was tasked with making what essentially boiled down to an image-viewer. The catch? I had to make it work without javascript (for Internet Explorer in particular), and it had to be done without reloading the entire page.

Sounds weird, I know, but blame Valve for using Internet Explorer 6, sans javascript, as their HTMLView object in the Source Engine SDK. Anyway... It sounds difficult, but it's really not, it's actually very VERY simple, it's just easy to overthink.

First of all, you're going to have to make sure all of the images are the same size, or at the very least, the same height. You're going to block out the HTML like so:
<div id='slideshow'>
   <img id="image1" src="img\image1.jpg" alt="Image 1" />
   <img id="image2" src="img\image2.jpg" alt="Image 2" />
   <img id="image3" src="img\image3.jpg" alt="Image 3" />
   <img id="image4" src="img\image4.jpg" alt="Image 4" />
</div>
<div id='slideshowNav'>
   <a href="#image1">Image 1<a>
   <a href="#image2">Image 2<a>
   <a href="#image3">Image 3<a>
   <a href="#image4">Image 4<a>
</div>

The key here is the fact that all of the images have their own id values. Now the css is going to look like so:
#slideshow{
   width: Width of your widest image;
   height: Height of the images;
   overflow: hidden;
}

Now the end result is you have the slideshow div acting as a sort of "viewing window" through which you're looking at the images. Each image has an id value associated with it, and clicking the link jumps to that image in the slideshow div.

I should note that last I checked, Opera has a problem with overflow hidden and scrolling, but it's a known bug in Opera and is in fact even a part of the Acid2 test, so I believe Opera 10 should work fine with this trick.

Wednesday, June 3, 2009

The Impossible Octal

Hehe, here's a little trick I learned from TDWTF... Thought it's really less of a trick, and more of an "I can't believe it's that broken" moment.

In the title bar of your browser, add this:
javascript: alert(parseInt('05'));

You get 5, right?
Good.
Now try this:
javascript: alert(parseInt('09'));

Yup, that's right, you get a 0.

Here's the article with the explanation for this odd output:
If you guessed 9, you fail. No, it's zero. See, Javascript supports octal numbers. Any number starting with a zero is octal, even if it can't be an actual octal number. In certain languages, like Perl, trying to use a non-octal number as an octal number results in an error. In other languages, like Javascript, it silently fails.

So, thank you Javascript, for teaching me something I didn't know about you... and making me hate your quirks all the more.

Blogger RSS feeds by tag (aka label)

One thing I wanted to do was have RSS feeds by tag/labels, so that I can use a single blog for the Journal, and tips sections of the site. The url for a specific label in a feed is:
http://yourusername.blogspot.com/feeds/posts/default/-/tag1
If you want to use multiple labels (this one, for example is labelled as 'tips' and 'other'), just add the tag to the end of the url, like so:
http://yourusername.blogspot.com/feeds/posts/default/-/tag1/tag2
This will return all posts which are both tag1 and tag2.

URL file access with a cURL backup

So in the process of getting my website up and running, I ran into the 'URL file-access is disabled in the server configuration' message. Since the server admin was asleep, I figured I'd try to find a workaround. cURL is a commonly used one for this scenario, but the problem is that if you switch hosts it may not be available. As such, here's a handy variable to tell if URL file access is enabled:
ini_get('allow_url_fopen')
It returns true or false depending on the value in the php.ini file, and you can throw it in an if statement to test for it, and use cURL in the else statement in case it fails.

Valid Blogger RSS Output

Having trouble getting your blogger rss output to validate because Google botched the tracking code (lack of alt attribute in the tracking image)?

Do what I did, add this to the php page processing the rss feed:
$entry['content'] = substr($entry['content'], 0, -8) . " alt='' />";
This cuts out the closing img and div tag, adds alt, and closes it all again... just pray google doesn't change it >.>

Tuesday, June 2, 2009

On IE6 and Windows Update

Once upon a time Internet Explorer's ties to Windows and Microsoft were it's biggest strength, but in retrospect, it may have been it's biggest flaw. Numerous people now use FireFox, Opera, Chrome, and other browsers, but none of these have the single most glaring fault that Internet Explorer boasts about like a badge of honor... Windows Update. Firefox and others all update on their own, automatically, and independently (by default), and give the user little reason to disable this behavior. IE, by contrast, updates through Windows Update (I believe it's actually been rebranded Microsoft Update now); a service which many people disable because of the risk of receiving updates which cripple their system (as the WGA check did to some people, even though their licenses were valid). This puts a large portion of IE users out of the reach of the update system, and further widens the chasm between each iteration of Internet Explorer.

The cost to us? Being forced to write pages for a browser so old that when it was first released, George W Bush had just recently become our new President, and was on vacation in preparation for what he expected to be two easy and uneventful terms. Not to mention the thousands, if not millions, of users who view the web with poor css implementation, poor png rendering, broken javascript support, etc etc. So now, with IE8's release, developers are forced to write code for 3 Microsoft browsers which render content in wholly different ways. Don't get me wrong, I'm glad that IE8 has at least taken some steps toward standards compliance, but it's a single step in a journey of miles. It seems to me that the problem isn't moving IE7 users to something better, the problem is moving IE6 users at all.

I hate the word "Blog"

So it's ironic that the backend for this journal will be Google's Blogger. I haven't written in/maintained one of these since I was an angsty teenager. Let's see how this goes.