Posts

Showing posts from November, 2011

JS Automatic Semicolon Insertion

Semicolon; Why should I care? "Javascript is the only language which people dare to use before learning" - Crockford Actually I, myself belong to that category of people whom crockford mentions :) But trying to be out.. So, What's new today? Just a informative writeup about ASI ASI? Ya, Javascript Automatic Semicolon Insertion What is a legal statement in Javascript? Following are some var a=10; a; b++; b+=1; ;;; // 3 Empty Statements +a var a = function() { }; {   a   b   c     }; Lets start Try the following var a=10; function test() {     var b;     b = a;     b+=1 } console.log(a) Even though I didn't insert any semicolon [Statement Terminator] in line 5 and 7, the JS engine never throws an syntax error. Reason: ASI Construct Rules to remember:     ** ASI will insert one for you, if you specify a line terminator @ [no line terminator] mentioned        in the gra...

Making Javascript Good :)

Somethings I learnt from Crockford :) Keep it right always :) function a()  //Seems to be working but not :) {     return     {         name: 'a'     };     } console.log(a().name); function a() {  //Keep braces always right. It works :)     return {         name: 'a'     };     } console.log(a().name); There is no concept of block level scoping in javascript but the syntax exists. So, the former falls in that block hole and returns undefined. It's not c or c++ var i = 'tamil'; for(var i = 0;i < 10;i++){      } console.log(i); This is misleading because declaring 'var i' @ initialization of for-loop doesn't mean 'i' has the scope of the loop & it doesn't interfere with the one out. There is no other scope than function scope in javascript. All our declarations are hoisted up to function ...

A Javascript Introduction

Had a chance to read a nice javascript tutorial on variables and data types :) Let's share :) Q: How will I declare a variable? var variablename; Q: I don't like variablename I wish to have $$$$$, Is it possible? A: Ya you can there is no restriction on varible names except 1. It should start with either a alphabet or $ or _ 2. It should not use any reserve words like function, break, var, etc., 3. It should not use any of the operators [!@#%^&*()-+=] Q: Is there any javascript practise to declare variables? A: The answers is upto you. But most common practise is using CamelCase [Inherited from java] var testvariable; const TEST_CONSTANT; function testFunction() { } testObject = new Object(); Another way is Hungarian Notation - appending type of the field/variable to its name var intAge = 19; //Interger var strName = "xxxx"; //String var bSet = false; //Boolean var fpRate = 12.22; //Floating Point var fMember = true; //Flag Advantage: Fol...

CQL(Cassandra Query Language) Reference

Hi, I think now I'm eligible to publish a blog post regd CQL. I wish this blog to be a tutorial rather a Syntax provider for various CQL queries Points to remember 1. CQL doesn't support Composite Types[likely to chage] 2. CQL doesn't support Super columns 3. Counter values are returned in native format [atleast in php/using cqlsh] Why should I prefer CQL? 1. Readability 2. Ease of use 3. SQL like 4. Stable Support: PHP => My Posts using PHPCassa Python => Refer Here and Download it here Java => JDBC Driver and Example is here Ruby => This might help Creating a Keyspace: cqlsh> CREATE KEYSPACE sample WITH strategy_class = 'org.apache.cassandra.locator.SimpleStrategy' ... AND strategy_options:replication_factor = 2; Note: : => Option Specifier Use a Keyspace: cqlsh> USE sample; Note: Don't forget to USE before use 'Sample' and 'sample' are different. Create Column Family: cqlsh...

Cassandra CQL PHP Part 2

I have explained the way to execute CQL Queries from PHP via PHPCassa in my previous blogpost here  and tutorial on cql queries here It was difficult for me to remember the syntax of update and select CQL queries for Cassandra. Hence I wrote wrappers for them which are listed below Update Counter Query: /* * $counterMap => Associative array of CounterColumn names and corresponding value for given $key * Ex: UPDATE TestCounterFamily SET 'counter'='counter'+1, 'counter2'='counter2'+3 WHERE KEY='test' */ function generateUpdateCounterQuery($columnFamily, $counterMap, $key) { $colArgs = ""; foreach($counterMap as $counter => $value) { $colArgs=$colArgs."'".$counter."'='".$counter."'+".$value.", "; } $colArgs = rtrim($colArgs,", "); return "UPDATE ".$columnFamily." SET ".$colArgs." WHERE KEY='".$key."...

Auto-Complete in Eclipse&Zend

[Try right click on project and see if there is Configure > Add PHP Support, If it is there use it] This is a inference of mine while using Eclipse/Zend as IDE for PHP in linux [Not sure abt windows] I was able to notice that PHP perspective over a SVN checked out PHP project didn't function as it was doing for a regular PHP project created via eclipse. For Ex: 1. No syntax errors where highlighted/notified 2. CTRL press over a variable or a class or a function didn't give the option to navigate to the point its declaration 3. Autocompletion was completely disabled After lots of searching, I figured out that whenever we create a project via eclipse, it will create two configuration files along with it .project .buildpath SVN projects might have these files not being configured properly or might even miss them So, inorder to overcome this, either you can create one by hand or create a new PHP project and export the files you checked out in to the newly creat...