•  Best Games of the Decade

    Best Games of the Decade

    For all the gamer geeks, don't miss any of it. Play.. Play... Play... boys.....

  •  OlivePad vs. iPad 3G

    OlivePad vs. iPad

    Read Insightful article, check out the tech spec of both the gadgets.....

  •  Download Angry Birds

    Download Angry Birds

    A game for geeks, A super addictive game, play on your iphone, ipad, android or your PC.

  •  Pyaaz To Tejas

    Pyaaz To Tejas

    Latest pyaaz ke daam related mess to tejas, where we gonna lend up guys....

  •  Boss and Pals

    Boss and Pals

    My experiences with startup, things i have learned and infer. please correct me if i am wrong ....

  •  A trip to Wagah Border

    A trip to Wagah Border

    My experiences of a trip to the amazing places, Not being a tourist but a Traveler, Sharing my experience with you, whatever I explored.... Don't forget to check out rare snaps of the place.

August 5, 2011

Google Closure vs. YUI Compression

Introduction to both the engines :

Very stupid thing to say that yui was developed by yahoo where google closure is google product. sigh....
Well yahoo guys  claims that yui has a high compression ratio but while trying it out i didn’t found it much. where google did an awesome job here and gave me a full control for the kind of compression requires. Like if i don’t want any AI which optimize my code and just remove the white spaces and logs or comments i just use WHITESPACE_ONLY option and easily do the job. Where yui compression doesn’t have that option to have a control on compression type. But one thing that profitable in case of yui is if you are trying to compress the code on the fly and just get it downloaded on the browser then it way faster then google closure.

What I did :
For YUI compression I used yuicompressor-2.4.7
  • Git checkout to  https://github.com/yui/yuicompressor.git
  • install java on your machine
  • $java -jar e:\yuicompressor-2.4.7pre.jar path/to/file -o path/to/output-file --type js
  • #Done

