Skip to main content

Posts

Showing posts with the label regular

Las Vegas

January has been pretty exciting for me since last three years, It marks my annual ritual trip to Las Vegas, this is my third trip this year. Almost all of my trips have been because of work. Since Las Vegas has some of the biggest hotels[1] in the world it has become a natural choice for some of the biggest American companies to host their internal and external conferences. As an example, CES hosts some 200,000 people every year [2]. This year I started my 30-hour flight journey, yes you heard it right I had a 9-hour layover at the London airport. Though it was far from ideal it was not that bad. If you can arrange priority pass [3] card from your credit card company or pay for it. Then you can use the lounge, showers and much more for free. I manage to steal the below picture from a hoarding at the airport.  Then after much rest and time pass at the airport terminal, I boarded my next flight to Las Vegas. When I landed McCarran International Airport, the first surprise for me was the...

Portugal

#Albufeira is a small town just 3h from Lisbon. This was our first stop of the trip. This place is absolutely beautiful. Since we went there during not so crowded time it was even more enjoyable !! When everybody is a photographer #fail Stairway to heaven Symmetry Defying #Gravity festivities in #Lisbon Palace of Pena We went to #Sintra on a day trip to see the beautify national Palace of Pena. Sintra is a small town just 30 mins from Lisbon. Sintra is a very popular tourist destination, as a result, is usually very busy, so plan your trip accordingly. Jerónimos Monastery in Lisbon. We did not get a chance to see the inside of the monastery since all the monuments are closed on Monday in Lisbon. Torre De Bellém National Sanctuary of Christ the King. This was such a surprise, we went there on 1st January trying our luck as all the monuments were closed on 1st of Jan, but to our surprise, we found this place open and we got a chance to go at the top of the statute.

Managing State in React.js + Flux Applications.

Recently i have been trying out the new kid on the block, React.js and its unidirectional data/state management partner Flux. The concept of React.js is very simple. Your app is a combination of react components.  Every component has a state and properties. Whenever there is any change in the state or properties of the components the component is rerendered. Though in the above points i used the state and properties very casually. Usually its very important to get your head around when to use state and when to use properties.  You can refer to this article  https://github.com/uberVU/react-guide/blob/master/props-vs-state.md  to find out more about props vs state.  On the other hand Flux which calls itself an architectural pattern rather than a framework, is also straight forward. There is a dispatcher whose main goal is to dispatch the event to all the registered objects. There is a store , the store basically encapsulates the state of a component or group of components. The store reg...

Introducing ember-data

Model objects, defined by the ember-data library abstracts away the complexities involved with handling the communication with the server, serializing, as well as de-serializing of the response received from the server. In order to define your ember-data model object, you just need to extend the DS.Model object present in ember-data module as follows: Models form the core of any MVC design pattern as they describe the core business domain at hand. In Ember.js, every route has an associated model that describes the business domain that the route needs to work on. Almost all of the examples that we have seen so far operate on the static data that is returned from the model property of the routes. But most of the times the data that needs to be operated upon is not static and is fetched from a remote server. Traditionally we have used jQuery or plain JavaScript to fetch the data from the server, using AJAX calls and then using those returned JSON objects as models in our application. This...

Broccoli - The Asset Pipeline in Ember.js

