Regex useful tricks with Lookahead and Lookbehind

Lookahead and Lookbehind in regex : Lookahead and lookbehind, collectively called “lookaround” is a very useful concept at times which would be otherwise next to impossible to solve by any other means. Found a great article explaining the cases where we can use this: Regex – Lookahead and Lookbehind Zero-Length Assertions

Few useful bits to understand the concept :

Related image

Image result for lookahead and lookbehind in regex

Image result for lookahead and lookbehind in regex

%Q, %q, %W, %w, %x, %r, %s

You can find some useful shortcuts in this article for rails.

Simple Ruby on Rails

%Q | %q | %W | %w | %x | %r | %s

This is an alternative for double-quoted strings, when you have more quote characters in a string.Instead of putting backslashes in front of them, you can easily write:

>> %Q(Joe said: "Frank said: "#{what_frank_said}"")
=> "Joe said: "Frank said: "Hello!"""

The parenthesis “()” can be replaced with any other non-alphanumeric characters and non-printing characters (pairs), so the following commands are equivalent:

>> %Q!Joe said: "Frank said: "#{what_frank_said}""!
>> %Q[Joe said: "Frank said: "#{what_frank_said}""]
>> %Q+Joe said: "Frank said: "#{what_frank_said}""+

You can use also:

>> %/Joe said: "Frank said: "#{what_frank_said}""/
=> "Joe said: "Frank said: "Hello!"""

Used for single-quoted strings.The syntax is similar to %Q, but single-quoted strings are not subject to expression substitution or escape sequences.

>> %q(Joe said: 'Frank said: '#{what_frank_said} ' ') => "Joe said: 'Frank said: '#{what_frank_said} '…

View original post 131 more words

Google Recaptcha With Ruby On Rails Integration.

gurudath bn Ruby On Rails

Google Recaptcha With Ruby On Rails Integration.

Google Recaptcha protects the websites you love from spam and abuse.

Below the steps to be followed to develop a sample ROR application with Google Recaptcha:-
Step 1. Create a Ruby on Rails application:-

a)Open a terminal, navigate to a directory where you have rights to create application and type:
rails new recap

b)After you create the application, switch to its folder:
cd recap

c)Type and run bundle install:
bundle install

Step 2. Create models, views, and controllers:-

a)For this application we will generate a scaffold, which is a starter template provided by Rails that bundles a model, a controller, and the relevant views for our application:
rails generate scaffold User name:string

b)After generating the scaffold we need to create the actual User table in our development database so we need to run migration:
rake db:migrate

c)To start the application run below command…

View original post 321 more words

A Bluetooth beacon in your fridge could help you eat less


Most applications for beacon technology so far have been targeted towards retailers and marketers — for instance, beacons have been used to push coupons for McNuggets when you walk by a McDonalds. Taking a different approach to the Bluetooth Low Energy protocol, a new free app from developer Brian Mueller employs beacons to help you eat less.carrot-hunger-screneshotCarrot Hunger, which launched for iOS on Thursday, has a nifty feature that requires a beacon in your fridge. Like a digital version of a “nothing feels as good as skinny feels” magnet on your fridge, the Carrot Hunger app can push a notification when you’re nearby a iBeacon reminding you to log the food you’re about to eat — effectively, a reminder not to stuff your face. Carrot Hunger recommends sticking the beacon in a fridge, but you can also stick a iBeacon in, say, your office’s kitchen.

carrot screenshot ibeacon

Unfortunately, Carrot won’t provide an iBeacon. You’ll have to bring your own beacon hardware — some iBeacon-capable beacons cost as little…

View original post 206 more words

My Experience with AngularJS: A Sound Framework of JavaScript

AngularJS is a sound JavaScript framework, and it makes the job of the programmer really easy and helps the programmer deliver a good UI(User Interface) with a great UX(User Experience) in a short span of time. Some of the great features of angularJS are as follows-

1. It’s an MVC framework of JavaScript:

It separates the developments in 3 sections: Model, View and Controller.

Model: The collection of data. AngularJS provides a special variable called $scope which is used to make the data available to the view.

View: This is the html template. In view we use a concept called “data binding” which facilitates use of the the data(in the model, i.e. $scope).

Controller: This is where the business logic is kept that explains how the data needs to be handled

2. Data Binding:

This is the most frequently used feature of angularJS that reduces the programmers job of handling the the reflection of change of data in the view. Consider the following code snippet


No of employees: <div>{{employees.length}}</div>

In this code we want to reflect in view as and when the count of employees change in the model. In case you had used JQuery to achieve the same you might have to do the DOM manipulation in your javascript code like as follows:


<div id="emp_count"></div>



and run this JS code as and when the employees count changes. So you need to keep track when this variable is changing which is a huge overhead. AngularJS even gives us a method called $watch which helps to keep track any change in the variable or object and handle the change in the $watch function block block

This examples shows you how simple it is with angularJS.

3. Directives:

You can define behaviour of a DOM element using directive. With its help you can define custom DOM elements, attributes for your project and define their behaviour in your angularJS code.


     <ang-alert alert-text="clicked 1">click me</ang-alert>
     <ang-alert alert-text="clicked 2">click me</ang-alert>