The code snippet used for the test:
function myObject() {
 this.property1 = "value1";
 this.property2 = "value2";
 var newValue = this.property1;
 this.performMethod = function() {
   myMethodValue = newValue;
   return myMethodValue;
 var myObjectInstance = new myObject();

After compression output :

function myObject(){this.property1="value1";this.property2="value2";var a=this.property1;this.performMethod=function(){myMethodValue=a;return myMethodValue}}var myObjectInstance=new myObject();alert(myObjectInstance.performMethod());

Observation :
Well here yiu din’t done any major things except removing the whitepaces and \n’s.  The var declaration can be minimized if you put up a little bit of your brain and also the object creation can be minimized here. Also changing the name of variables and a cmpression that give them alternate smaller names can reduce the code size by almost 20 to 30 %.

Here comes Google Closure :

Google gives you three levels of compression :
  • Whitespace only
  • Simple(quite similar to yui compression)
  • Advanced

What I did :
curl -s \
       -d output_format=text \
       -d output_info=compiled_code \
       --data-urlencode "js_code@${yourfile}" \
       http://closure-compiler.appspot.com/compile \
       > $outfile

After compression output :

In case of ADVANCE_OPTIMIZATION you got the out put like :
alert((new function(){this.b="value1";this.c="value2";var a=this.b;this.a=function(){return myMethodValue=a}}).a());

Observation :
A code of 270 bytes aprox was reduced to 116 bytes after the advance compression of google closure. Apart from this the variable declaration and namings are changed for the code size reduction significantly. here the factory methods are being used which is a nice way of writing the object oriented code instead of plain structural code. Observe that instead of creating an object for the function the declaration time here Google closure instantiated it, and the sub-method has been called just next to the object declaration.

The inbuilt intelligence of the google closure sensed the end point which is an alert function and the parameter was an instance of an object and its method which returns a value. So the sexiest part of it to declare the entire method as an argument, and the method has been called adjacent to it which reduced the overhead of naming the function and the gecko or webrick needs to memorize the function, where its just declaring the anonymous function.  

Apart from the AI part of it, you might say what if we need to use that same function anywhere else in the code. Answer is google closure senses the function if being used only once, so it tries to make it in-line, else it just try to minimize the code and keep the name of function consistent so that can be used letter in the code. So in this case a definite win by closure.

Now the problem part is doing the aggressive compression is sometimes harmful, in case of debugging in production environment. Definitely google  closure done a lot of things to optimize your code but at the end of the day you need a little extra efforts to understand the flow of your own code, as the change in to the prototypes and declaration part. I didn’t found any of the glitches (thanks to google) in case of type definition or argument part of a method. People can argue about the type checking and what if the arguments get messed up by the AI part of google closure. Google has a solution for that. Check http://code.google.com/closure/compiler/docs/js-for-compiler.html We know that js doesn’t have type declaration, so JSDoc Tags helps to define the type of declaration and it helps closure compiler for better understanding and generating the warnings accordingly. So if you have something in your code like

/** @const */ var a = 10;
// some more code
// other declarations and functions
a = 15;
The closure compiler (in advance mode) will return you an critical error of redeclaration of a content. \

JSC_CONSTANT_REASSIGNED_VALUE_ERROR: constant a assigned a value more than once at line 6 character 2

That helps you a lot to maintain the integrity and avoid code blots. What on earth can be better then something which  helps you to write optimized and efficient code.  

Still in case of compilation profiling of compile time of YUI compressor and Google closure, YUI is on the man-on-top. So if you are planning to integrate the compression in to your deployment strategy like while deploying making a URLfetch and getting the compiled compressed code, then deploy it on staging or production, will take a little longer in case of google closure, where YUI will be a faster solution. Second if you can compromise with the deployment time then using the advance optimization of google closure is always the better solution.
...Read More

July 9, 2011

Games : No More Cleavage Show - But More Blood

About the recent supreme court orders for violent games,  Bennett Haselton writes about the court decision consistency and awkwardness. "I'm glad the Supreme Court struck down the California law against selling violent video games to minors, but reading over the decision, I had the odd feeling that the arguments by the dissenters made more sense than the majority — mainly because of the hypocrisy of continuing to ban sexuality while giving violence a pass."

John Landis said, "R is when you bare a woman's breast, PG is when you cut it off."  Apparently now also the law of the land regarding games, according to the Supreme Court's June 27th decision (PDF) over-ruling a California law that banned sales of violent video games to minors. While reading the actual decisions and aruments it seems like a complete show of hypocrisy when they treating sex as more taboo than blood baths.

Steven Breyer wrote in his argument about the decision : "But what sense does it make to forbid selling to a 13-year-old boy a magazine with an image of a nude woman, while protecting a sale to that 13-year-old of an interactive video game in which he actively, but virtually, binds and gags the woman, then tortures and kills her? What kind of First Amendment would permit the government to protect children by restricting sales of that extremely violent video game only when the woman -- bound, gagged, tortured, and killed -- is also topless?" Here he makes more sense,   But he i want to add one more thing, There are games where the objective of missions to Rape a native American woman like "Rapelay", and to "Kennedy assassination" sort'a games, how they make sense to sell these games to a 13 year old boy, what we are teaching him ? biology and history in such a way ? 

John Stewart made a point with a Mortal Kombat scene where two nasty guys can grab a female opponent by the legs and violently rip her in half from the crotch on up, blood flying everywhere, and that was supposedly fine, but if there was even a bit of a pixelated nip slip; they will ban it .

May be here i sound a little racist but the fact I come up with is normally American citizens gets upset by seeing the naked human body, while being more relaxed about exposing their children to simulated or virtual violence. Guns and bazooka are ok, bare bodies ... nooooo. I think its a cultural thing When Janet Jackson showed a nipple in a tv show at superbowl, the USA threatened to riot and completely shocked for this shameful behaviour by the public figure, because it might damage their kids for rest of their life. We Indians laugh on this: on billboards, you can see posters of half naked people selling cosmetics and the big glittering posters of naked chicks on the streets of las-Vegas, but why they were so much worried for the Janet Jackson's show? 

Same with Indians, when it comes to sexuality and exposure we become very strict but the truth is Indian porn market have a good reputation all over the world? Then who watch such films and videos? Aren't we also in such category of Hippocratic people? In India, you grown enough to choose your government at the age of 18 but you aren't old enough to hold a drink. 

No matter what you think or what court think about sex and violence, that isn't the matter i am writing about. I want to put up a question here whether there should be special and separate rules for games! If California government passes a rule against the nudity in games, where supreme court overruled it. At present time there are various medium are there to reach such violent and sexual things to reach to the masses, And there will be more in coming time, Do we really want exclusive rules for all such mediums?  There should be consistency in every such rules and regulations for every medium of communication - broadcasting - entertainment. Don't you think so ?  
...Read More

CWE/SANS : Top-25 Nasty & Dengerous Programming Errors

Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
Buffer Copy without Checking Size of Input ('Classic Buffer Overflow')
Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Missing Authentication for Critical Function
Missing Authorization
Use of Hard-coded Credentials
Missing Encryption of Sensitive Data
Unrestricted Upload of File with Dangerous Type
Reliance on Untrusted Inputs in a Security Decision
Execution with Unnecessary Privileges
Cross-Site Request Forgery (CSRF)
Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Download of Code Without Integrity Check
Incorrect Authorization
Inclusion of Functionality from Untrusted Control Sphere
Incorrect Permission Assignment for Critical Resource
Use of Potentially Dangerous Function
Use of a Broken or Risky Cryptographic Algorithm
Incorrect Calculation of Buffer Size
Improper Restriction of Excessive Authentication Attempts
URL Redirection to Untrusted Site ('Open Redirect')
Uncontrolled Format String
Integer Overflow or Wraparound
Use of a One-Way Hash without a Salt
...Read More

Do you have a google private profile ?

Google announced that it will no longer support private Google Profiles after July 31, 2011. The move comes as Google jumps out with its latest social experiment, Google+. Those who have already been moved to Google+ will see their Google+ profiles replace their Google Profiles. At the moment the only information Google requires users to reveal is their name and sex. 

A fellow guy was telling me the last day, "I hate social networks, don't fall for them. Make
Real friends."

I said may be they are as odd as you, But in my case all of my friends are on facebook, and I can't see anything wrong to keep in touch with them on social networks. Thats the way I come to know each and everyday what they chattering about, where they are hanging out, and who is with who's chick after the recent breakup. I have lived in 9 cities across india, and luckily was succeeded to make friends out there. I can't call them for no reason, and its difficult to say even a hello while having a hectic professional life. Why to be "so-difficult" to your friends, and just have a social profile and stuff like that, and make out? Sometimes they plain old forget that they have to tell me via a different means than everybody else. So I do mention, my profile is on Facebook, find me there alive. And if everyone moved to Google+, or just in case to some other social network  I would probably have to follow them. My parents, they're not on any social network, and actually they have no reason to join like You (The fellow, I was talking about). 

P.S. Thanks Mom and Dad for not being on social  networks, because i don't want you to know that what I was doing and Julie's place last night.

"Not Being Social"
I wonder when people saying they don't want to use social networks. I have been with a lot of marketing analysts - and I am pretty sure that they know where the target people are and in few countries including USA they just buy demographic data for pennies. And thats how our society is evolving right now. Why in just 3 days vizualize.me got 4 million email id's ? how you come to know that there are sim cutters available for your iphone which your uncle bought it from Europe? How you come to know that your girlfriend is cheating on you ? (well a bad example for demographic data, but its a fact)  

Some people say  i don't want to build a farm or Interested in facebook credits. I agree for some people its irritating thing, but why they just can't block it? and continue commenting on neighbor's daughters status, (I found it really interesting :P). Any which ways social networks are mend to keep the contact with friends you have or people you know, its not for making new friends. If you don't like mutton, that doesn't mean you start hating the entire market which has a mutton shop over there. 

P.S. Its a mistake to judge the whole system by some edgy cases.   

...Read More

April 20, 2011

Engine Yard : Background Jobs (!BJ)

Background Job processing is all the tricky and freaky for the developers (AtLeast for me as i had a lot of hiccups while doing that). A lot of people "blah.."ing but never found any good article on the background job. 

Working in nextLeap as Engineering Lead. I came across some of the points which needs to be considered because scaling and the response time is the most critical issue for us. Getting rid of the heavy task while requesting and done in background is the key factor for scaling Any webapp. So just came into my mind to write the guideline and things needs to keep in mind while writing the BJ err.... Background jobs. 

1. Stay in Limits dude !!

Background jobs are there to do heavy tasks, DB queries, binary read and writes or may be multimedia generation or whatever and there can be more stuff. User has to wait till the job completion and if you cant wait then BJ is better option the BJ(Background jobs). Yea, but scheduling them is the responsibility of developers, in such a way that it could reduce the time. Well scheduling and the crons can help on this a lot. For example If you are on to writing 5 different binary files of a size of avg 10 MB / every hour, your maximum (average) execution time for your background job is five to six minutes (As it includes db queries or the required data fetching + the writing latency) First know your required maximum number of jobs at a time which will help you to figure out the resources and the job to be done on time.  Rails background jobs needs to be understand very well before writing em. Else one err and the data can be lost or failed job can create a mess in some cases. Like in case of generating reports, if you are doing it on the fly and making it downloadable for the user, and suppose there is an error in logic, it will break everything, the report will be useless and the CPU cycles and the api calls are completely wasted. (And remember you are paying the clouds for each and every single call).

2. What about the load testing buddy…Are you done with it ?
Load Testing
How can you forget the load testing? Oh because you dont have heavy databases for now. So is there any plan when your databases will grow?  understanding the resource utilization of your jobs is extremely important. Know how much memory and CPU your most frequently utilized job consumes, resource utilization of every job is available in engine yard dashboard. For more information on cloud prising i found this article very useful http://cloudpricecalculator.com/blog/ Its good to put some benchmarks on the background jobs. Good news is Engine yards supports that.  

When you benchmarking the background jobs, you must use production data not the development data as if its of no use you cant do a load testing on it (Untill you don't have lods of data in development env), if there is high memory uses and your jobs are still slow, review and refactor the code using your brain as far as you can. (Oh la la that rhymes) for large objects try reducing the size by optimizing the queries and avoiding unnecessary  data which doesn't needs to be process at all. Make sense ?

3. High rate of job failures (Shit.. Shit.. Shit..)
Fixing the Buggy Jobs
Till now we are talking about the optimization and refactoring stuff, but what if your job fails?  No worries it happens. but is that the failure ratio is too high? Simple answer  is you wrote a shitty code that breaks every other time. Dude the managers will scold you for this, whenever wherever they see "Something broken".
Well we are using exception notifier so before "they" knows we get the email and starts fixing it up ASAP. And managers will give you the applauses because you already know about the broken thingie. Good Job Mike ;) 
Well make sure you can stop those jobs temporarily which cause high amount of  failure alerts. By default engine yard deletes the failed background jobs. So its good to disable the feature. Only if you are on verge to fix it.
4. Spoilers
 While working on google appengine (I hate people who call it GAE which sounds like "gay"), i have seen a very common glitch with Deferred Tasks (Delayed jobs). Its uses UTC time which always needs to be considered as your local time can be different then UTC.  On Engine yard Monit or God config takes care of it, keep your mind-eye-figures open while configuring those. It may cause issues with job failing.

Loading all the libs and full rails environment increases the cost. So be aware of what you need and when you need them. For this read the manual of rails development environment. (As i am too lazy to extract the and write here ) Keep your rails version updated. But there is a spoiler, some of the new versions of rails are not backward compatible. So schedule the time when you don't have major releases, for the sake of up-gradation process.

Some of the jobs can be splitted into two or more sub-tasks. If possible then go for that. It will reduce the time. 9 mothers cannot make a baby in 1 month, but you can blessed with 9 babies if you worked "hard" and did a good overnight "job".

Final Speech.  (Don't worry i'm not gonna die after this)

Time and resources needs to be manage accordingly. It depends on The kind of project you are working on and the kind of teammates you dealing with. Thankfully Nikhil Lanjewar is there. The failures cannot be avoid completely but what is to be a good engineer is to have less exception mails in the in-box. After applying all the above suggestions  if you are no more receiving exception alerts that doesn't mean that i am the hero or you did a great job. there might be your background jobs are not running at all :P
...Read More