Ember CLI includes the fast asset pipeline broccoli (can be found at https://github. com/broccolijs/broccoli ). Broccoli draws heavy inspiration from the Rails asset pipeline. It runs on node.js and is independent of the backend platform you are working with. One of the most common ways to handle asset compilation and minifying is to use the Grunt task runner, or a similar tool. Let’s say you are working on an application that involves the compilation of CoffeeScript, Sass, and other similar assets. Now to make these assets available to our application, you will have to write a Grunt task that does the compilation. When you start the active development of your application, you will realize that running the Grunt task after making any changes to your CoffeeScript or Sass files iscumbersomeandtime-consuming.So,youstartusinggrunt watchinyour application to rebuild your entire application whenever you make any changes anywhere in your application. But very soon, when your application ...

Ember.js Object Model

JavaScript is a multi paradigm dynamic language that supports all of object-oriented, procedural, and functional styles of writing code. This makes it one of the most powerful, as well as the most misunderstood language of all times. Often one aims to write code that is modular, extensible, and testable. But not everyone is able to write good quality code because it requires deep understanding of the language, design principles, as well as discipline to write code that consistently follows a particular school of thought. Ember.js framework helps in creating applications which are highly modular, extensible, and can be tested easily, and the Ember object model lies in the heart this framework.

Suffix Trees , a bit complicated but really powerful data structure

Continuing with my obsession with the string matching algorithms , after  KMP algorithm which does string matching in O(n +k) time , where n is length of the string and k is the length of the pattern. I tried exploring another data structure called as “Suffix Trees” , Suffix trees are nothing but compressed tries , where you model all the suffix present in a string in an optimized tree/trie structure. this is how a suffix tree for word “BANANA” will look like some of the other common use cases , where suffix trees can be used is  Find the longest common substring of the strings S and T. This can be done in time O(|S| + |T|) Find the longest substring of S that appears at least m > 1 times. This query can be answered in O(|S|) time. Traverse the suffix tree labeling the branch nodes with the sum of the label lengths from the root and also with the number of information nodes in the subtrie. Traverse the suffix tree visiting branch nodes with information node co...

Ruby implementation of the famous Knuth–Morris–Pratt Algorithm

today just decided to write the   Knuth–Morris–Pratt string searching algorithm  , implementation in ruby.  As you can see that the algorithm is divided into two parts , one is the preprocess , which is the crux of the Algo and the actual string searching using the preprocessed metadata. The preprocess function is run only on the patterns, and it calculates Ï€[i] = the longest proper prefix of pattern[0..i] , which is also a suffix of pattern[0..i]. e.g. if the pattern you are searching for is  P = [ ‘A’,'B’,'A’,'B’,'A’,'C’,'A’] the Ï€ array will look like Ï€ = [ 0,0,1,2,3,0,1] which shows that longest running prefix of the pattern is ABA . Buy doing the above calculations the algo saves itself some of the comparisons which it had to do in the naive , brute force approach. if you get the preprocessing function then the rest of the things are straight forward , the algorithm is intelligent enough to understand that if next char in the seq does...

HATEOAS - Hypermedia as the Engine of Application State

Just came across this term HATEOAS , which some of my team members were using in describing what we did in our previous project wrt to REST. My Last project was about building an e-commerce platform for one of the largest book publisher and distributor in Latin America.As part of that project we had thought to use the LEVEL-3 for rest communication which is using REST as a hypermedia controls.  You can read about different levels of REST at this Martin Fowler’s Blog  . When we said we wanted to use REST as hypermedia controls , the main idea behind this was to be able to navigate the result of a REST call. For Example if there is a product catalogue call which looks like GET /products/123456 So It would return  As you can see that apart from the the properties of the product 123456 it also has a links array. This links array contains the the link description in rel and the location of that document. so essentially what i could do is parse the JSON response , and then look for wha...

Using RSVP for multiple ajax promises

So i was working on a bug in my project the other day wherein the requirement so we had to make multiple ajax calls to our backend and then once when “all were done” we had to trigger the success callback, even if any one of the calls fails we do not trigger the success callback. And the asynchronus nature of the the ajax calls make it more difficult. So to solve this problem we had a count variable with a promise, with every callback we were incrementing the callback and then when the count was equal to the number of calls then we would resolve the deffered object which would fire the success callback. This approach worked but was difficult to understand and debug. To simplify this a bit we used the RSVP which was bundled with the ember source. so instead of maintaining the count and then manually resolving the promise we used the Ember.RSVP.all(<array to observe>, function(){ console.log(“success callback”)}) so it resolves the success callback once all t...

Segregation of responsibilty with EmberJS router actions and store

Recently we upgraded our application to ember 1.3.0 and ember-data 1.0.0-beat4.Though it was a challenging task , since most of the api’s , conventions and names had changed so it involved in a lot of effort ( the upgrade deserves a separate blog post ).The one of the many things which has changed in the ember-data and ember 1.0 is the actions hash in the routes . So routes can now have actions which look something like. You can call these actions from Handelbars using {{ my-button action= “ showUser”}} or  from the view code using  this.sendAction( ’ action’, param1, param2); The events gets bubble up from the { Handebars } -> View -> Route  This picture form Emberjs docs explains it in a better way.  you can read  http://emberjs.com/guides/templates/actions/#toc_action-bubbling  for more details about action bubbling. The other change which the ember-data library brings about is making store the centre of all the interactions to the server , Store ...

Concise languages make you focus more on business problems rather than fixing syntax

Today i was reviewing the code of one of the prospective java candidates, even though the code was really well written , after switching between ruby and java for over 3 years now , java code now seems very messy for example when i look at  Map<String, Double> currentCurrencyQuotations = quotations.get(lastCurrencyName); it gives me a feeling that probably the person spends a lot of time in type checking the code rather than focussing on real business problems. Ruby solves this very beautifully.i can just say   current_currency_quotations = quotations.get(lastCurrencyName); current_currency_quotations[:key]  would just return me the value of this key.  Even though this might not be a very good example , but if the language is concise and makes it easier to do operations , you can focus more on solving complex business problems rather than getting stuck with silly syntax issues.

EmberJS Vs AngularJS

Recently i was about to start another project , and we decided to use the latest tech stack , so we went with ruby 2.0 , rails 4 , mongo  2.4 but then we had to decide what javascript framework we should go with. Personally i did not had any preference , if it was only me i would have gone with plain jquery, since the project is not UI heave and contains some complex forms with complex validations. But then i was also convinced of the fact that over the time javascript becomes very unstructured and difficult to maintain. So we decided to do some research on which framework to choose from and why , i already knew some people who are already using angularjs in their projects and not all were happy , some even decommissioned the angular framework after working on it for couple of months. Angular at first seems a sensible and a good choice and there was sufficient documentation for the same Here is what i found about Angular Angular JS claims that it is a full blown web app framework for j...