Thursday, December 24, 2009

How to Use TextToSpeech Feature of Google

Here is how you can make your own TextToSpeech App, using Google's un-documented API.

Google Has an undocumented REST API to get TextToSpeech

http://translate.google.com/translate_tts?q=your+text+goes+here
Here is the HTML Code. Do not miss to see the screen-cast.

<html>
<head>
<title>
Text To Speech Demo
</title>
<script>
function GetSpeech()
{
var framehtml="<iframe src=\"http://translate.google.com/translate_tts?q=";
framehtml+=escape(document.getElementById("mytext").value);
framehtml+="\" </iframe>";

document.getElementById("myframe").innerHTML=framehtml;
/*we are done!!!!!*/
/* we will test now*/
/*wow!!!!! its working :) */

}
</script>
</head>
<body>
Enter your text Here
<textarea id="mytext">
</textarea>
<button id="mybutton" onclick="GetSpeech();">
Click me to get the text
</button>
<div id="myframe">
</div>
</body>
</html>

Here is a screen-cast


Thanks Guys
Happy Christmas

Sunday, December 20, 2009

Jump into 3D maps by calculating orientation

Lets make a VirtualDrive MashUp today. As you know that Google maps API has Street view feature and Live maps has Bird’s Eye view feature. We will mix these 2 things in our mash-up.
Feature of This MashUp will be
  • To Take input as source and destination address.
  • Animate the street view & Bird’s Eye from source to destination.
To get this done you will need direction API to know the path between source and Destination. Eventually Google’s Direction API will do this for us. Direction API returns a PolyLine from source to destination. We will use GDirections.getPolyline() Function. Once you have all the points (Latitude and Longitude) along the path you are all set to go. But wait street-view and Bird’s Eye view are 3D Maps they also have something called orientation .
Bird’sEye View requires only one extra parameter "orientation" which can be
  • North
  • East
  • South or
  • West
Where as Google Street View is more complicated , its requires Yaw and Pitch (i am ignoring zoom level which applies to all kind of maps)
image
Since we will concentrate on driving , we will keep the pitch horizontal i.e. pitch will be zero.
Yaw can be calculated by using 2 points along the path. Yaw is the angle of your driving direction from North, in degrees.
Here is a JavaScript code to calculate Yaw with given 2 values of GLatLng.
(Note that Yaw & Bearing is closely related terms and they are having same value here.)
function GetBearing(GLatLng1, GLatLng2) {

var lat1 = GLatLng1.lat();
var lon1 = GLatLng1.lng();
var lat2 = GLatLng2.lat();
var lon2 = GLatLng2.lng();
lat1 = lat1.toRad();
lat2 = lat2.toRad();
var dLon = (lon2 - lon1).toRad();

var y = Math.sin(dLon) * Math.cos(lat2);
var x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
return Math.atan2(y, x).toBrng();
}
One feedback about street-view API though, function setLocationAndPOV is very mysterious and I could not make it work.
Individual Code snippets I picked from here
  1. Google AJAX Playground
  2. Live Map APIs Sample
  3. movable-type
Now Jump To Demo

And Do ViewSource to see the code.

Saturday, November 21, 2009

Google's "Chrome OS" is Bad Evolution

I am a computer engineer. I will always love to see computing evolving in right direction.
Google Chrome OS is bad for evolution of computing.

Computing evolved with Desktop computing and then web apps. Browser Based apps are always slow and faulty, they can never be as robust as a desktop application can be.

After The invention of web services and REST API, I would love to see web enabled desktop Apps.

I love the concept of Portable Apps , When we mix concept of portable Apps and Cloud Based storage, we can achieve much better results.  BUT Google will never let it happen, they are re-inventing all those age old things again in browser. I have posted a small video response on you tube.

Here it is.

Wednesday, November 11, 2009

Phonetic Translation For Hindi

Hello!! I am an Indian, and for obvious reasons I have many friends on twitter who are also Indian and  we communicate in Hindi very often. Wait!! We don't type Hindi on twitter, because Hindi typing requires a special keyboard (or at least special Input Method), which we typically don't keep with us. Its because we Indian officially work in English Language.

So if you are a foreigner and You see this phonetically typed Hindi, No way you can get it translated to your own language.

So For you I have created a small JavaScript hack so that you can translate Phonetic Hindi into your own language.

This is not for only who are foreigners, If you are Indian & still you have problem in understanding Hindi, here is Tool for you.

Demo

How to develop on your own??

This is a Mashup. I am using 3 different service.

1.Script Convertor

2.Google Translate API

3.YQL (a very useful platform for creating mashup)

To see the source code open the demo page and view source.

I have written only few lines of  of JavaScript to do this.

Sunday, November 8, 2009

Coding Bullshit Meter (Outlook Addin)

I thought this will be fun. We developers often get some mail from corporate management, which are completely bullshit to us. How much bullshit it has?? Lets calculate? To calculate I have created a small outlook Add-in (plug-in) which will Display the bullshit percentage on the ToolBar when you select the mail item.


Some of the keywords its uses to calculate the bullshit is this


synergy,strategic fit,gap analysis,revisit,bandwidth,best practice,bottom line,hardball,out of the loop,benchmark,value added,proactive,win-win,think outside the box,fast track,result driven,empower,knowledge base,total quality,quality driven,touch base,mindset,client focus

