Monthly Archives: October 2009

Javascript Tip: Convert string to unicode values

The following script will convert a string to the unicode values using javascript.
toUnicode is a extension to String.charCodeAt. The benefit of this function is that it returns the whole string a html unicode format.

Code

1
2
3
4
5
6
7
8
String.prototype.toUnicode = function () {
    var uni = [],
        i = this.length;
    while (i--) {
        uni[i] = this.charCodeAt(i);
    }
    return "&#" + uni.join(';&#') + ";";
};

Here’s another method that I thought of.
This one is using a regexp instead of a while loop and an array to form the unicode text.

1
2
3
4
5
String.prototype.toUnicode = function () {
    return this.replace(/./g, function (char) {
        return "&#" + String.charCodeAt(char) + ";";
    });
};

Usage:
Call toUnicode() on any string object.

1
obj.toUnicode();

Example:

1
<li/>”.toUnicode() //outputs: &#60;&#108;&#105;&#47;&#62;

However, if possible use document.createTextNode to insert text instead of converting it to unicode. Document.createTextNode is a native DOM method meaning it’s a lot faster, and easier to understand .
More infor here: document.createTextNode

Larry Battle

I love to program, and discover new tech. Check out my stackoverflow and github accounts.

More Posts - Website

Follow Me:
Twitter

The Key to Success

A basic guide to success.
The key to success is hard work, healthy body and mind, network of support and an education.
Before you start, you must have a goal in life. This is what you will be working towards.

  • Hard Work: Maintaining self confidence and motivation is the first start. Next planning and being proactive will help you towards achieving your goals.
  • A Healthy Body and Mind: What goes in, is what goes out. Thinking positive, eating right, and exercising, will increase your energy, performance and brighten up your days ahead.

    Self- Esteem & Confidence:
    How To Have A Healthy Body And Mind
  • A Network of Support: The people you know is a main factor of success. You take on your surroundings, mainly your environment and your social network. If you want success, avoid negative surroundings. And join positive ones with people who have already achieved your goal.
    How to Network
  • Education: Knowledge is power. Don’t do something without first understanding it. Therefore do research before starting a project.

With these simple tips, you can change your life and achieve your goals.

Larry Battle

I love to program, and discover new tech. Check out my stackoverflow and github accounts.

More Posts - Website

Follow Me:
Twitter

How to get the cheapest Airfare ticket.

Traveling is always fun, but paying for the ticket isn’t.
Having flown around world on a budget, I’ve learned a lot about getting the best bargains.
The following are tips for finding the best airfare price online. Using these tips will save you hundreds or thousands on you next flight.

Cheapest Ticket = “Buying time” + “Flexibility with dates” + “Type of ticket” + “Airfare Website”

  1. Buying time:
    – Purchase your ticket within a month or two before your departure, 2 weeks the latest.
    During this period canceled and undesirable tickets become available.
    – Search between 11 pm – 3 am for tickets.
    Because of the low traffic, the airfare sites normally offer lower rates. Therefore, avoid buying during daytime, as business is booming and the discounts become hard to find.
    – Search for bargains throughout the week at different times of the day.
    This helps you get a better image of the pricing.
  2. Flexibility with dates:
    – Play around with the dates to find the cheapest match.
    Generally, leaving between Sunday – Wednesday gives the best results, as most people choose to fly towards the end of the week. To make up for the slow days, airlines offer lower prices to attract more customers for the start of the week.
  3. Type of ticket:
    -Choose an Economy and Round trip ticket.
    Economy is the cheapest ticket you can get. Round trip tickets are filled with discounts. So for a one way trip, sometimes the round trip is the cheaper one to get.
  4. Airfare website:
    – Compare with different airfare sites.
    Kayak.com is the best out there because they offer price history, tracking, and more features to make life easier. Other sites include orbitz.com and priceline.com.
    Also, try to pick a big airport that is close by, as bigger airports are cheaper than small ones.
    NOTE:
    * Double check your websites before buying anything from them. Google their history to avoid scams!
    * Double check the ticket before buying it. Make sure it’s the right one because most of the time it’s non-refundable and cost money to change.

Lastly, you get what you paid for. Slow down and take a 10 minute break before buying anything. Make sure it’s something you can live with and not too stressful to handle. So make sure your trip doesn’t include 3 stops with a 20 hour wait in between.

Like what you read? Then bookmark me below and tell your friends. 🙂

-Larry

Larry Battle

I love to program, and discover new tech. Check out my stackoverflow and github accounts.

More Posts - Website

Follow Me:
Twitter

Add me to your LinkedIn.

Hey everyone,
I’m trying to form a bigger network on linkedin.com.

linkedin
linkedin

So if you would like to help, add me to your connection list. Thanks.
Larry Battle’s LinkedIn Profile.

Larry Battle

I love to program, and discover new tech. Check out my stackoverflow and github accounts.

More Posts - Website

Follow Me:
Twitter