Posts

Showing posts with the label programming

Partially rendering Handlerbars from Backbone view

Image
While working on a project I had this situation where I wanted to render a view partially after some ajax is done. In this post I will explain how to render HandlerBar views partially. For the purpose of demonstrate I will simulate delay using setTimeout() function instead of an ajax request. So for an example lets consider following setup 1. Template <script id="PersonTemplate" type="text/x-handlebars-template"> <div> {{firstName}} {{lastName}} <div> <div id="divPartial"> <a href="{{website}}">{{website}}</a> </div> </script> 2. Backbone Model var PersonModel = Backbone.Model.extend({ defaults: { firstName: 'Bharat', lastName: 'Patil', website: '' } }); 3. Backbone view using Handlerbars view var TestView = Backbone.View.extend({ //assign model view instance model: objPerson, //get the...

Step by step Cordova calabash-ios automation

Step by step guide about how to integrate calabash-ios with Cordova in an automated way without opening Apple Xcode. Note: First try steps given on https://github.com/calabash/calabash-ios . If those steps aren’t working for you then try following steps. For me only manual steps given on above link worked. Also this script doesn’t create separate target same as “calabsh-ios setup” command. I also presume that you have already setup your cordova project and nodejs . sudo gem install calabash-cucumber If you get any error then try using following command sudo ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future gem install calabash-cucumber reference Go inside your Cordova project directory npm install xcode npm install fs-extra npm install underscore Download script “cordova-calabash-ios.js” from here and paste it inside your cordova project at www level (not inside www). (Note: This is very primitive script you can modify it according to your n...

DataSync PhoneGap/Web applications using LocalStorage

Recently I have developed a PhoneGap application in which I wanted to synchronize data with server. In this post we will see a simple method to send data from PhoneGap application / Web application using LocalStorage as a queue. Conditions were like below: Store data in queue locally in LocalStorage Sync data with server if online when application comes online it should start syncing the data again if any upon successful sync remove from queue else try again synching one item at a time I have developed this solution using Backbone and Backbone LocalStorage plugin. Lets start understanding the solution. 1. Backbone Model var QueueModel = Backbone.Model.extend({ defaults:{ 'url': null, 'method': null //http method like GET, PUT, POST etc. } }); This model is nothing but representation of ajax settings that can be found here . 2. Backbone Collection used as a Queue which is using Backbone.LocalStorage plugin. You should use singleton p...

How to create syntax highlighter using jQuery

Image
Today I am going to show you how to create a basic code highlighter for website. This UI is actually inspired by sixrevisions.com . I have added functionality of showing line numbers. Following things will be covered How to add line numbers How to highlight single line comments i.e. those lines which starts with // How to highlight comment blocks i.e. those lines which are enclosed within /* */ Live Demo       Download Code To use this code highlighter you have to wrap your code inside <pre> tags. Really there is nothing new in it. It is the same traditional old method. <code> tag is another way of adding code into your post. However there is a difference between <pre> and <code> tag. To give analogy of their working I would give example of <div> and <span> respectively. This means <pre> is a block tag and <code> tag can be used inline. One important thing we need to consider is, in WordPress ...

A simple to use wrapper over Node.JS mysql library

Image
I was working on a project on Node.JS platform. In this project I was suppose to exchange data with MySql server. For this purpose I used two packages which are available in NPM repository, namely, mysql  and mysql-queues . Later is required because former driver yet doesn't support transaction feature of MySql database. If you go through them you will be confused a little bit and will find it difficult to understand in one go. To simplify this situation I created an easy to use wrapper over these two libraries. You can find my wrapper on GitHub by following this link . I am still in progress of making it feature rich. How to use this wrapper: Install mysql and mysql-queues using npm install command. Download wrapper by going on this link . Now you can use it in a way that is specified below: Initialize object var dbClass = require('DB'); var options = {}; options.host = 'localhost'; options.user = 'root'; options.password = 'root...