Posts

Showing posts from March, 2012

Cassandra PHPCassa & Composite Types

This post is updated inorder to support phpcassa 1.0.a.1 Cassandra Composite Type using PHPCassa phpcassa 1.0.a.1 uses namespaces in PHP which is supported in PHP 5 >= 5.3.0 Make sure you have the relavant package. The script mentioned below is the copy of PHPCassa Composite Example I will explain it step by step (1) Creating Keyspace using PHPCassa         Name => "Keyspace1"         Replication Factor => 1         Placement Strategy => Simple Strategy (2) Creating Column Family with Composite Keys using PHPCassa         Name => "Composites"         Column Comparator => CompositeType of LongType, AsciiType (Ex: 1:example)         Row Key Validation => CompositeType of AsciiType, LongType (Ex: example:1)         Sample Row:                 'example':1 => { 1:'columnName': "value", 1:'d' => "Hai", 2:'b' => "Fine", 112:'a' => "Sorry" }

Javascript ASI and join vs concat(+)

Javascript Automatic Semicolon Insertion I came across a nice implication of Automatic Semicolon Insertion while developing an API in javascript. I'll let you guess at first as usual. Try the following function asi() { var a = 10, b = 20 c = 30; this.log = function () { console.log(a,b,c); }; this.set = function (A,B,C) { a=A; b=B; c=C; } } var a = new asi(); a.log(); var b = new asi(); b.log(); a.set(11,21,31); b.log(); b.set('This', 'is', 'wrong'); a.log(); //Expected output 10 20 30 10 20 30 10 20 30 11 21 31 //What happened?? 10 20 30 10 20 30 10 20 31 11 21 wrong How Come? First Thing to note: See Closely at line 3 there is a comma operator missing. So, now parser will decide what to do :P Remember: Whenever a statement misses a semicolon and if the statement following it makes sense along with the former. Then JS engine will not place a semicolon. Perhaps it parse them

Is Javascript Pass By Reference or Pass By Value?

Javascript - Pass By Reference or Value? Javascript Types: string, number, boolean, null, undefined are javascript primitive types. functions, objects, arrays are javascript reference types. Difference? One of them is pass by reference and value. I'm Considering string from primitive type and object from reference type for explanation. Try guessing the alerts in the following examples yourself before reaching the answers //Example 1 function test(student) { student = 'XYZ'; alert(student); } var a = 'ABC'; test(a); alert(a); //Example 2 function test(student) { alert(student.name); student.marks = 10; student.name = 'XYZ'; } var a = {name:'ABC'}; test(a); alert(a.name); //Example 3 function test() { var student; return { setter: function (a) { student = a; }, getter: function () { return student; }, change: function () { student.name = 'XYZ';