Category Archives: Uncategorized

Uncategorized

Angular Digest Cycle

Published by:

I am going to explore the Angular digest cycle, which is the process behind Angular data binding. By the end of this post, you’ll understand how data binding works in angular, what is digest cycle, how we trigger digest cycle by calling $scope.$apply() and how exactly digest cycle works.

First of all, let me tell you one thing about Javascript .i.e
Javascript Is Turn Based.
The JavaScript code we write doesn’t all run in one go, instead it executes in turns. Each of these turns runs uninterrupted from start to finish, and when a turn is running, nothing else happens in our browser.
Instead, whenever there is a task that takes some amount of time, such as an Ajax request, waiting for a click event, or setting a timeout, we set up a callback function and finish our current turn. Later, when the Ajax request completes, a click is detected, or the timer completes, a new JavaScript turn is created and the callback is run to completion.

Let’s look at the below code

When the JavaScript code is loaded, that is a single turn. It finds a button, adds a click listener, and sets a timeout. Then the turn is complete, and the browser will update the web page if necessary, and begin accepting user input.

If the browser detects a click on #clickMe, it creates a new turn, which executes the buttonClicked function. When that function returns, that turn is complete.
Now take a look at a very simple AngularJS snippet where you start typing your name into an input field. There is also a div that shows what you typed, in real time:

Whenever the name model changes, the expression automatically updates itself. It’s done just by setting up a watcher on the name model.

Most watchExpressions are created implicitly within AngularJS, but you can also create them manually. Let me show you how to do that:

Note : Here in watch expression we pass newValue and oldValue. When watch expression changes, then the listener function is called. This is also known as dirty checking.

For this strategy to work, we need to know when data has possibly changed, and this is where $scope.$apply comes into play.

The step that checks to see if any binding values have changed actually has a method, $scope.$digest(). But we almost never call it directly, instead we use $scope.$apply() which will call $scope.$digest() for you.

$scope.$apply() takes a function or an Angular expression string, and executes it, then calls $scope.$digest() to update any bindings or watchers.You can also say that it just  starts new javascript turn. Digest cycle executes at least twice.

So, when do you need to call $apply()? Very rarely, actually. AngularJS actually calls almost all of your code within an $apply call. Events like ng-click, controller initialization, $http callbacks are all wrapped in $scope.$apply(). So you don’t need to call it yourself, in fact you can’t. Calling $apply inside $apply will throw an error.

So what happens when we write

1. The directive ng-model registers a keydown listener with the input field. When the input field text changes a keydown event is fired and the corresponding listener is called to handle it.

2. Inside the keydown listener the directive assigns the new value of input field to the scope model specified in ng-model. In our case the model name is updated with the new value. This code is wrapped inside $apply() call.

3. After $apply() ends the digest cycle starts in which the watchers are called. If you have an expression {{name}} in the view it has already set up a watcher on scope model name. So, in digest cycle this watcher gets called and the listener function executes with the newValue and oldValue as arguments. The job of this listener is to update the DOM with the newValue probably using innerHTML.

4. The overall result is that you see the {{name}} updated with whatever you type into the input field instantly.
References:

http://www.thinkful.com/projects/understanding-the-digest-cycle-528/

Notes On AngularJS Scope Life-Cycle

 

Uncategorized

Native vs Cross-Platform apps: The eternal dilemma

Published by:

With Facebook reporting that 90% of their 2015 Q4 monthly active user coming from mobile users (52% from mobile only) mobile apps are truly taking off. In India, a country of 1.3 billion people, mobile phone subscriptions have already reached 1 billion mark. It’s increasingly becoming a norm to have mobile apps which compliment  a business’s website.

With an average person said to be spending at least 90mins a day on his/her smartphone, it’s more important than ever to develop good experiences for mobile users. Mobile devices are truly personal and they offer unique opportunities for businesses to connect with users. But this also comes as a challenge as only 16 percent of users will give a second or third chance to an app which failed to provide a good experience. Users are more likely to download your app if it has a higher rating either in the apple or google play store, which makes developing great user experience in mobile apps a number one priority.

