Posts

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)     ...

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';...

CAPTCHA - A Revolution

Image
CAPTCHA = Completely Automated Public Turing test to tell Computers and Humans Apart What is a CAPTCHA? A System built by Luis von Ahn, Manuel Blum, Nicholas J. Hopper, and John Langford of CMU to make sure that user who is active at the other end is a Human and not a bot. This was initially done to prevent bots entering yahoo chat rooms and redirecting the users to someother sites. CAPTCHA - Reverse Turing Test : Yups, CAPTCHA is a reverse turing test because it reverses the role of computers and human. Computer is a device designed to perform what human want it to. But in the case of CAPTCHA it is reversed. It is completely automated, so computer challenges you to perform some action to identify that you are a human. Initially [even now] CAPTCHA was an distorted image with some characters in it which would make lives of bots harder to detect them but which wouldn't affect human though Next generation of CAPTCHA carried a audio link with the distorted image beside to ...

Nodejs Modules and Export Explained

Enjoyed a week playing around with nodejs :) Lets share Simple Node Server [http://localhost:6666]: var http = require('http'); var server = http.createServer(function (req, res) {            // Do Whatever you want               res.writeHead(200, {'Content-Type':'text/plain'});               res.end('Running');          }).listen(6666, function () {                    console.log('Node Runs on port 6666'); }); How to install a node_module? NPM is a powerful package manager for node which you can use to install node modules Ex: npm install redis The above command installs redis module in ./node_modules/redis directory How to use a module? Use require() method Ex: require('redis') How will node resolve the modules? Consider /home/xxx/sample  |___ index.js  |___ node_modules...

HTML Input Place Holder

A Simple way to implement placeholder in a Input Field. Although HTML 5 by default provides placeholders[placeholder attribute], it falls short in Cross Browser Compatibility Construct A Simple Form Username: Let's Implement Placeholders Now [With jQuery] Change the HTML To HTML: Username Result Username Apply CSS and Overlay placeholder over Input Element CSS: .place-holder { position:relative; left:-245px; color:#AAA; z-index:1; } .name-field { width:250px; background:#FFF; z-index:0; } Result Username Handle Focus and Blur Event :) jQuery: $().ready(function () { function hideHolder() { $('.place-holder').hide(); } function showHolder() { if($('.name-field').val() == '') { $('.place-holder').show() } } $('.name-field').focus(hideHolder); $('.name-field').blur(showHolder); $('.place-holder').click(function () { $('.name-field').trigger('focus'); }); }); ...

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...