Sparkle is an Adobe AIR application for code highlighting. It does not depend on any webservice, and hence, can be used in offline mode as well. Sparkle uses awesome Syntax Highlighter by Alex Gorbatchev. You can think of Sparkle as a UI front end for Syntax Highlighter.

Sparkle was born of the need to display syntax highlighted code when

  • it is difficult/impossible to include Javascript in the HTML page
  • one rarely paste code snippets and the does not wants to compromise on page load times
  • display code snippets in RSS feeds

Using Sparkle is damn easy,
  1. Run Sparkle
  2. Paste your code snippet in the text area
  3. Choose code language and theme
  4. Click on Convert
That simple. Move to the Get HTML Code tab and click on Copy HTML to Clipboard. You may need to include the given style sheets somewhere in your HTML code.

Home Page | Download | Source (coming soon!)

Sparkle needs Adobe AIR 1.5 Runtime on Windows, Mac or Linux.

Happy Coloring!

written by Sandeep Gupta

Thursday, May 27, 2010 at 9:53 PM

While working on an Actionscript wrapper for Google Buzz APIs, I hit a road block while authenticating via OAuth. It seems the OAuth header used when making authenticating requests to other Google APIs does not work when sending to Google Buzz API. Here is a sample of the Authorization header that I used to make it work.

Authorization: OAuth oauth_consumer_key=anonymous,oauth_version=1.0,oauth_signature_method=HMAC- SHA1,oauth_token=MY_TOKEN,oauth_nonce=D8CE99A1-B346-9474-1469-D4F370F76F37,oauth_signature=MY_SIGNATURE,oauth_timestamp=1274883043,oauth_ callback=oob 

Just wrap all request parameters with the word "OAuth " (note the leading space, without the quotes) as comma separated values. In your Flex/AIR code just use it as,

request.requestHeaders.push(new URLRequestHeader('Authorization', constructedHeader)); 

I will soon be making the code to the library public.

Keep Watching!

written by Sandeep Gupta

Wednesday, May 26, 2010 at 8:27 PM

A very common task when working with Webservices, is to encode/decode specific URI components, and for there is no direct API in Java for the same, it gets a difficult. Below is the code piece that I have been using for quite some time now.

Hope this helps.