Performance of your app is also a critical feature that cannot be overlooked as users uninstall and leave bad ratings. In fact nearly 59% of users uninstall apps which are slow and 42% say they uninstall apps because they didn’t like the user interface.

Another survey conducted to check how crashes and slow apps have an effect on the user showed following results

user_stats

All this in mind it becomes hard for a company to choose whether to build a native or a cross-platform app.

Now when we talk about cross-platform apps they come in two flavours

  • Cross-Platform apps which are wrapped in web view (Cordova, Ionic etc).
  • Cross-Platform apps which get compiled down to native code (Xamarine, React-Native etc).

Here’s a breakdown on some of the features of both.

Features:

Cross-Platform(WebView) Cross-Platform(Native) Pure Native
Low development time Low development time Moderate development time
Low performance High performance Highest performance
One codebase, no need for multiple type of developers for different platforms One codebase, no need for multiple type of developers for different platforms Need different type of developers for different platforms that you plan on supporting
Can access some of the native functionalities like location service, maps etc, but very limited Can access most of the native functionalities but does not have complete control like native apps Has complete control over native apis and functionalities
UI and UX is mediocre Can build great UI and UX for mid and high end devices Can build great UI and UX for all devices
Support for wearable devices non-existent Support exists for wearable devices, but is very new and trying to play catch up with ever changing native apps Complete support for wearable devices
Support for updating app on fly Support for updating app on fly No support
Does not provide a personalised experience (no support for detecting network speed, contacts etc) Provides a satisfactory personalised experience (support for all native functionalities, but most features are playing catch up and doesn’t provide complete flexibility) Provides a truly personalised experience

The above listed points are some of the most prominent features of hybrid and native apps respectively. So back to the question as to what we should be using, well in theory this is how it should be.

  • If your app is something internal, which doesn’t make use of any core native features like camera, sms etc. and you want to get the app out as soon as possible to most of the mobile platforms go for Web View wrapped cross-platform apps.

  • If your app is complicated and doesn’t require you to build a lot of custom stuff or make use of a lot of native features and ok with compromising on some of the UI features (happens rarely but be prepared for it) go for Cross-platform apps which compile to native.

  • If delivering a great app is your priority and you are willing to invest more time and money for it then go for Native apps.

That being said there are only a handful of apps in the playstore(both android and ios) which have actually been built using cross-platform apps. On the other hand native apps have been tried and tested for a long period of time with ready solutions to a lot of previously faced problems.

Building native apps is always much more reliable than building cross-platform apps and that is one of the most important things when you build a mobile app, because unlike web apps where you can visit any link without any commitment, a user makes a commitment by downloading your app. You need to make sure to provide the best experience possible to value that commitment. Remember it’s almost impossible to gain back a user and the user expects nothing less than a reliable, high-performance app when he/she does download your app.

Uncategorized

Performing Exercism on Ruby!

Published by:

One day I stumbled upon this awesome site called “Exercism”. It mainly focuses on improving your skills via Deep Practice & Crowdsourced Mentorship, Strengthening your problem-solving skills by guiding others through the process. I got hooked onto it and then I thought why not share my learning with all. Being a Ruby programmer, my notes are Ruby based.

Things To Keep In Mind

Before tackling any program/problem/challenge you should keep certain points in your mind. Some are general, some are more language specific.

Some questions you might want to ask yourself:

  1. Am I adhering to the Single Responsibility Principle?
  2. Is all my code on the same abstraction level?
  3. Can I combine conditional clauses?
  4. How does my API look to clients of this code (i.e. how do other classes interact with this class)?
  5. Do I have duplication?
  6. What requirements are likely to change? Would I be able to implement such changes painlessly? [Note that it is not that you should normally guess what future requirements are, but it can be helpful on Exercism]

