Posts

Showing posts from 2012

Backbone JS + Chrome App [manifest version 2]

Hello World!!, YAJSBP :) QUOTE: Getting to know a library or a technology is pretty easy, but things get reversed when you want to apply the same which you felt you knew :) In this blog post I'll take you through some integration challenges I faced while developing a chrome app along with backbonejs So, I got to know about this guy Backbone.js an year before at jsFoo 2011. The moment I noticed him, I visited his birthplace and got an overview of him. Then I felt that I could claim I know backbone.js. Later realised it was too early to say that. An year after I decided to try this guy and started developing a chrome app[ Features Recorder ]. Then I faced the following small challenges[on integerating backbone with chrome app] which I solved my own way :P Problem: 1 Chrome App manifest version 2 doesn't allow eval or new Function Error: Uncaught Error: Code generation from strings disallowed for this context Take a look at Chrome app Content Security Policy Why

Asynchronous Javascript & jQuery Deferred Why?

Using jQuery Deferred In this post I'll try to cover an overview of promises and deferred. Further how to use them in nodejs. Define Deferred? Google Define: Put off (an action or event) to a later time; postpone Deferred in javascript? Javsacript being an event driven scripting [and a developing programming] language, there is obvious need for developers to defer things awaiting events. For ex: window.addEventListner("load", function () { console.log("Defer my execution till window load"); }, false); $.ajax({ url: 'data.html', success: function () { console.log("Defer my execution till ajax load is successful") }, error: function () { console.log("Defer my execution till ajax load fails") } }); So? This is nothing unusual!!! Ya, obviously it is nothing unusual and obviously a beginner level fact. Deferred: As a programming paradigm, is a design pattern which solves the problem of code nea

Cassandra Composite Types - A Overview [with CQL & Cassandra-Cli examples]

Just felt like sharing what is composite type in cassandra and How can we make use of it After so many discussions in Stackoverflow and PHPCassa forums, I hope I have got a clear picture over the topic What are composite types? Composite types are like structures in C or C++ For ex: The way we define a linked list [basic] struct LLNode { int data; char name[20]; struct LLNode *next; } Which means every member of this struct will have data of type int, name of type char array and a next pointer of type LLnode The struct is a composite of basic datatypes[not exactly in this case] Also you can't initialize value to any of these attributes when you define a struct The same way Cassandra Composite Type is a dataType derived from existing basic supported dataTypes . Why do we need this? Cassandra initially had and still has the concept of super columns. The basic use of them is maintaining an inverted index . Consider a data model in cassandra ColumnFamily: UserMast

Varnish Cache Purge, Ban and Ban Lurker

Lets walk through some basics of varnish before understanding purge and ban Varnish? From DOC : Varnish is a web application accelarator. Varnish can cache & serve all your static properties [css, js, images, parsed PHP pages, HTML] Reduces load on the webservers even on high traffic. Can act as a load balancer even [provided with proper director configurations]. Varnish uses VCL [Varnish Configuration Language] to override the defaults and tweak varnish based on usecase Varnish caches contents [cache object] against a key. By Default the key is Hash(HostName and Request URL) We can override the defaults by editing vcl_hash sub-routine in vcl file Do Cache objects live long in varnish? In varnish every cache object is stored against a ttl value. Every object will be auto-magically removed out of cache once they reach the expiry. TTL can be configured globally as default while starting varnishd with -t option . Also can be overridden in VCL using bresp.ttl va

npm - package manager for node and package.json a overview

npm: node package manager [!an acronym :P] Till the time I got to know about this guy, code upload across servers use to be a tough task. He is the one to look out incase you are to develop an application in node and host it across servers package.json is his weapon ;) In this article I'm just planning to touch npm basics and use of package.json and it is tl;dr ;) What is npm? From here : npm is a package manager for node. You can use it to install and publish your node programs. It manages dependencies and does other cool stuff. Basically node uses commonjs style module system. Every module is an independent piece of javascript code which can be plugged in and out of the core of your application. Modules can be custom built or built for a generic purpose like redis, mysql, async, log4js. And it will be always good to know if there are any pre-built modules available for our need before we start building our own. npm does it for you like a charm :) How do I instal

Javascript - A Reference for Beginners

Javascript Resources for beginners Javascript is one of the best programming languages that I had come across as a programmer Once I got a chance to know the good parts of javascript from Crockford from this video I got some interest in exploring all that good parts in full. First thing that impressed me from Crockford's presentation was "Javascript is the only programming language which people dare to use before learning it" Till that point I belonged to the same category that Crockford mentioned in the above quote So, I began to spend some valuable time with the language to come out of that crowd As a first thing I read a really nice book "Pro Javascript Techniques" Then, I got a chance to attend a javascript conference jsFoo organised by HasGeek There were really nice and lightning talks on advanced javascript techniques in which I had no knowledge about till that point. I just observed the talks and grasped as much as I could. After

Ubuntu 11.10 Bluetooth Issue & Exploration

Command Line Bluetooth Transfer This blog talks about the way to mount bluetooth enabled mobile phone for file transfer via obexfs and also a very nice way to transfer files without a GUI using sdptool & ussp-push Don't forget the power of sudo whenever you get any permission denied error ;) Since I had upgraded my ubuntu version from 11.04 to 11.10. I never succeeded in sending files via bluetooth to my mobile phone. And finally the day has come, I Googled for the error that I use to get while trying to send files via bluetooth "Permission Denied (13)" and landed Here From there I got redirected to Launch pad where I found many people reporting the same issue. I got a chance to know some decent amount of distinct phone models too ;) And I got him & HEEEE was the Guy whom I was looking for. Also The issue with 11.10 can be resolved by upgrading your blueman service too via ppa I just tried his way $ sudo apt-get install obexfs $ hci

Interesting Javascript Facts

Wishes to the web development world :) In the past 2 to 3 months I had chance to know about loads & loads of innovative JS Libraries All of them made me wonder "Is there a thing that we can't do in JS?" I wish to share some facts which got me mad in to this language & very beginnerish ;) What is {} + []? As soon as I saw this question my reply was "[object Object]" But the real answer was 0 :O Couldn't get any good guess on this, so posted @stackoverflow And I myself couldn't believe I missed it :P {} => Empty Block Scope & +[] => 0 So, cometh thy answer :) Some more of the same kind {} + {} = NaN [] + [] = "" [] + {} = "[object Object]" Why obj === +obj? I found this @ the source of Backbone.js I was wondering why should they check JS number type in such a way? Once again I got back to Stackoverflow The reply once again stunned me up :D It was to save the

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

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           |____ redis                      |____lib/                         ...           |____ my_module