public static final String ALLOWED_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()";

 public static String encodeURIComponent(String input) {
  if(StringUtils.isEmpty(input)) {
   return input;
  int l = input.length();
  StringBuilder o = new StringBuilder(l * 3);
  try {
   for (int i = 0; i < l; i++) {
    String e = input.substring(i, i + 1);
    if (ALLOWED_CHARS.indexOf(e) == -1) {
     byte[] b = e.getBytes("utf-8");
   return o.toString();
  } catch(UnsupportedEncodingException e) {
  return input;
 private static String getHex(byte buf[]) {
  StringBuilder o = new StringBuilder(buf.length * 3);
  for (int i = 0; i < buf.length; i++) {
   int n = (int) buf[i] & 0xff;
   if (n < 0x10) {
   o.append(Long.toString(n, 16).toUpperCase());
  return o.toString();

 public static String decodeURIComponent(String encodedURI) {
  char actualChar;

  StringBuffer buffer = new StringBuffer();

  int bytePattern, sumb = 0;

  for (int i = 0, more = -1; i < encodedURI.length(); i++) {
   actualChar = encodedURI.charAt(i);

   switch (actualChar) {
    case '%': {
     actualChar = encodedURI.charAt(++i);
     int hb = (Character.isDigit(actualChar) ? actualChar - '0'
       : 10 + Character.toLowerCase(actualChar) - 'a') & 0xF;
     actualChar = encodedURI.charAt(++i);
     int lb = (Character.isDigit(actualChar) ? actualChar - '0'
       : 10 + Character.toLowerCase(actualChar) - 'a') & 0xF;
     bytePattern = (hb << 4) | lb;
    case '+': {
     bytePattern = ' ';
    default: {
     bytePattern = actualChar;

   if ((bytePattern & 0xc0) == 0x80) { // 10xxxxxx
    sumb = (sumb << 6) | (bytePattern & 0x3f);
    if (--more == 0)
     buffer.append((char) sumb);
   } else if ((bytePattern & 0x80) == 0x00) { // 0xxxxxxx
    buffer.append((char) bytePattern);
   } else if ((bytePattern & 0xe0) == 0xc0) { // 110xxxxx
    sumb = bytePattern & 0x1f;
    more = 1;
   } else if ((bytePattern & 0xf0) == 0xe0) { // 1110xxxx
    sumb = bytePattern & 0x0f;
    more = 2;
   } else if ((bytePattern & 0xf8) == 0xf0) { // 11110xxx
    sumb = bytePattern & 0x07;
    more = 3;
   } else if ((bytePattern & 0xfc) == 0xf8) { // 111110xx
    sumb = bytePattern & 0x03;
    more = 4;
   } else { // 1111110x
    sumb = bytePattern & 0x01;
    more = 5;
  return buffer.toString();

written by Sandeep Gupta

Saturday, May 15, 2010 at 10:00 PM

Please Note: The post is not meant to offend anyone or to hurt anyone's belief or sentiments. I put here the various theories/thoughts that I have found on this topic in a single plate, and leave it on to you to make your own choice.

In science, all new discoveries, inventions and innovations bolster the already established facts and laws. They are derived from all previous experimentation and in-line with established rules of science. They do not differ unless one is in contradiction of the other. As an example, the discovery of radio waves by Heinrich Hertz was based on earlier discoveries of electricity and magnetism, made by Newton, Young, Huygens, Faraday, Maxwell and others.

Let's go for a walk in the case of Astrology.

Definition of Astrology
As defined by the Wikipedia,
Astrology is a group of systems, traditions, and beliefs which hold that the relative positions of celestial bodies and related details can provide information about personality, human affairs, and other terrestrial matters.

The core beliefs of astrology were prevalent in parts of the ancient world and are epitomized in the Hermetic maxim, "as above, so below"

Astrological systems were developed independently in every culture around the globe. Each was unique to its society. Beyond the need for a calendar, the Egyptian, Persian, Chinese, and Mayan astrological systems have very little in common. Each expands into its own mythology of gods and alchemy.

Today’s western astrology inherits most of its tenants from ancient Mesopotamia (Persia) and has been refined through Greco-Roman mythology with a healthy dash of medieval alchemy thrown in for good measure.

Need of Astrology
The basic need for astrology arrives from the fact that as humans each one of us has an inherent desire of knowing our own future. How would we do in the times to come, and if there is something we can do to prevent misfortune. And thus, we tend to easily dive on anything that has been suggested to indicate the same, be it astrology, palmistry, face reading, vaastu or parrots picking from a pack of cards.

Examining the Science behind Astrology
Almost all astrological systems have their basis on the following pillars,

Planetary System: Astrology accounts for the planets discovered and their influence on each human being. The influence divides into various forces and assumption, which we would talk of later. Astrology has more or less been based on the naked-eye astronomy, and hence, has not accounted for the more recent discoveries. The ancient authors were unaware of any planet beyond Saturn. If planets do cause an influence on our life, why do Uranus, Neptune or Pluto are left out. How about the various moons of planets like Saturn and Jupiter that have been discovered recently, or are yet to be discovered.

Heavenly Bodies: Astrologer's claim that heavenly bodies have an influence on us. Experts question as to why other heavenly bodies, quasars, pulsars, black-holes, or dark matter are not accounted in the system. These bodies were formed from the same source, are composed of the very same fundamental materials of five base elements, and are part of the same universe.

Gravity: Gravity is next big factor in astrology. As per the theory of Gravitation, the gravitational pull between two objects is inversely proportional to the distance between the two objects. It has been proved beyond doubt that there indeed is gravitational attraction between any two given objects. This pulls up another question: the pull between a planet and a human is much much smaller than the pull two humans will exert on each other. Then why is the gravitational pull between humans around us is not considered in the theory of astrology.

The article by Phil Plait's actually does the whole lot of computations between gravitational and tidal forces that act upon us. The upshot of this is, at the moment of birth the gravitational pull of the midwife’s gloves far far far exceeds all of the combined gravitational pull of everything out there in space.

Radiation and Electromagnetic Frequencies: Similar to gravitation, radiation is believed to be the cause because each planet and body emits a frequency that somehow interacts with us. Now in the whole galaxy, considering the target as Earth, the biggest source of electromagnetic force is the Sun. In which case, it comes up as a surprise that much more emphasis is laid on stars than the sun.

Precession of the Earth: The constellations shift by about 1 degree every 72 years, thanks to the drifting of the Earth's spin. The Earth spins around an imaginary spin axis that runs through the North and South Geographic Poles. But it doesn't spin true. If you have ever spun a top, you'll see that this spin axis soon begins to wobble. The spin axis will slowly sweep out a complete circle.

The same thing happens with the spin axis of the Earth - except that it takes about 26,000 years to sweep out a complete circle. So roughly every 2,000-and-a-bit years (26,000 years divided by 12 Houses), the star signs get shifted by one House.

This is not a new discovery. Back in 129 BC, Hipparchus was the first to find this shifting-of-the-stars when he compared the astronomical records with what he saw with his eyes.

Multiple Innovations, Multiple Theories: In most modern western systems there are four classical elements: earth, air, fire and water. Chinese add a fifth element, wood to their system.

They all divide the sky differently as well. The basis for astrology is the zodiac, an arbitrary designation of star groups. An astrologer would argue that it is not arbitrary, but rather equal 30-degree slices of the sky. Arbitrary is used here in the context of "cultural significance." For example is Orion a hunter, a tree, or a sheep? The Greeks, Chinese and Sumerians would answer, "Yes," respectively. Is Orion part of the zodiac? According to western astrology no, but the Chinese see this differently.

In western systems, planets are the main actors, while in the Egyptian system, stars such as Sirius and Rigel have much higher precedence.

The interpretations of various objects in the system are different as well. Planet Venus is considered female in the west, the metal star in Chinese, and the orphan boy in Maasai.

Arbitrary Assumptions:
Why is the time of birth considered the point of deciding factor in astrological predictions? Why not the time of conception? Are foetus somehow exempt from heavenly influence. If yes, will the influence on a human, living in a room surrounded by flesh on all sides, be negated?

Why is the distance between stars and earth not considered? Stars may appear very close in our conical view of the sky, but the distance of one of them could be magnitude different from the one appearing just on it's side. Can two objects with such vast difference in distance transmit same influence on us?

Astrological Research
The National Council for Geocosmic Research, a “non-profit organization dedicated to raising the standards of astrological education and research” published a “research” page and a free program called NeuroNet, that you can download to help you look for correlations between astrological aspects and personality traits. The manual to the program states,
Before the computer era, it was impossible to make proper statistical researches

Astrology Challenge
In 2005, Skeptico carried an Astrology Challenge putting various questions on the table and gathering responses of various astrologers. Responses by Robert Hand, Penny Thornton, and Dorian Gieseler Greenbaum are definitely worth reading. Some excerpts from the replies are as under,
Unfortunately there is an entire academic discipline built around the study of the history of astrology and there are no snappy answers that one can give a skeptic or anyone else for that matter. It is (seriously) a bit like asking a physicist to give a quick answer to the question how strong theory works.

The problem is that it is not clear to many of us that the scientific method is the only source of truth.

if you wish to get the answer to your questions, you are going to have to do the research.

Time Twin Study
The Telegraph once carried a study on time twins. Two time twins (born at the same time), and obviously at the same place, were monitored in a given time-frame. Their birth charts were identical and astrologers were asked to predict their future. The study collected data on how similar or different their days (the future) went.
Dr Dean said the results undermined the claims of astrologers, who typically work with birth data far less precise than that used in the study. “They sometimes argue that times of birth just a minute apart can make all the difference by altering what they call the ‘house cusps’,” he said. “But in their work, they are happy to take whatever time they can get from a client.” ...

Dr Dean said the consistency of the findings weighed heavily against astrology. “It has no acceptable mechanism, its principles are invalid and it has failed hundreds of tests,” he said. “But no hint of these problems will be found in astrology books which, in effect, are exercises in deception.”

Mendeleyev's Argument
The following comes as a very frequent response in support of Astrology.
on the night of February 17, 1869, the Russian scientist Dmitri Mendeleyev went to bed frustrated by a puzzle he had been playing with for years; how the atomic weights of the chemical elements could be grouped in some meaningful way and one that, with any luck, would open a window onto the hidden structure of nature. He dreamed, as he later recalled, of "a table where all the elements fell into place as required."
If Mendeleyev can dream of a periodic table in his dreams, then why can't ancient men dream of astrology? Absolutely valid point.

The hidden question here is, Dmitri Mendeleyev went to bed frustrated by a puzzle he had been playing with for years, what was the puzzle astrologers were trying to solve when they went to bed.

Time for Humour: The Curious case of Parashar Light
Let's examine the curious case of Parashar Light, one of the famed astrology software programs available and it's Frequently Asked Questions. The point in question is, "What causes General Protection Fault". Quoting the answer from the site,
There could be many reasons, ranging from a bug in the software, to your CPU being overheated.

Note: Underline emphasis by me
So as per the developer's of the software, a General Protection Fault can be caused due to the CPU being overheated. As per Wikipedia
A General Protection Fault in the Intel x86 and AMD x86-64 architectures, and other unrelated architectures, is a fault (a type of interrupt) which can encompass several cases where protection mechanisms within the processor architecture are violated by any of the programs that are running, whether it be the kernel or user program.
For the lay man, it is caused due to a program violating the basic notions of processor architecture and is meant to stop such a program from executing further.

At least the reason above brings in some humour in the life of a developer.

Try Yourself
You may try a fun exercise in case you wish. Get hold of a friend and ask him/her the star sign they were born in. Now go ahead and read any one of the horoscope readings given in the newspaper except their owns. Ask what %age of it they found accurate. Now reveal that you were kidding, and this time you are going to read their correct one. Read another one that is again not their own. Calculate the %age. Now reveal the true predictions and calculate the final %age. Check for yourself how each of the three values fare in this war. Better still read all the signs of a newspaper and see how much they apply to you.

Twelve signs, twelve months, twelve types of people.

Debunking the Debunkers
For those who would like to read a response by a Valerie Vaughan as made by him in The Mountain Astrologer (Aug/Sept 1998), follow this link.

For those who would like me to point to other theories/responses/facts/sheets etc, please leave them in comments. I would be more than just interested in reading and thinking through them.

I do not wish to conclude this post, hence, I leave it open-ended for you to make an informed choice.

written by Sandeep Gupta

at 12:41 AM

A wise man once said, Change is the only constant! And today is the day of the change. This blog has a new home,; a new theme with some new colors; and a new name, sangupta. sangupta has been my user id in the online world, and hence, it sticks.

The code pieces have a new home as well,

I plan to put much more new content and thoughts that I encounter each day while playing with code.

Keep Walking and Play Code!

written by Sandeep Gupta

Friday, May 14, 2010 at 9:43 PM