What does "1" + 2 + 3 equal?
We're talking JavaScript here. Kind of a trick question. Given operator precedence, I thought that the addition would have been performed first. For example, if multiplication were involved, it would be done before string concatenation, even if at the end of the statement (see Example C). What does "1" + 2 + 3 equal? You might guess 15, but that would be incorrect. The answer is the string "123." Let's test it and learn about operator precedence involving JavaScript strings.
Example A
var a = '1' + 2 + 3; // equals "123"
document.write(a);
</script>
The code simply runs left to right. And "1" + 2 comes before 2 + 3. What matters is, reading left to right, the datatype mix of the pair of values associated by the + operator. The first pair is "1" + 2, so that is evaluated first. The result of "1" + 2 will then be added to 3.
So here is what happens.
- "1" + 2 runs first and equals "12" because the operand "1" is a string, JavaScript performs datatype conversion on the 2 to convert it to a string "2" and then the + operator does concatenation to produce "12."
- Now, in memory while the program is running, we have "12" + 3 to process next. Again, because one of the operands is a string, JavaScript converts the number 3 to a string and performs concatenation on "12" + "3" to produce the final result "123"
Example B
Another example. Addition occurs among pairs from left to right, eg, 1 + 1 being the first pair, until a string is encountered.
var b = 1 + 1 + '2' + 3; // equals "223"
document.write(b);
</script>
When a string is encountered, the JavaScript interpreter performs concatenation and converts any non-string arguments to a string. The result is 1 + 1 = 2, then 2 + '2' involves a string, so the number 2 is converted into the string '2' and we have '2' + '2' = '22'. Then the final '22' + 3 results in '22' + '3' = '223' and we're done.
Example C
The final example shows how crazy this can be. When concerning addition vs. concatenation, we move from left to right. When other operations are involved, we might start at the end then move left to right.
var c = 1 + 1 + '0' + 2 * 5; // equals "2010"
document.write(c);
</script>
Example C shows that the last pair, 2 * 5, because it involves multiplication, is evaluated first, after which we have 1 + 1 + '0' + 10. Then 2 + '0' + 10. Then '20' + 10 that finally equals '2010' and we're done.
Cold Song – Sting
What power
art thou
who from
below
hast made
me rise
unwillingly and slow
from beds of
everlasting
snow?
See'st thou not
how stiff
how stiff
and wondrous old
Far, far
unfit
to bear
the bitter
cold?
I can scarcely
move
or draw
my breath
Can scarcely
move
or draw
cold my breath
Let me, let me, let me freeze
again.
Let me, let me freeze
again to death.
Let me, let me, let me freeze
again
to death.
maxChar jQuery Plugin: New Release 0.3
Happy New Year!
I can't believe I'm saying this ... due to popular demand ... I have updated maxChar, my configurable jQuery plugin that adds a character counter to Web forms.
Example character counter
New and Improved
New features added in 0.3.0 are:
Overview, Instructions and Examples
See the main page, maxChar jQuery Plugin.
Download maxChar 0.3.0
Download from the jQuery plugins repo maxChar release page.
Bug Fixes
For information about the bugs fixed, see the maxChar bugs page.
Working on next version of maxChar
The new version of maxChar will be coming out soon. I've received a lot of great comments and it's getting mentioned on other sites as well now. This has inspired me to set aside some time for the next version. Here are some of the sites I found that mention my plugin.
Boromir, who art thou?
Oh the things we argue about. Here's an interesting one. Wouldn't movies and books be better if more main characters died? Wouldn't stories be less predictable, thus more engaging? Enter Boromir, Captain-General of Gondor, the heir to the Steward of Gondor, Denethor II. Is the death of Boromir an example of a main character dying? Some say yes, some say no.
We had this discussion at work the other day, and there was disagreement among the men. The two sides bascially split based on the character of Boromir in the book vs. in the movie. Is the character of Boromir played down in the movie vs. the book? Certainly. Peter Jackson has to cut huge parts of the books out of the movies. I read the books a long time ago, in the fourth grade, so I am not the best authority here. I do recall Boromir having, obviously, a lot more scenes in the books than in the movies. One could argue he was a main character in the book but not in the movies. So, his death could be an example of a main character dying in a book, but not an example of a main character dying in a movie.
I argue that, in the movies, Boromir was not a main character. Even in the books, I think of Boromir as a supporting character. He represented Man's corruptibility and although his character was important in that role, it was a supporting role, not a main role. Hey, just because he was in the Fellowship does not mean he was a main character. That's like saying the extra in Star Trek was a main character because he was in the away team. Nope, he was there to die because none of the main characters could die. And that's the issue here. Same with Boromir. He served his purpose in the books and once his supporting role was over, he died. Period.
As another example, take the character of Wash from Firefly. He was definitely a main character and he died right at the end. You have seen Firefly, right? If not, you should. At the end of The Return of the King, Bilbo and Frodo die metaphorically, in my opinion, by setting sail with the Elves. But that's not the same thing.
So, was Boromir a main character? What say you?
Quest for new wireless router
My quest has begun. After years of battle with my router and with Time Warner Austin, I set out again to the front. Time to buy a new router. Unfortunately, I am keeping Time Warner (bastards have a monopoly on my area, but some day ... Your time is coming Time Warner).
Anyway, back to the router issue at hand. I currently have a Linksys BEFW11S4. Over the past couple of years since I ... Speak of the devil. I am not kidding. I just lost my connection and had to power cycle the router. Again. Also power cycled the cable modem.
Router features
So, what do I need in a router? I need something that works with what I have now, a mix of wireless G and N devices. I need a router fully loaded for sharing files at home, connecting via vpn to the office, open for gaming and even for an occasional Website that I am hosting at home, etc. and that I can easily administer via a Web interface. Of course I want the best range and the best security available to consumer-level routers. Do I expect too much? We'll see.
Required features
- Web interface
- VPN
- At least 1 ethernet connection (for Canon MP970 printer)
- At least 1 USB 2.0 connection (for Iomega LDHD250-U external hard drive)
- 1 up connection
- Dual band signals - One signal for surfing and another for streaming
- QoS - Quality of Service is actually a tech term for exactly what it sounds like, a good uninterrupted signal. You can prioritize certain types of traffic, for example, video streaming over Web surfing.
Bonus features
- Integrated cable modem - I've seen this but not sure if it works or not with Time Warner (Grrrr, Time Warner)
- Dual SSID - Allows two wireless networks, one public and one private.
Router reviews
Here are the products I looked at worthy of comment.
- AirPort Extreme Base Station
- Motorola SURFboard SBG900 DOCSIS 2.0 Wireless Cable ModemGateway (Black)
- ZyXEL NBG334W 802.11g Dual-SSID
- ZyXEL X550N
- Netgear Rangemax WNDR3700 Dual Band Wireless-N Gigabit Router
- D-Link DIR-655 Extreme N Wireless Router
As I review each router, I will not discuss every feature. That would take too long. I will discuss the features most relevant in the course of a normal discussion. If a particular required feature is missing, I will stop there in the discussion and call "deal breaker" and move onto the next router review.
AirPort Extreme Base Station
Many people remark on the stability of the AirPort Extreme Base Station from Apple. Plus, it supports having two wireless networks instead of just one like most routers. With two networks, you can have one public network and one private network. Routers that support only one network force you to choose whether to make your network ssid public or private. With dual ssids you can have both. This allows you to setup a guest network for visiting family and friends and have your personal devices/computers on the private network, to prevent guests or neighbors from having access to your shared files, etc. even when they are on your home network. Users on the public network cannot access computers on the private network. But they still have internet access. Cool.
Unfortunately, the AirPort has no admin Web interface. Puzzling. That's a deal breaker. I need to be able to login to the router, forward ports, etc.
Motorola SURFboard SBG900 DOCSIS 2.0 Wireless Cable ModemGateway (Black)
As I am displeased with Time Warner cable, replacing their cable modem with one built into the router intrigued my interest. Would it work better? I'll never know. The Motorola router has no WAN uplink and does not support MAC address spoofing. Maybe I would not need either feature but not having them makes me nervous. Maybe with the built-in cable modem I woudn't need MAC address spoofing? Not sure, just nervous. Deal breaker.
D-Link DIR-655 Extreme N Wireless Router
I almost bought this router. Again, some great customer reviews on amazon, but no dual SSID and some other D-Link products sound shoddy with negative custom reviews. While reviews of this particular router were mostly great, it got a bit nervous. Deal breaker.
ZyXEL NBG334W 802.11g Dual-SSID
The ZyXEL router sounds like a great router and the one I would have bought if I were not interested in N technology. I'll just say it rocks in every other way, and ZyXEL, based on customer reviews at amazon and elsewhere sounds like a great company. But no N support is a deal breaker.
ZyXEL X550N
So, then, you ask, "What about the newer ZyXEL that does have N?" Again, looks like a terrific router but, unfortunately, the new one drops support for dual ssid. Not necessarily a deal breaker, until I found a router that has everything, the Netgear Rangemax WNDR3700.
Netgear Rangemax WNDR3700 Dual Band Wireless-N Gigabit Router
And we finally come to the winner. This router literally has all my requirements and extras. And I found it last, when I about to bite the bullet and buy the D-Link router. Great customer reviews, all the features I could want, and a nice price. I bought it on amazon, then noticed it wasn't in stock. My mistake. I found it in stock on buy.com at $20 more, but I ordered it anyway. I need it now and the price was still decent and well under other seller's prices.
New Macbook Pro laptop