Use Private, that way you limit the public API of any class. It’s considered a good practice to expose as few methods as possible, so you don’t come up with a “fat interface” and has to maintain a lot of methods that probably nobody else uses (this is troublesome when you want to refactor your code but you aren’t sure if somebody is using method x or not.

If you are using in-built methods you should understand them first – how they work, what are the pros & cons, in which use-case you should use them. Don’t assume, dig them up. Some examples:

  • p & puts are not the same
    p foo does puts foo.inspect , i.e., it prints the value of inspect instead of to_s, which is more suitable for debugging (for example, you can tell the difference between 1, “1” and “2\b1”, which you can’t when printing without inspect).
  • to_a  is super-expensive on big ranges.
  • Use string interpolation only when necessary.
  • a.map(&:to_i) i.e. Symbol#to_proc  : you are passing a reference to the block (instead of a local variable) to a method. Also Symbol class implements the to_proc method which will unwrap the short version into it’s longer variant. Example:

Some problems from Exercism

I have described what I learned from individual problem. I am also putting names of the relevant problems so that you can look them up. My code is uploaded on Github. Also I have explained why I used certain in-built Ruby methods. I have highlighted some specific things that you should consider in general.

Accumulate

Two ways to yield a block in ruby : yield & call

(Read “ZOMG WHY IS THIS CODE SO SLOW?”)

  • Yield returns the last evaluated expression (from inside the block). So in other words, the value that yield returns is the value the block returns.
  • If you want to return an array use map/select depending on situation. You don’t need to initialize an array & return it.

Anagram

Anagrams are same if sorted.

select  will return element if condition satisfies. So in case of conditions use select  over map / each .

Beer-songs

Follow this link

Binary

Use map.with_index  so that you do not have to initialize another variable & directly apply  inject on the result.

Bob

Start simple. Try to make test pass in a very easy way.

Etl

Use of each_with_object :

Grade-school

Initialize an empty hash and declare values as an array. To sort & return a hash use hash.sort.to_h .

Grains

Sometimes solution could be a single word. Check for patterns. For instance, here you don’t have to iterate 64 separate calculations in self.total. Think about the totals for the first few squares: 1, 3, 7, 15, 31. Now think about those totals in relation to powers of two. Total is a series of (2x-1) where x is 2**(n-1).

Hamming

  • raise  could be another method. Always look out for single responsibility principle.
  • select  &  count  are perfect methods here.
  • It is considered a good practice to expose as few methods as possible, so you don’t come up with a “fat interface” and maintain a lot of methods that probably nobody else will use. This is troublesome when you want to refactor your code but you aren’t sure if somebody is using that method or not. In this exercise, the only method being called is self.compute , so this means you could make self.raise_size_mismatch  private and avoid exposing it.

Hello-world

You can pass default argument to a Ruby method :

Leap

You can minimize loop:

to:

But I won’t prefer it, because the former one is more readable. Sometimes you have to gauge which is worthier.

Phone-number

Interesting use of sub:

Raindrops

Assign common values as constant. Avoid unnecessary computing. For example you only need to check if 3, 5 & 7 are factors.

Robot-name

shuffle  method of Array (can be applied to a-z but will be futile for 0-999 as it takes lots of memory & computation). Use Default assignment  ||=

 

That’s it for now. Please do let me know how this blog helped you and whether I missed something that should be included. Sayonara for now!

Uncategorized

The Coffee Mug Paradigm

Published by:

On 9th Feb, 2016, Cybrilla Product Owner, Nitish Gulati, delivered a Mangalwari Gyan session on The Coffee Mug Paradigm – A Lean Product Management Strategy at our talk space in Bengaluru. His talk is slowly gathering audience and he will be a speaker at Discuss Agile’s Conference. The talk throws light on lean product strategies and agile methodologies. He he describes lean product marketing as a combination of agile & lean approaches.Nitish performed the case study to analyse marketing strategies of startups. The Coffee Mug Paradigm can help product lead companies better understand & implement lean product marketing strategies.

Uncategorized

Not The Best – Just Perfect

Published by:

Cybrilla_Interior
If you search for ‘world’s most awesome offices’, we may not feature(that result is biased in the favour of Google!).

That search result reflects the perspective of certain individuals/publishers. Seen under the light of the morning sun that brightens up the mood early morning and the track lights in the evening, ours might not fall far behind.

Cybrilla Collaboration Desk


And to correct those search page listings on interesting office spaces, this is our honest attempt to making a slight dent in the universe of google search results.

We actually do not compete on fancy lounge spaces, conference rooms etc. Hell we don’t even have those fancy biometric access. Ours becomes a competitive space with the people put together. In my opinion, the garages where HP or Apple began were more iconic than their current offices, so was ours.

Cybrilla Office Inaugration


The office is workshop inspired & a Cyborg made attendance system welcomes you. But it encapsulates all features of a cutting edge system – scans RFID, uses Raspberry Pi (the credit card size computer), scanner, speaker for text to speech conversion and matrix keypad size 3X4 for delivering output in graph & charts.

Cybrilla Reception

We gave a detailed thought to every aspect of design and consulted with one of the best interior designers to create a work-space that has our brand values at its heart. We now have an open space office that provides us the platform to take the company forward.

With growing footprint in the international markets, we needed a space equipped with all the amenities for communication with our overseas clients. Our new office comes equipped with a conference room.

Cybrilla Confrence Room

 As a company we believe in frequent iterations and our discussion room is designed in a manner that facilitates short discussions. The high table is purposefully high, so that we do not sit and keep the meetings short and when we have to, there are high chairs that are not meant for sitting for long. That’s right, we create more – discuss less.

Cybrilla Library & Discussion Room


Similarly, the large desks with capacity to seat entire teams has been designed to achieve greater collaboration. But then, for a short while everyday, you need space, for that we have the solitary room. For relaxing after work we have the kitchen area with pub like seating so that you do not have to leave office to unwind. Stay as long as you like, stay because you like it.

Cybrilla Kitchen


Cybrilla Interior


To keep our team members well read, we have designed a library. To help our mobile first workforce, we developed the Liborg App. The app is built with the functionality to issue books, search books by image, barcode scanning, image issue and the ability to preview any book using search.

Cybrilla Library & Discussion Room


Interestingly, the most iconic office space should be judged on whether it put a dent in its’ industry & not by being ‘Garage Inspired’.

The most iconic as judged are designed in manner that if someone has to stay back for the night, they do not miss home. That validation is subject to circumstances, ours is a welcome space where Cyborgs routinely stay back for Star War Movie Marathons & Counter Strike Nights. 

We have outgrown 5 offices in as many years and every time we moved because of organic reasons and not because we could afford it.

  • The new office is more spacious, in sync with our expertise of scaling up, applications and workforce. Its’ a 3300 sq. foot space with a mix of open space and rooms, crafted to suit the needs of developers.
  • The kitchen is right there with ample space to stock. This ensures the builders of robust applications stay fueled.
  • We have a mini auditorium where people can speak to be heard, especially where Mangalwari Gyan and Meetups which are a regular feature.
  • There are no separate rooms/cabin so that even the CEO knows he’s being watched!
  • The large desks double up as dining tables for the frequent parties.
  • Designed to optimize on daylight.Twinkling Cybrilla In Evening

    We have tried to craft a fun and collaborative work space so that our people – Cyborgs feel addicted to come & stay back. Happy developers equal successful products, which in turn equals happy clients.

    We’re observing a rapid growth here, which means we’ll be able to deliver inspiring products from our inspired office. We’re on a mission to change the world using software as a vehicle and are excited to see what Summer has in store for us. With all this space we’ll also be able to host events at our office, so we’ll be excited to invite people in and show them what Cybrilla is all about.

    If you’re looking to make a career move this Summer, we are hot, why not join us in our brand new office? We’ll be hiring in many more positions in the months to come, so keep checking our latest job openings here.

    Don’t forget you can follow us on Twitter, Facebook, LinkedIn, Google + & YouTube for all the latest news from Cybrilla & Software Industry.


Uncategorized

Party at Work..Why Not!

Published by:

IMG-20151110-WA0041 (1) (1)

In sync with our policy of celebrating all major festivals and even minor successes, we celebrated Diwali at our ‘Nice View’ office. Diwali, also known as the Festival of Lights is celebrated in verve by lighting Diyas (earthen clay shells with a lighted wick) to signify the triumph of good over evil. Staying true to the spirit of Celebrilla errr Cybrilla, Diwali Party was a congenial affair.

At Cybrilla, we have a vibrant culture that celebrates festivals from across the country. Diwali Party shed light on it through a 100 LED’s as we avoid Diyas and crackers for the love of environment.

From adoring the floor with a beautiful Rangoli, the walls and tables with garlands and flowers to dressing in ethnic Indian wear to ordering everything that is otherwise cooked at home(Yes! we took a few shortcuts). All stomachs looked convex after having been stuffed with Gol Gappas and other delicacies.

The lack of sound of fireworks was soon replaced by the Cyborgs on dance floor who went all footloose dancing to the top charts. The cherry on the cake was the solo performance of Satish Perala, our CEO, who set the bar high for upcoming dance events. It was amazing to see an otherwise code filled evening progress into an amazing night of Cyborg get together. The Diwali Party was yet another gem we would preserve in our memories.

Uncategorized

Statemachine

Published by:

What is Statemachine?

Statemachine is any device that stores the status of something at a given time and can operate on input to change the status and/or cause an action or output to take place for any given change. A computer is basically a state machine and each machine instruction is input that changes one or more states and may cause other actions to take place.

example1: Turnstile

Statemachine diagram for turnstile

Turnstile has two states:
1) states: locked and unlocked
2) There are two inputs that affect its state: putting a coin in the slot (coin) and pushing the arm (push).
3) In the locked state, pushing on the arm has no effect; no matter how many times the input push is given it stays in the locked state. Putting a coin in, that is giving the machine a coin input, shifts the state from Locked to Unlocked.
4) In the unlocked state, putting additional coins in has no effect; that is, giving additional coin inputs does not change the state. However, a customer pushing through the arms, giving a push input, shifts the state back to Locked.