This is the first time i am developing any kind of Add-In for any application. I used Visual Studio 2010 (beta) 2010 for developing.

You will get many problems,  when you will develop an outlook plug-in. One of the biggest problem I faced was that "Event of 'Item selection change' was not firing".
this.Application.ActiveExplorer().SelectionChange
I finally come to know that you need to keep a reference of the ActiveExplorer all the time in the class.

Ok, this trick worked!!!

Download Source Code Here

I am not creating installer for this (or any kind of set-up). If at all you want to use this, please download the source code and compile on your machine. You might need Visual studio 2010 for this.

Thursday, November 5, 2009

Simplest Way to Add code review using CodeCollaborator

One of the simplest way to add code review is by doing a diff on 2 folders. Where Folder1 Contains the previous code and Folder2 contains updated code.

Unfortunately the documentation was lil messy and I was not able to do it.


Here is simplest simplest example.

Use command line client of Code Collaborator and type this command
ccollab adddiffs new  Folder1 Folder2

Instead of new, you can write the review number which you have created at your server.

ccollab adddiffs 12345  Folder1 Folder2

I had problem about this, so posting here. May be this will help you as well.

Good thing is smatbears people are on twitter and they helped me.. Thanks guys.


Tuesday, October 13, 2009

Bungee with BungeeAmerica (on The Bridge to Nowhere)

Yes, I am talking about my life time experience of bungee jumping which I did with company called Bungee America.





How to get reservation
--Call them (310-322-8892) and follow the procedure

Experience

  1. Bungee Jumping is awesome, I jumped thrice.  But jumping with bungee America is even cool, because you are 100% safe.
  2. Before reaching to bungee spot, we hiked 5 miles in canyons(deep inside San Gabriell mountains). that was really cool. In-fact I hv never done any hiking like that before. Hiking on the trail, was really adventurous.
  3. First we all reached Azusa, 6th street. From there we drove our car to last parking deep inside the San Gabriell mountains.
  4. From Last Parking lot we all hiked to "Bridge To Nowhere", which is a 5 mile hike, and you will cross the river 6 times. So our shoes gone wet (we all were in Bermuda Pants). This hike takes almost 2 hours of time and very tiring, though there are no steep slope.
  5. We all had our lunch with us, because there is nothing you will get there to eat.
  6. When you will reach there everyone will be excited & when you will go for bungee, everyone will cheer you up. That is cool, because when you are going for something like that you need support of crowd.


Photos
Here you go FullScreen
(Photos are mapped here)
Note: Azusa is a place near to Los Angeles, CA

Friday, October 9, 2009

Small Lil Updates