Macbook Pro
I've done it. The desktop is on the way of the dinosaur. Large and still thrilling. But too big to survive in today's world. I had to get a better laptop. My ghettotop wasn't cutting it anymore. Having a desktop is great when you need to sit at a desk. But having to sit at a desk when you need to work is not so great.
So what kind of laptop did I get?
I got a really sweet deal on a new Macbook Pro (MB470LL/A).
It came with just 2GB of ram but I can easily upgrade that when needed. I'm doing a lot more coding now and less graphics work, so I think I'll be fine with just the 2GB. Hah!, "just the 2GB." And it's DDR3 RAM. Nice.
The screen is 15.4 inches. I thought about getting the 17 inch but frankly didn't want to shell out the cash. Besides, I want it to be as portable as possible. If I need a bigger screen at home, I'll have a reason to buy big one
.
The hard drive is only the 5400 speed but like I said, I'm not doing a lot of graphics work. And it's 250 GB, large enough and I already have an external drive. Oh yeh, and it has the SuperDrive for burning.
All I need now is a wireless mighty mouse. I wasn't impressed with the docking station options I found. The word monstrosity comes to mind. The Apple Cinema Display would be nice! But I think I'll find my 15.4 inch screen very comfy. Yeh.
Learning about link building
Allow me to share an overview of what I learned at the SEO link building seminar, "Finding Your Most Valuable SEO Link Prospects, Faster and Easier with Ben Wills." This is my second seminar on link building. The first one was a couple of years ago and I did not get much out of it. This one was different. Speaking to a packed room, Ben Wills presented on tools and techniques for evaluation and getting quality links. What is a "quality link" you ask?
Quality Links
First off, just to be clear: we are talking about links on another site pointing to your site. We are not talking about links on your site in your Web pages. Sometimes that confuses people because a lot of SEO discussion is about improving your own links. Here we want to get links from other Web sites. A quality link will be on a popular Web page. It will bring your site traffic. And it will increase your page's Page Rank on Google.
Top 5 Ways to Measure a Link's Marketing Value
I have blatantly copied this list from the company Ben Wills work for, Ontolo. I am listing just the top 5, but the actual list is the top 16.
- The Link Prospect Page Ranks Top 20 in the SERPs
- Multiple Pages from the Same Domain Link to Top Ranking Sites
- PageRank of Domain/Target Pages
- Social Media Distribution
- Domain Traffic Estimates: SEMRush, Compete, Alexa etc…
Ok, so how can I find quality links
I found out about a couple of ways for finding and evaluating the quality of a page for link prospects.
- SeoQuake, a free Firefox Extension
- Google query modifiers help you search Google for quality link pages
Final Question: How do I get a link?
Getting a quality link has also been a bit of mystery to me, mostly because I have no budget and do not want to just spend lots of money, i.e., buy links. I thought that buying lots of links and learning by trial-and-error, something I could not afford, was the only way. It's not.
- Pay for links (the joke about paid links being like paid sex was hilarious ...)
- Email bloggers and ask for a link. Yes, email them. Make sure it's a personal email, not some automated attack on mankind. Ben's main message here: be nice and courteous and real, and bloggers will respond positively to your emails. Ah ...
Conclusion
This page is just an overview with a few details. I highly recommend attending any link building seminars by Ben Wills. I should also mention Meetup and Dave and Busters and Amy Gelfand. Meetup.com is a great online tool for finding local meetings on a wide range of topics, including Web marketing, Web development, etc. (My wife uses for a local Moms group.) I was suprised at what a great meeting place Dave and Busters turned out to be; I was skeptical but the meeting room was great. Amy Gelfand (Gelfand Design) has a deep interest in Web standards and SEO. I found out about the meeting from her on Facebook.
New jQuery plugin: maxChar
Easily add a max character limit on any HTML input or textarea form field. Also dynamically updates status message countdown to user, eg, "10 remaining" as they type. Has several options. Message is customizable. Correctly handles user events, even paste via right click menu.
Update: version 0.3.0 is out
This post is about the 0.1.0 version. The newest version is now 0.3.0. To see the new version and keep up with future updates, see the main maxChar page.
Features for version 0.1.0 (deprecated, see Update above)
- No JavaScript in HTML tags
- Drop dead simple with sensible defaults or completely customizable with overrides
- Have plural and singular forms of message
- Easily work with multiple target fields, as many as I want
- Properly handle user pasting text via right click menu
- Be able to properly handle updating message
Basic example .. doesn't get any easier than this
The most common use case is to add the maxChar functionality to a textarea, eg, in a comment form. Just load jquery, load the plugin, and initialize it on the target form element while passing the character limit you want to enforce.
Instructions
- Add links to jQuery and the maxChar plugin in your HTML head section.
- In your HTML head section, initialize the plugin in your jQuery ready block.
- In your HTML, just make sure your input or textarea element has the id you passed to maxChar above.
NOTE: although below the only element you create is the textarea element, the maxChar plugin dynamically creates and adds a span element after the textarea element. This dynamically created span element is the container for the updated status message, eg, "N remaining."
Advanced Examples: You want options, you got options
I added the options that made sense to me. Check 'em out.
Option: indicator
The indicator is the HTML element that displays the status message, such as "10 remaining." By default, maxChar dynamically creates a span element with an id="indicator", then adds it in the DOM after the target element, in our previous example, after the textarea.
Sometimes, though, you will want to override the default indicator HTML element and specify your own. Just pass the indicator id as a parameter and maxChar will not dynamicaly create and insert a span element; it will instead update your specified HTML element with the status message.
And in your HTML, add the custom element wherever you want it in your design.
Setting up multiple instances
Using the indicator option is usually mandatory when using maxChar with multiple form fields, since you normally want each field will need it's own indicator. (If you do not specify multiple indicators, all targeted fields with share the single indicator; this would be an interesting design but probably a little confusing.)
And in your HTML, specify your HTML input and textarea and the matching span elements for their indicators.
Options: singularMessage and pluralMessage
You can also change the indicator's status message. By default it says "N remaining" but you can change the text after the number (N) to whatever you want. You can also create singular and plural versions, eg, "2 characters remaining" and "1 character remaining."
Option: spaceBeforeMessage
In addition to changing the status message itself, you can also specify the spacing in front of the message. This option is handy if the status message should, or should not, have a space between it and the textarea or input element. The default is one space character. In the following example I remove any space by setting to an empty string.
Option: rate
The interval at which maxChar runs is configurable. The default is 200 milliseconds. Sometimes you might want to tweak this rate for your own reasons. I found myself setting to different values to get the exact rate I felt was user-friendly. Since you might have your own preference, I made it an option.
undefined method `install_gem_spec_stubs’
If you know what the title of this post means, I'm sorry you are having trouble running rake in your rails project. If you have no idea what I'm saying, consider yourself lucky and move on.
Not a big deal, in the end, but just another pain in the butt that needs fixing. While updating my project from rails 2.0 to 2.3.2 I was greeted, right on cue, with exactly what I expected: an error. Rails is great but it can be love-hate sometimes.
Turns out that when running rake rails:update, to update to rails version 2.3.2, the new boot.rb file is not copied into your project's config directory.
To fix, simple copy vendor/rails/railties/environments/boot.rb to config/boot.rb, overwriting your existing config file.
I also found that I was completely missing the initializers directory in my project's config directory. So I got those files as well by creating a new rails project and copying the whole config/initializers directory into my config directory.