Statemachine has 3 fundamental components:
1) States
2) Events
3) Transactions

From above example: we have
States: locked and unlocked
Events : putting the coin and push the arm
Transactions: locked to unlocked, unlocked to locked

example2: Vending Machine
Uml diagram: States and Transitions:
The Statemachine that runs a simple vending machine.
The Statemachine that runs a simple vending machine.

From the above UML diagram: we have
States: Waiting, Paid
Events : dollar, selection
Transactions: waiting to paid, paid to waiting

What is event?
Event is an action or trigger, which invoke the transition to change the state of the object.

What is Transition?
Each transition can be defined by identifying the state where it begins, the event by which is invoked, and the state where it ends.

Ruby Toolbox Statemachine

Ruby Toolbox Statemachine has list of gems which supports statemachine functionality.

Why we need statemachine functionality in ruby?
The main reason for using state machines is to help the design process. It is much easier to figure out all the possible edge conditions by drawing out the state machine on paper. This will make sure that your application will have less bugs and less undefined behavior. Also, it clearly defines which parts of the internal state of your object are exposed as external API.

Most web apps contain several examples of statemachine, like accounts, blog posts, orders, invoices and many more.The problem is we never think of them as statemachines while designing your application. Therefore, it is good to have some indicators to recognize them early.

Since Ruby has list of gems.Among them, below 3 gems are fully-featured,
statemachine
aasm
workflow

The above three gems vary in their syntax and some additional features.
You can find the detailed explanation of:
statemachine
@:https://github.com/pluginaweek/state_machine
aasm
@:https://github.com/aasm/aasm
workflow
@: http://rubydoc.info/gems/workflow/frames

Table: List of features in gems.

STATEMACHINE AASM WORKFLOW
Callbacks yes yes yes
Guards(Conditional transition) yes yes yes
Automatic Scope no yes yes
Validation errors yes no no
Dirty attributes yes no no
Tracking & Observers yes no no
Transaction Support yes yes yes
Named Scope yes no no
Transition Context yes no no
Generating Graphs yes no no
Transaction Event Handler no no yes
Inheritance yes no yes
Transition hooks yes no yes
Integration with ActiveRecord yes yes yes
Integration with couchDB no no yes
Integration with Mongoid yes no no
Integration with ActiveModel,
datamapper,mongomapper & sequel
yes no no
Static/dynamic definitions yes no no
Core Extensions yes no no