Not finding enough time to update my blog.
Here is something, (when u don't have anything to read from my blog.)



[Currently I am on a official trip, Here in San Diego,CA. Hectic Schedules]

Thanks
Keep reading my blog.

Saturday, September 5, 2009

What a software engineer can learn from YSR’s death

[Background: YSR was Chief Minister of Andhra Pradesh (state) of India. He died in a chopper crash.]

One of the reason media figured out for YSR death is “he ignored safety processes/guidelines, and he influenced the aviation staff to fly during bad weather condition”.
Now question is whose mistake??
Is it the mistake of CM to influence staff who takes care of safety guidelines? Or it’s the mistake of staff that he got influenced???
I believe it’s the mistake of staff.
Very often this happens in software industry as well, we are given some tight schedule and we are forced to finish it. How you act in such scenario?? Mostly we try to finish that within deadline and we skip essential steps e.g. we skip unit testing, we skip code reviews and all of above we tend to write quick and dirty code.
Before doing anything like that you should ask a question to you.
Which is more dangerous?
· Refusing to work on tight guideline?
· Or writing quick and dirty code, and skipping process guideline?
Act accordingly!!
I personally refuse to work on tight guideline many time, because I think that might annoy my Boss for a moment but when something will go seriously wrong after product delivery, it might annoy whole company.
[sad about the death of a mass leader]

Thursday, August 27, 2009

YQL hack to get DZone popular articles on 1 page

Problem with DZone feed is, it contains the link to DZone page. No way i can jump to article, skipping the DZone page. At the end of this article You will be getting a simple YQL based hack to get a DZone popular links on 1 page linked to original blog page.
Note: if you are not interested in how i got it Jump to Demo.
STEP-1
Using YQL first get the popular links.  using feed table (use YQL console).
URL to popular link feed is http://feeds.dzone.com/dzone/frontpage
So my YQL query will be.
select * from feed where url='http://feeds.dzone.com/dzone/frontpage'

You will get the details of all popular articles linked to Dzone’s page (same as in feed).
I am just interested in links so my YQL will be (replace * by link).
select link from feed where url='http://feeds.dzone.com/dzone/frontpage'
STEP-2
With all those link retrieved in the step-1, get the HTML page out of it. get the title node using an XPath query .
First by simple DOM inspection i can figure out that title node is wrapped in a DIV element  whose class name is ‘ldTitle’.
select * from html where url in (select link from feed where url='http://feeds.dzone.com/dzone/frontpage') and xpath='//div[@class="ldTitle"]/a'
Select format as XML and grab the REST URL
which will look like this
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%20in%20(select%20link%20from%20feed%20where%20url%3D'http%3A%2F%2Ffeeds.dzone.com%2Fdzone%2Ffrontpage')%20and%0A%20%20%20%20%20%20xpath%3D'%2F%2Fdiv%5B%40class%3D%22ldTitle%22%5D%2Fa'&format=xml

STEP-3
Now Time to do some tweaking. if i get this data in XML i have to parse it. if i will get it in JSON, JavaScript will do all the parsing for me. That's why i love JSON.
Now if i get everything in JSON i have to regenerate DOM via a JavaScript code. I am lazy to do even that. So i want result formatted in JSON and DOM section as it is(i.e. in XML).
I can do this by putting a call-back as argument in above REST URL.
so my REST URL will be

http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%20in%20(select%20link%20from%20feed%20where%20url%3D'http%3A%2F%2Ffeeds.dzone.com%2Fdzone%2Ffrontpage')%20and%0A%20%20%20%20%20%20xpath%3D'%2F%2Fdiv%5B%40class%3D%22ldTitle%22%5D%2Fa'%0A%0A&format=xml&callback=loadlist

My call back name is ‘loadlist’. so lets implement this call-back.
which is like this.
function loadlist(data)
{
var content_div=document.getElementById('content');
if(!data.query)
{

content_div.innerHTML="error.. failed to load"
}
else
{
var i=0;
var html="";
for(i=0;i<data.query.count;i++)
{
html= html+data.results[i]+"<br/>";
}
content_div.innerHTML=html;
}
}


To see the full source code, visit this page and view source code. I have implemented extra function ‘track’ for some purpose. .


Sunday, August 23, 2009

7 things I did on my blog, to make it a better place to read

Readability & accessibility for a blog is very important.  You need to give few good reasons to your reader to bring them on your blog site. Today, when technology is really advanced we need to re-look our blog website & think of few additional things.  This blog has all those 7 things, which I am going to discuss. I consider my blog most accessible in all forms. Good theme for readability, easy to share, optimized for speed, accessible on mobile, user can choose to translate in his language & last but not the least user can choose to listen its content.

1. Choose better theme.
This is most basic thing. Clean and neat theme on a blog is very important. White background with black colour text is most appropriate theme.  Do not put too much of flashy advertisements or flashy content, they not only distract & confuse your readers; they also slow down the loading time. This article might help you to choose better theme.

2. Make it easy to share & comment.
Blogging is a form of social media. It’s very important to have better interactivity with your readers.  Comment form must be having various options; user should not be forced to login to put comment. Yes, if don't want any unwanted content to be posted by your readers, your can go for “comment approval” option.
These days’ people love to share blogs on various channels. Add buttons like addthis, dzone, tweetmeme(blogger, wordpress) digg(blogger, wordpress) etc to make it easy to share.

3. Optimize for speed.
Adding to much of buttons, poor theme and gadgets might slow down loading time of your blog site. Here are 3 things you can do to improve performance.

i. Put all unobtrusive scripts at the bottom of page.
As you know most of the gadgets and buttons are based on JavaScript. Adding too much of buttons and gadgets might slow down loading time of your blog.

Any JavaScript block, freezes the loading of rest of the content till complete JavaScript code is not loaded. So you can effectively bring readable content much early, by putting most of the JavaScript blocks at the bottom of the page. Question is how can you decide, what can be kept at the bottom of the page? Any script which only executes when entire webpage is loaded can be brought the bottom of the page. In more technical terms any unobtrusive code can be kept at the bottom of the page.

ii. Use CDN (for better loading time) .
One way to get free CDN is “Google’ App Engine”. Read this article.

iii. Run tests like Yslow or Page Speed.
YSlow and PageSpeed are a plug-ins for Firefox (on top of Firebug). These plug-ins can run a test on websites and can tell you what can be optimized.  They will provide huge list, though you can not achieve all of them easily but if you even achieve 50% of them your website will be much faster than any webpage. If you really want to see most optimized web page see yahoo home page. They have lots of content on the website but still loading surprisingly low.

4. Automated podcast (sometime listening is better).
If you are kind of guy, who write long descriptive content, automated podcasting feature might help your reader to have an option to “listen” rather reading it. Odiogo gives free automated way to get podcast of your blog text. It has built-in text-2-speech feature, which will narrate your blog.

5. Automatically Translatable.
Automated translation might not help a lot, but can be really handy for foreign users. Use Google Translate widget on your blog so that user can easily translate.

6. Mobile readable.
Many people prefer to do blog reading on their mobile. There is an easy way to create mobile version of your website. You can use Mobify, to get mobile version of your blog. Getting mobile version is easy; you can get it in 3 easy steps.

7. Add some fun.
On my blog you can drag those sidebar gadgets, such kind of functionality can help reader to play with your blog.

Thanks for reading, Love to see your comments.

Sunday, August 9, 2009

Top 11 Language Concepts That Every Developer Should Know

There are a few fundamental things we have invented in programming languages,
which was invented at various point of time, particularly by one language and they were later adapted by many other languages.
I am going to list some of them, which have bigger impacts.


DataType
The first and foremost thing which we have ever invented is the data type. Computers were  just a dumb machine, which could only understand the binary sequence. Binary sequence made no sense till it was grouped to form a DataType.
As you know a DataType, is something which groups the binary sequence together and represents some entity in mathematical word OR real word. All depends on its interpretation.
DataType is not just a grouping of binary sequence but also a set of operations which it posses. I mean a DataType definition just don't end with its binary  grouping but also the operation which can be performed on those entities.
Later we have evolved these DataTypes into more complex form. We used mathematics to bring various complex data structures like List, Stack, Queue etc.
Today almost every programming language directly or indirectly have concept of data type.


Pointers
With the invention of computers, we've   also invented the concept of loading and storing data from Hardware. Computers accesses memory by toggling special bit patterns in the  wires (which was called data bus).  This  led to the invention of Pointers in our high level programming languages.
Pointers specially became popular in C programming language. Pointer is one of the most popular programming concepts ever invented.  Other than C language, pointers are supported by languages like C++,C#, Fortran, Pascal. Few dialects of BASIC also supports pointer.


Structured Programming
Most of the programs in the early days were completely relying on GOTO statements, which was a real mess and was making programmers life real hell. Now that's where we have invented the "structured programming " another fundamental programming concept. Through this concept we have brought something called functions, and subsequently we realized the power of abstraction.


OOPs
I think OOPs (Object Oriented Programming) is one of the most popular and ever lasting fundamental concept we have invented in history of programming languages. OOps is an umbrella concept. We have brought many concepts under this.Concepts like Data hiding, Inheritance, abstraction, polymorphisms (static & dynamic) were just the beginning of OOps. OOps is available directly or indirectly in almost all modern languages. Languages like C++, java & c# have brought it a long way.


Regular Expression
Regular expressions provide a concise and flexible means for identifying patterns in string. This is used for searching and replacing special pattern in a string.If your favourite programming language is supporting Regular Expressions, and you are still thinking of learning,then this is the time to go and learn. Regular Expressions are now supported by many languages (almost all popular programming languages). Additionally Regular expression became standard language for many find and replace system utilities. Unix command (utility) Grep is one of the most popularly known Regular Expression based utility. Regular Expressions became so popular concept that many programming languages made it as the part of there language syntax (construct).Languages like  Perl, Ruby and TCL embraced regular expression as their primary language construct.


SQL
With the invention of Relational database, where everything is stored in the form of Tables, SQL type of languages evolved. This was mainly developed for  data query, data update, schema creation & schema modification. They became so popular that it was extended to make procedural SQL.
With the popularity of SQL, recently Google has brought GQL to abstract their Big Table ( a non relational data base). SQL like syntax is also borrowed by yahoo in YQL, to query data from anywhere on internet. LINQ in C#.net, is also inspired from SQL.


Managed Heap
Managed Heap OR Smart pointers, was another revolutionary concept which was invented as a hack of OOps concept (classes ) in C++. This was invented by Microsoft in a concept called COM. Smart Pointer, solved the problem of memory leak .
This concept was later adapted as default language semantic in programming languages like Java & C#. Later this was adapted by many programming languages like VB.net and Managed C++.


XPATH
XPath is another programming concept which was developed to access DOM tree, and became a preferred way to access the XML formatted data. This is another programming paradigm which you should be aware of, If by any chance you work with XML.



Duck Typing
The Term “Duck Typing” is invented by Python, though the concept of duck typing is old and was there in few languages earlier than Python.In duck typing, programmer is concerned with just those aspects of an object that are used, rather than with the type of the object itself.
Let's understand this. Let us say we have a real life object Shape, which knows how to draw itself (with a method draw).  Now in OOps, We enforce this by creating an interface something like IDraw, any anything which can be drawn on the screen must be of type IDraw(i.e It should be inheriting IDraw). I Duck Typing, object can be drawn on the screen as long as object holds the draw method,irrespective of the type of object. DuckTyping removed the dependency of common interface definition, which are typically shared by client and server modules in OOps languages.  Disadvantage of such thing is, programmer will not be able to know at the compile time, that the object is not having the draw method in it. But wait, python does not have compile time, its interpreted language, so all the problem can only be identified during the runtime.
One thing i am sure about DuckTyping is that it is very risky deal when you are building a big (cathedral like) software. But it is very good when you are writing  very small quick and dirty lines of code.
Duck Typing is supported by Python, JavaScript(and similar languages) & C# (for your surprise, read this nice example).
Duck Typing helps a lot in JavaScript, in fact the concept of “JSON based AJAX” is completely based of duck typing.
Duck typing is a very controversial concept, many OOPs lovers hate this concept.


Closure
Some languages (e.g. JavaScript) allows you to define a function inside another function. Closure is the scope, which inner function is having.  Coolest part of closure is, scope remains valid even after outer function have returned.
One of the nice example of closure is this (in JavaScript), Inner function dofading will still be having access to ‘Div_InClosureScope’ even after the Fade have returned.
function Fade(id)
{
var Div_InClosureScope= document.getElementById(id);
var level=0;
function dofading()
{
var hex=level.toString(16);
Div_InClosureScope.style.backgroundColor='#ff'+hex+hex+hex+hex;
if(level<15)
{
level++;
setTimeout(dofading,100);
}
}
setTimeout(dofading,10);
}
In more general term, closure is a special scope, provided to a special instance of a function. In OPPs the member function enjoys closure (data members are in closure scope). Programming language C does not have closure concept at all. Its a most simple and straight language.

Yield
I found this technique first in python.This was not something new, but can confuse most the programmers from c/c++ background. This technique somehow stores state of iterator (I will explain latter), and returns different result at different time, and this is something c/c++ programmers are not used to. Any C/C++ programmer assumes a function is a stateless machine, which can return only one result for given set of argument, no matter how many time you going call that function.


A Python function stack can be unwrapped( retuned) in 2 ways, by a return statement or by a yield statement. A return statement stops the execution of a function (same as in c/c++ ). On the other hand an yield statement halts the execution of a function and store the state, so that when it will be invoked later, execution will start from the same point.


Lets take an example of typical Fibonacci number generator.

#An endless generator
def fibonacci():
i = j = 1
while True:
r, i, j = i, j, i + j #respective assignment
yield r

for rabbits in fibonacci():
print rabbits,
if rabbits > 100: break

Output
1 1 2 3 5 8 13 21 34 55 89 144

Python certainly support, C++ like return statement, but using yield is most efficient for this such generators. All those recursive way of writing Fibonacci number generators are really inefficient( though they look simple).
Yield statement is also supported by C#.net.  Here is one of the nice post about yield in c#. Do not miss!

I love this article, "Life after loops". somehow, its connected to this blog post

Saturday, August 1, 2009

We Code writers are better than Literary Writers

We write to make it readable.
Yes, we spend 20% of our coding time to produce working code, and rest of 80% time in beautifying and indenting our code. We love to make our code more and more readable.

We don't beat around the bush.
We write very specific. We hate un-necessary details. We try to communicate the message (the solution) as early as possible.

We love to keep it simple.
We as a code writer, don't try to complicate things. We feel much better when we see our solution simple. That's why we say KISS (keep it simple, stupid!).

We don't repeat Information.
yes, we believe in DRY (don't repeat yourself) principle. we represent one information at only one place. Though many novice developers make mistake to represent  information twice and thrice in their code. This brings a serious problem.

We don't count pages.
We developers, (true developer) feels very productive when we delete LOC( line of code). Most managers in our company think that LOC is true measure of our productivity, but we don't.  We love to delete code, and our most productive time is spent in deleting Code.

We are open.
As an innovator, we try to present idea, even if we are scared that idea can be stolen. We don't think hiding an idea makes any kind of sense.

We are least bothered, when it comes to plagiarism.
Unlike literary writers, we are less concerned about plagiarism. We love if someone copy our code. We take it as a good news. in-fact the whole open source philosophy is based on it. We just request to mention our name in the code, but if they don't mention we don't bother.

Thursday, July 30, 2009

Few Elegant solutions from Apple (present and future)

Looking at the various patents and products from apple I believe they are most innovative people in the world (of computers& devices).

(Note:Click images to explore more)

iPod Shuffle's VoiceOver SolutioniPod shuffle with VoiceOver icon.
VoiceOver solution provides, a voice based menu to the iPod listeners. Solution looks quite great and you might end up thinking that iPod shuffle has TextToSpeech functionality. But answer is NO. iPod shuffle is still a device which can just play an audio file. The menu items come from the another audio-file which has been synced into your device thru PC. Today your PC is capable of TextToSpeech, iTunes will use this to get the small audio file, which will be the sound of SongName, Artist and etc. (textual information resides in your mp3 file).

 

Movement-Aware Interfaces for iPhones


Isn't It Great to make your icons bigger, when you are jumping or running while using your iPhone. I think  YES,  iPhone will use accelerometer to resize its menu and  other UI elements. 

USB device ejection touch sensor


How annoying is it to do several click on your PC, just to eject your USB device? Its solved!! Apple's USB devices will be having a small sensor to know that when you are going to hold your USB device and probably your intension is to plug-out.

Haptic Feedback for touch screen


Touch screen helped us to utilize the same physical space for different functions. awesome!! But reality is, user never sees what he is going to touch. This is not a problem in hardware keys, because they are embossed and they can be felt. Many other companies have brought the haptic feedback already, but that's actually a joke, they actually vibrates the phone's vibrator when you will tap(or touch). Here is a patent from apple which is going to materialize the haptic feedback in real sense.

Device Settings In smart Headsets


Don't your think EQ (equalizer) settings are more related to your output device than your iPod. YES,  then Apple has made it simple, now there will be smart headsets which can store EQ settings.

Monday, July 6, 2009

2 Steps to make your (blogger based) blog translatable.

Here are the 2 step to make you blog translatable, Like this.

STEP-1
Grab This code
<script src='http://www.google.com/jsapi' type='text/javascript'></script>
<script type='text/javascript'>
google.load("jquery", "1.3.2");
google.load("language", "1");
</script>
<script src='http://jugad.googlecode.com/files/translate.js' type='text/javascript'> </script>

STEP-2
Go to blogger, and "Edit Layout" Section, and choose "Edit HTML".
In Head Section just paste the above code, Save and exit.

Optionally You can also add a title less Gadget of type "HTML/JavaScript" and paste the above code. But it might not work all the time.


Please feel free to leave comment if its not working with you.

For the advanced Users:
I have created a Unobtrusive JavaScript code, Here
This requires Google Language API & jQuery.
First two script block above is to bring jQuery in your blog and then my script to produce a translate "combo box", which can be used to translate your blog.

Demo: Click Here
Source: Click Here

Thursday, July 2, 2009

Quick and Dirty Way of Buffer Serialization in C#

This article will tell you to get raw buffer from the c# structure. Basically C# is a TypeSafe language, it never lets you to access byte-stream of any managed object. But You can still make a raw buffer using Marshal.StructureToPtr Method . Today, In this article I will introduce you to new serialization format called QP-Encoding(Quoted-Printable Encoding). QP-Encoding is old encoding style, but known to very little people. Its very simple to understand.
Its a string formed from Raw buffer, whose every byte is represented by '=XX' way. In QP every byte is represented by =and followed by the 2 character of Hex which tells you the value of that byte. BUT if byte is printable it will be printed as it is.

For Example: a buffer whose byte sequence is 41,4A,4F,08 Then QP could be =41=4A=4F=08 but since 41 4A and 4F is printable character you can also write as ")JO=08" (as a better QP)

Using marshalling technique here you can transform any(almost any) c# managed object into QP string using following function
static public string SerializeBuffer(object obj, ref int size)
{
size = Marshal.SizeOf(obj.GetType());
IntPtr ptr = Marshal.AllocHGlobal(size);
Marshal.StructureToPtr(obj, ptr, true);
byte[] byteArray = new byte[size];
string encode_qp = "";
for (int i = 0; i < size; ++i)
{
byte b = (byte)Marshal.ReadByte(ptr, i);
encode_qp += "=" + b.ToString("X2");
}
Marshal.FreeHGlobal(ptr);
return encode_qp;
}
This is How you can DeSerialize
static public void GetDeSerializedBuffer(ref object Obj, ref string QPData)
{
int size = Marshal.SizeOf(Obj.GetType());
IntPtr ptr = Marshal.AllocHGlobal(size);
for (int i = 0; i < size; i++)
{
Marshal.WriteByte(ptr, i, ReadByteFromQPString(ref QPData));
}
Obj = Marshal.PtrToStructure(ptr, Obj.GetType());
Marshal.FreeHGlobal(ptr);
}

Monday, June 29, 2009

Few more awesome questions..

Thanks for all your appreciation for my last post, Here is some more question, which are more funnier that previous list.
  1. If white house is white, the blue house is blue, and the red house is red. Why green house is transparent?
  2. Why all of the black boxes are painted bright orange?
  3. If there is a substance exist, which can make Black Box indestructible, why not same thing is used to make whole aircraft?
  4. Why black paint smells like a green paint?
  5. Why there is flotation devices under plane seats instead of parachutes?
  6. What's another word for thesaurus?
  7. Why is it that when you transport something by car, it's called a shipment, but when you transport something by ship, it's called cargo?
  8. Why I get a phone call from Vodafone to say my bill was outstanding? (I always say thanks)
  9. I understand money talks, but why it always say "goodbye" to me?
  10. How can a burnt match thrown from a car start a forest fire when 2 boxes of matches, 10 fire lighters & lighter fuel can't light a BBQ?
  11. What will happen if a abortion clinic will have a 12 months waiting time?
  12. Why isn't the number 11 pronounced onety one?
  13. Ever wonder what the speed of lightning would be if it didn't zigzag?
  14. If people from Poland are called Poles, why aren't people from Holland called Holes?

    Saturday, June 27, 2009

    twimr04: Creativity, History & Programming

    Just to remind, twimr is a series of blog posts from me, where i put random stuff. These items are basically collected over couple of weeks, via a special hash tag #twimr. from twitter.

    1. 13 Add-ons to Strengthen Firebug

    2. This is great collection of Old Spy Gadgets Part-1 Part-2 Part-2

    3 . This one is a cool animation using post-it notes. ( titled Deadline)

    imageHere is the making of this video 

    4. Stunning Solar system (Stunning, graphics jus by using (jQuery) JavaScript

    image

    5. Some people think that Twitter invented in 1935

    image 6.Developers this is really nice collection of “Hidden Features Of Perl, PHP, JavaScript, C, C++, C#, Java...”  [Incredibly Useful Lists] 

    7.This is something to do with environment, Build a Greener Charging Station

    Thursday, June 25, 2009

    How to add Tabs on blogger?

    [This is old post, you can follow easy steps , with new blogger template designer here]
    Here is a step by step procedure to add tabs for your blogger.

    STEP-1 Go to Blogger Dash board

    STEP-2 Go to layout section of your blog, and go to edit HTML
    [Save your template, to make sure that if anything will go wrong, you can restore the things back]
    STEP-3: Grab this code
    #tabsB {
    float:left;
    width:100%;
    background:#F4F4F4;
    font-size:93%;
    line-height:normal;
    }
    #tabsB ul {
    margin:0;
    padding:10px 10px 0 50px;
    list-style:none;
    }
    #tabsB li {
    display:inline;
    margin:0;
    padding:0;
    }
    #tabsB a {
    float:left;
    background:url("http://sites.google.com/site/hackbit/tableftB.gif") no-repeat left top;
    margin:0;
    padding:0 0 0 4px;
    text-decoration:none;
    }
    #tabsB a span {
    float:left;
    display:block;
    background:url("http://sites.google.com/site/hackbit/tabrightB.gif") no-repeat right top;
    padding:5px 15px 4px 6px;
    color:#666;
    }
    /* Commented Backslash Hack hides rule from IE5-Mac \*/
    #tabsB a span {float:none;}
    /* End IE5-Mac hack */
    #tabsB a:hover span {
    color:#000;
    }
    #tabsB a:hover {
    background-position:0% -42px;
    }
    #tabsB a:hover span {
    background-position:100% -42px;
    }

    STEP-4 Paste this code(above code) just after body CSS which will look like this
    body { 
    background:$bgcolor; margin:0;
    color:$textcolor;
    font:x-small Georgia Serif;
    font-size/* */:/**/small; font-size: /**/small;
    text-align: center;
    }

    STEP-5 Grab following code (customize the link as per your need)
    <div id="tabsB"> 
    <ul>
    <li><a href="#" title="Link 1"><span>Link 1</span></a></li>
    <li><a href="#" title="Link 2"><span>Link 2</span></a></li>
    <li><a href="#" title="Link 3"><span>Link 3</span></a></li>
    <li><a href="#" title="Longer Link Text"><span>Longer Link Text</span></a></li>
    <li><a href="#" title="Link 5"><span>Link 5</span></a></li>
    <li><a href="#" title="Link 6"><span>Link 6</span></a></li>
    <li><a href="#" title="Link 7"><span>Link 7</span></a></li>
    </ul>
    </div>

    STEP-6 Paste the above code in you HTML template after header section (the line which will look like this)
    <b:widget id="Header1" locked="true" title="Experimenting Blogger (Header)" type="Header">
    </b:widget>

    STEP-6 Done!!, save the template and view your blog
    You can get some different kind of tab design here

    Wednesday, June 24, 2009

    How to translate using Google Translate API ?( why it sucks?)

    Recently Google have launched  Translate API. Which is nice and quick way to get your text translated. This is also good when you are translating HTML formatted text. They will preserve the formatting.
    Here I have quickly created a Hack To enable any document translatable.
    lets assume you have a document likethis.In which every paragraph which requires translation is a div with Id “lang_text”
    <div class="lang_text">
    Just checking that this thing will be translated properly or not?
    </div>

    Now with the help of jQery i will add a DorpDownList just above these div, when you select it will translate the text.
    Simple Translate API works like this
    google.language.translate('This is what i want to translate', 'en', ‘el’,
    function(result)
    {
    if (result.translation)
    {
    alert(result.translation);
    }
    }
    );


    Why it sucks?
    On the demo page, you will see that its not translating the last paragraph. Yes, this where it sucks. It does not translate longer text. WTF?
    Here is complete source. (you can also view source of demopage)
    <html>
    <head>
    <script src='http://www.google.com/jsapi' type='text/javascript'></script>
    <script type='text/javascript'>
    google.load('visualization', '1', {packages: ['table']});
    google.load("jquery", "1.3.2");
    google.load("jqueryui", "1.7.1");
    google.load("language", "1");
    </script>
    <style type="text/css">
    #TranslatedText{
    color: #cc0000
    }
    </style>
    <script type="text/javascript">
    $(document).ready(function(){
    var ele=document.createElement('div');

    $(ele).html('Translate<select class="translate_lan"><option value="en">English</option><option value="hi">Hindi</option><option value="el">Greek</option><option value="sq">Albanian</option><option value="ar">Arabic</option><option value="bg">Bulgarian</option><option value="ca">Catalan</option><option value="zh-CN">Chinese</option><option value="hr">Croatian</option><option value="cs">Czech</option><option value="da">Danish</option><option value="nl">Dutch</option><option value="en">English</option><option value="et">Estonian</option><option value="tl">Filipino</option><option value="fi">Finnish</option><option value="fr">French</option><option value="gl">Galician</option><option value="de">German</option><option value="el">Greek</option><option value="iw">Hebrew</option><option value="hi">Hindi</option><option value="hu">Hungarian</option><option value="id">Indonesian</option><option value="it">Italian</option><option value="ja">Japanese</option><option value="ko">Korean</option></select>');
    $(ele).attr('class','translate');
    $('.lang_text').before(ele);
    $('.translate_lan').change(function(){
    var translate_text=$(this).parent().next('.lang_text').html();
    if(translate_text)
    {
    google.language.translate(translate_text, 'en', this.value, function(result) {
    if (result.translation) {
    $("#TranslatedText").html(result.translation);
    }
    if(result.error)
    {
    $("#TranslatedText").html(result.error.message);
    }
    alert('done');
    });

    }
    });
    google.language.getBranding('brand');
    });
    </script>
    </head>
    <body>
    <div id="TranslatedText" title="Translation">
    Your Translation will appear here
    </div>
    <div class="lang_text">
    This is a simple text
    </div>
    <div class="lang_text">
    Just checking that this thing will be translated properly or not?
    </div>
    <div class="lang_text">
    This is a HTML, <a href="http://www.markandey.com">This is a link.</a> This is not
    a link.
    </div>
    <div class="lang_text">
    Lets test for multiparagraph translation
    <p>
    This is paragraph1</p>
    <p>
    This is paragraph2</p>
    </div>
    <div class="lang_text">
    Description of Service. The API consists of Javascript and associated service
    protocols that enable You to display results from Google ("Google Results") on your
    website or in your application (each, a "Property"), subject to the limitations
    and conditions described below. You are allowed to use the API only to display,
    and to make such uses as are necessary for You to display, Google Results on your
    Property. The API does not provide You with the ability to access, and you are not
    allowed to access, other underlying Google Services or data. 1.2 Modifications.
    Google is constantly innovating in order to provide the best possible experience
    for its users. Google reserves the right to change the form and nature of the Service
    that Google provides (e.g. to charge for access to the API, to set a maximum number
    of Google Results You may access through the API, etc.) with or without notice.
    In addition, Google reserves the right to release subsequent versions of the API
    at any time with or without notice, but in accordance with Section 1.3. If a modification
    is unacceptable to You, You may cancel the Service by removing the Javascript and/or
    other implementation of the API from your Property. If You continue to use the Service
    on any Property, You will be deemed to have accepted the modifications. 1.3 Deprecation.
    If Google in its discretion chooses to cease providing the current version of the
    Service whether through discontinuation of the Service or by upgrading the Service
    to a newer version, the current version of the Service will be deprecated and become
    a Deprecated Version of the Service. Google will issue an announcement if the current
    version of the Service will be deprecated. For a period of 3 years after an announcement
    (the "Deprecation Period"), Google will use commercially reasonable efforts to continue
    to operate the Deprecated Version of the Service and to respond to problems with
    the Deprecated Version of the Service deemed by Google in its discretion to be critical.
    During the Deprecation Period, no new features will be added to the Deprecated Version
    of the Service.
    </div>
    <div id="brand">
    </div>
    </body>
    </html>
    Now Let me guess why it does not work. This API is based on a REST API. A REST API submits the data using a URL
    e.g.
    so certainly you have the limitation of data you can send.
    So beware of such scenario, else you might encounter a hang case, because your call-back will not be invoked!!!

    Saturday, June 20, 2009

    2 must have Bookmarklet for Chrome

    Hey there,
    I believe we miss two good feature from Firefox and IE, which is
    1. Automatic detection of RSS feed link.
    2. Ability to have a portable bookmark (somewhere on the cloud)
    Let me tell you 2 Bookmarklets (What is Bookmarklet?) which will solve your problem.
    1.Google Reader Subscribe Bookmarklet:
    image1. Go to [Google Reader ]—>Settings—>goodies page.
    image 2. Get Subscribe bookmarlet.
    3.Now when every time you visit a blog, to subscribe that just click this bookmarlet. This will automatically detect the RSS link. You can immediately subscribe in your reader as well.
    2.Google Bookmark Bookmarklet:
    Go to Google bookmark account and at the bottom of the page you will find this Bookmarklet.
    image
    Now jus click this Bookmarklet to bookmark anything on Google Bookmarklet.

    Thursday, June 18, 2009

    New WebApps & Gadgets , You can give a try

    Thanks for visiting my blog. If you use Google reader you can subscribe to my blog.
    Here in this post , I am going to tell you few new things which came on web recently. Then I will discuss about new gadgets. Specially how they have impressed me.
    WebApps
    image
    Wolfram|Alpha : This is a new search engine, which can give you accurate facts and figures. e.g when your search “what is population of UK?” you will get an answer as  “60.8 million people  (2007 estimate)”.  I think this is useful in these kind of cases, but it fails when you search “who invented electric bulb?”. This search engine is not of much use. But this has brought healthy competition in the market, to innovate on search engine front.
    image
    Bing : Bing is a new search engine from Microsoft. Its kind of re-branding of live.com. It has few good features. I love the image search on Bing, I just need to keep on scrolling, and I will keep getting the images. this is better than Google because currently image search technology is not accurate,and I often don't find image, for which i am looking for on my first page. So clicking through the pages is really annoying.
    image
    Google Squared: Sometime you want to get your search results in a tabular form, Google has came up with Google Squared to get the search result in tabular form. Try searching “cars” here
    image
    Hunch: This is another, product from founder of Flickr, Caterina Fake. Hunch helps you make decisions and gets smarter the more you use it.

    image
    Acrobat.com: acrobat.com is new office suite launched by adobe. This is another competitor of Google docs. Though there are plenty of online office suite is already available. Like Zoho .
    Gadgets
    image
    iPhone 3GS:This is new iPhone, which is faster than 3G. Has more memory, has more battery life and has video recording. Its has MMS, Virtual keyboard is better one. Operating system on this new iPhone is faster, they have done some kind of optimization, so that UI will be more responsive.
    image
    Palm pre: People are looking palm pre as potential competitor to iPhone. UI wise its really stunning. You van switch between apps without coming to home screen (unlike iPhone). Its has qwerty hardware keyboard. GPS,Video,Music all basic Smartphone feature are there. additionally they have activity cards feature. Which is awesome. You will feel like you are working on laptop.
    image
    Toshiba TG01 (code name Tsunagi) : This is new phone from Toshiba, which has world’s fastest processor in it. Phone is based on QUALCOMM's Snapdragon Platform, which has ARM, 1GHz processor speed. This is the first time any phone is reaching the 1Ghz milestone. This phone has big LCD screen. And cool UI. It is based on windows mobile.
    image
    Viliv X70: This is a notebook without keyboard. This is really cool. Equipped with all features like Bluetooth and all. and its also has GPS.
    image
    Samsung’s Galaxy i7500: This is first Android based phone from Samsung. I feel like this is just the android version of Omnia.
    image
    CrunchPad: The Launch Prototype : TechCrunch is a blog company, which has released a prototype of a e-reader. This is a widescreen e-reader, without mouse or keyboard. Its nice Read more here
    Thanks, That's it . Read about these gadgets & webapps, and if you like it buy them. Specially the people who are still living the life without any Smartphone, they should buy one now.
    Thanks, for reading till end.