angular.module("myApp", []).
directive("angAlert", function () {
    return {
        restrict: 'E',
        link: function (scope, element, attributes) {
            //setting style
            $(element).css("display", "block");
            //defining event handler
            $(element).on("click", function () {

See demo here:

In this code ang-alert is a directive whose behaviour is defined completely in the javascript code. so HTML is kept clean of any event handler. and the html code itself is self-explanatory. This way the programmer can cocentrate on the module he is developing i.e. either the UI or the javascript and the final product is a clean code. Which is the best thing about angularJS.

Here comes the benefits of using AngularJS in you code:

  • Code becomes cleaner and maintainable: Its sound MVC framework governs you a good coding standard to follow throughout your code, which was not given by some other framework like Backbone.js.
  • Code becomes self-explanatory: Even a non-technical person can understand the high level logic by going through the code if written properly.
  • Increased Reusability of components: The directives provide you a  way to make reusable components without any alteration most of the time.
  • Unit testing becomes easy: If you use a Directives, many times in you application, a bug found in one section for the directive code, needs to be fixed only once, and the bug will be fixed in all the places wherever the directive is used
  • It provides the control for animation: Setting css animation rules on the classes that get applied on the DOM elements while transition happens for the rule set by the directives, you can achieve animation easily. For more check AngularJS animation documentation.

If this made you like angularJS, please read more on There are lot more in this magical framework.


Using jsFiddle with AngularJS


AngularJS is an awesome framework and its google group is very active. AngularJS community figured out quite early that it is so much easier to collaborate having a live code snippet.

There are many code snippet sharing tools out there but the jsfiddle is great and is used very often by the AngularJS community.

This post tries to dive into several usage scenarios of jsfiddle with AngularJS framework. The aim here is to make sure that people can quickly and easily prepare their jsfiddle which is crucial for getting help from  the AngularJS community.

Start safe

The easiest way to have a working jsfiddle with AngularJS is to start from a template prepared by the AngularJS team: The jsfiddle under this URL is updated with each release so you can just bookmark it and use it a starting point for your fiddles.

One remark: when using a stating point make sure to fork it instead of editing the original one.

View original post 797 more words

When is AngularJS Superior to jQuery?

angular-over-jqueryOne of the most common questions asked by neophyte web developers is “Which framework should I use?” While there is no one ‘right’ answer to this question, a common subject of discussion is the differences between AngularJS and jQuery. While in some respects comparing the two is akin to comparing apples and oranges, there are undoubtedly reasons to choose one web framework over the other as the primary implementation target for a web application’s front-end. Below we will look at a few scenarios where AngularJS is a superior choice to jQuery.

When DOM Manipulation Isn’t a Priority

jQuery is highly focused on DOM scanning and manipulation for achieving its goals. A common practice is adding and modifying DOM elements based upon user interactions, such as presenting the results of a query retrieved over AJAX by simply placing pre-rendered HTML into an existing DIV. With AngularJS, the focus of development is on the data presentation itself. Through use of two-way data binding, these kinds of updates can be achieved automatically without destroying and rebuilding the DOM. It may not be entirely possible to avoid DOM manipulation, but on average you will be doing less of it with AngularJS than you would with a pure jQuery implementation.

When Focused on Productivity

AngularJS, despite having a steep learning curve, has a high focus on the productivity of its developers. Many of the features of AngularJS are focused on increasing developer throughput. One example is extensive support for unit testing built-in to the framework. This focus on testing allows developers to focus on processes that produce more robust and dependable code by easing the development of unit tests. Additionally, by decoupling the DOM manipulation from the logic of the application, developers can focus on the “why” rather than the “how”. On average, this results in a smaller code base with improved stability and easier debugging.

When Taking Advantage of a Declarative Interface

One of the common issues with jQuery is that it takes an imperative approach to programming. In essence, it is telling the computer how to achieve a certain goal, and what you want is the result of that process. Declarative programming, on the other hand, switches the focus – it tells the machine what you want, and lets it figure out how to make that happen. JavaScript in general is designed with an imperative approach in mind, while HTML – and the directives that AngularJS add to it – is designed to be declarative. By working in AngularJS, you end up using a declarative approach that more closely matches the original intention of HTML – telling the computer what you want the presentation to look like, and then letting the computer handle the details. With this approach, the lines of code required to accomplish a specific task are often greatly reduced, resulting in more readable and maintainable code.


As mentioned above, comparing AngularJS and jQuery is in many ways comparing apples and oranges. The two frameworks were created with different goals in mind, and solve separate problems. That being said, there are many gains to be made in terms of programmer throughput for a certain subset of applications that focus on data presentation and manipulation as opposed to data analysis, and in that realm AngularJS has a large advantage over jQuery. Ultimately choosing a framework comes down to a number of factors related to your organizational strengths and the core competencies of the tool itself, but in many ways AngularJS is an excellent choice for enhancing developer throughput and reducing maintenance costs for your web application.