Friday, May 1, 2009

Use JavaScript to get the position of the caret in a Text Box

If you have an <input type=”text” /> on your web page and that element currently is in focus, you can use this cross-browser function to retrieve the current position of the caret/cursor:

function GetCaret(input)
{
if(document.selection)
{
var range = document.selection.createRange().duplicate();
//moveStart returns the # of characters moved.
return -range.moveStart("character", -input.value.length);
}
else if(input.selectionStart)
return input.selectionStart;
return -1;
}



Internet Explorer doesn't support the selectionStart property used by FireFox (I've heard Opera uses selectionStart and I believe Safari does as well) so instead we get the currently selected range via document.selection, use the selection object's createRange method to create a TextRange object which is what IE uses to manipulate text data. There doesn't seem to be a direct way to get the position of the TextRange within the parent object, but we can use the moveStart method to move the start point of the range. This method returns the number of characters moved, which happens to be the position of the caret - technically the negative of the position of the caret since you had to move the selection backwards to reach the start.



This method could easily be modified to get the ending position of the selection by using range.text in IE to retrieve the text selected (range.text.length would be the length of text selected) or use input.selectionEnd in other browsers.

Friday, April 10, 2009

How to Rearrange Your Start Menu in Vista without UAC

I found a good tip at keyliner.blogspot.com that if you give yourself full access to the folders “C:\Users\Public\Desktop” and “C:\ProgramData\Microsoft\Windows\StartMenu”, you won’t get the UAC nags when you rearrange, delete, or customize items in your start menu.  That was a huge annoyance for me since I like a well organized start menu.

Thursday, March 26, 2009

World of Warcraft Interface Idea

Blizzard should release a change where you could right-click on the map and you automatically run to that point.  It would be easy if you were on a flying mount.

Wednesday, March 25, 2009

The Internet wasn’t built for Media

Online distribution is increasingly popular these days due to streaming services such as Hulu.  It’s easy to watch what you want, when you want it.  Cloud computing is taking us back to client-server days where the “cloud” (a bunch of servers) do all the computing and you interact with the cloud via a browser.  Now there’s even talk about streaming video games.

The problem with online distribution is that the internet wasn’t built for mass distribution.  Every time you request a video, a separate connection is made and the content is sent to you individually.  For a few users or small requests, this works well and efficiently – the content is only sent to those who request it - but when you look at large numbers of users streaming large video files, the system starts to break down.  Each user is using separate bandwidth whether they’re watching the same file or different files.

In contrast, TV services from your cable or satellite company are broadcast based.  They send the same signal to everyone.  They might use a lot of bandwidth sending all the channels to everyone and within each household, the vast majority of this bandwidth is wasted, however it’s much more efficient for a mass audience because the signal is only sent once.  You can choose to tune in to the broadcast or not, but the bandwidth used it based on the number of channels being sent, not the number of users using the service.

The ideal distribution method would be a combination of the two ideas: Allow each user to request content, but allow download sharing.  Rather than sending each packet to each user individually, send each packet once, but specify multiple addresses so the content can be shared.

Wednesday, February 18, 2009

Where’s this cool stuff I keep hearing about?

A short list of the things I keep hearing about and want the most:

  1. An electric car.  Even better would be a plug-in hybrid that can go around 60 miles on pure electric before needing to start the Internal combustion.  That would mean I could go to work and back on electric-only, yet I could still be able to go on longer trips if needed.  If I can’t have that, I’ll take a small electric car to get me to work and back and keep my current car for those longer trips.  Photovoltaics on the roof would be great too – even if it couldn’t fully charge my car while I’m at work, it would still reduce the amount of juice needed when I plug it in.
  2. A new smart phone.  I haven’t decided which one in particular, but I’d take a 32 GB iPhone, a phone running Windows Mobile 6.5 (like the HTC Touch Diamond2 or Touch Pro2) or one of the new Android phones like the Magic.  I need it now, not in Q2!
  3. A flying car.  I’ve been promised one of these in movies since the 80s.  Where’s my flying car?

Thursday, October 16, 2008

We need gender-neutral pronouns

Who's in charge of the English language these days?  I'd like to make a suggestion:  Gender-neutral pronouns.  Back in the old days, it was perfectly acceptable to use male programs (he/his) in times when you don't know the gender of the person you're referring to.  This is standard practice in many other cultures and languages in modern times as well, but with the politically correct nature of modern English, this is often frowned upon and we're forced to result to saying and writing "he or she" or "his or her" to refer to a single person.

What I propose is the addition of a few pronouns to refer to these cases.  I'm leaning towards "ve" for the subjective and "vir" for the possessive, though I'm open to suggestions.

Maybe if we all start using these words, they'll make it into the dictionary.  Rappers make up words all the time.  Why can't we make up some that are actually useful?

Wednesday, October 15, 2008

Listen to what is Said

After watching the debate, as always what stands out in my mind isn't the policies themselves but the way people hear what is said, apply their own fears, selectively filter other information, and regurgitate it to make it totally different.  I also notice that neither candidate's plan is correct - the correct answer either lies in the middle, or is addressed by neither.

I admit I may be biased myself, but I find Obama to be the victim of this phenomenon more often than McCain.  An example:

Health Care:  Obama said he wanted to let you keep and reduce the cost of employer-based health care, but if your employer doesn't offer health care or you don't like the offered plan, you have the option of enrolling in the government's plan.  He also wants to introduce mandates that exclude small businesses, but ensure that those that can afford health care plans actually spend the money to get them.

Through filters and fears, this somehow equates to government-run health care.  This simply isn't true.  What this actually means is reduced cost of health care.  At least on the surface.  The real problems that I notice with his plan are pre-existing conditions and the failure to address the real reason for the high cost of medical care.

I'm not sure on the details with the mandates against exclusion for pre-existing conditions (I advise you to look into them yourself).  If by this, he means that the insurance company must cover your medical needs even if you had the condition before you were covered (though you were likely unaware of the issue), then I agree.  If he's saying that you must give insurance to someone even though they have a pre-existing (and costly) condition that you do know of, then I have mixed feelings.

The problem with known pre-existing conditions is that the cost of treatment will undoubtably be more than the cost of the insurance - the whole reason it's called insurance is that it's something of a gamble.  For most people the cost of the insurance will be much less than the cost the insurance company pays.  This is actually necessary because those that do need insurance will need more than they put in.  Money goes into a pool and is paid out as necessary.  It absolutly should be prevented that an insurance company cut you off if you actually do start needing your insurance.  You're paying for the assurance of health care coverage, you should get what you paid for.  You "won" the gambit, though you probably don't see it that way.

The real reason for the high cost of health care however, is the frivolous lawsuits.  I'm not talking about criminal negligence, though I do think that the amount awarded is typically far too high, I'm talking about the cases of honest mistakes.  If a doctor makes an honest mistake or unintentionally misses something, I don't think a lawsuit is right.  Since your chances if you didn't go to a doctor were 0%, I don't see how you can hold a doctor responsible for a mistake.  Again, in cases of real negligence, it's different.

While on the topic of frivolous lawsuits, that's a big economic issue too.  One of the reasons everything costs so much is because everyone keeps suing everyone else for ridiculous things.  Judges need to throw these things out at the start before the defendent spends loads of money on lawyers or settles to avoid the cost of a trial.  If people weren't awarded for stupid lawsuits, they'd stop spending the money on starting them.