6ae6c37c4990ba332de628c6a155eb70
About Abhijit Sinha
I am a Sports Enthusiast/Coder/Designer/Wannabe Entrepreneur. I love to try things which look exciting. Current interests are React, Elixir and Mobile development. In my free time, I like to learn about gadgets and new technologies. I love to experiment with various forms of creation and challenge myself at every opportunity.
All blog articles by Abhijit Sinha
6ae6c37c4990ba332de628c6a155eb70
Abhijit Sinha

What is BombBomb

BombBomb is a platform to record, send and track video emails. BombBomb provides lots of value to users - who can send personalized video email instead of regular text emails. You can learn more about BombBomb here.

How to integrate BombBomb

We used the BombBomb Javascript API to connect to various BombBomb Services. To begin, include the BBCore and jQuery libraries in your html (The latest version is available at...

Read complete blog post

Speed

  • Method Missing

Method Missing is one of the concepts of metaprogramming ruby. Although metaprogramming is very powerful it too has some shortcomings especially speed. A normal method is comparatively 1.5x times faster than a missing method. One of our users complained about our calendar page being very slow - on inspecting we found request was taking more than 30 seconds for loading the month view of the calendar and eventually request timed out. The user had lots of activities on that...

Read complete blog post

enter image description here

Postgres uses a mechanism called MVCC(Multi Version Concurrency Control) to track changes in your database. Due to this reason, some of the rows become “dead”. Dead rows are generated by DELETE and UPDATE operations, as well as transactions that have to be rolled back. Refer this link learn more about MVCC.

These dead rows keep on adding as there are lots of updates and deletes. Periodic clean up of these dead rows is necessary to not only save space but also maintain the performance of your...

Read complete blog post

6ae6c37c4990ba332de628c6a155eb70
Abhijit Sinha

Recently we developed one feature where we wanted to present a new tab view for an existing smaller form interface whereby users can use the full screen of the new window to move around and use the feature with ease. While we were developing the feature, we came across few challenges and thereby few learnings which we thought would be good to share -

1. Caching existing values.

We have around 8-9 forms from where we can use this feature but each of them have different implementation based on...

Read complete blog post

We were debugging one issue in our application which was caching the scope we had in where clause for firstorcreate in model callbacks - and found one interesting issue -

Theconditions in the where clause were cached in after_create callback if we use where().first_or_create, please check example below -

Example:

Contact.where(first_name: 'Kiprosh').first_or_create

Contact Model:
after_create :sanitize

def sanitize
 Contact.where(creator_id:...

Read complete blog post

Recently I was getting an issue while inserting a new record to one of the table in our database. I was getting this specific error -

ActiveRecord::RecordNotUnique (PG::Error: ERROR: duplicate key value violates unique constraint "canonical_cities_pkey" DETAIL: Key (id)=(*****) already exists.

Understanding the error

The table currently has several thousand entities for canonical cities. But when am trying to insert a new record it builds an canonical_city record and assign it an 'id', say...

Read complete blog post

If you have an application which creates notes, learning how to integrate evernote to sync notes will be very handy.

You may refer this ruby gem - evernote_oauth which has useful methods to access your existing evernote notebooks, create notebooks and notes, etc. The gem is well documented.

Refer this blog to understand and see code to create note on evernote - Create Note on Evernote

If you refer the code in the above blog to create a note - just this particular snippet -

n_body = "<?xml...

Read complete blog post

If we need to support additional parameters for devise authentication besides normal(username/email with password). We can do this in devise by overiding an existing method, 'activeforauthentication?'. After authenticating a user and in each request, Devise checks if your model is active by calling model.activeforauthentication?

Consider a feature 'Lock sub user', here we can add a boolean flag 'is_locked', based on this flag we enable or disable the authentication for the sub-user:

 def...

Read complete blog post

6ae6c37c4990ba332de628c6a155eb70
Abhijit Sinha

Spec Improvements

We were fixing some failing specs in one of our project, we noticed beside failures the spec timings was too high. We spent time not only to fix also improve the performance. During this process we learned few good practices and removed bad things we added earlier which helped us improved the performance.

1) We had good amount of setup code for specs, for which we were using let statements. We can move the setup into a before(:all) block, replacing lets with instance...

Read complete blog post

6ae6c37c4990ba332de628c6a155eb70
Abhijit Sinha

In one of the projects(ACES), we came across a functionality: to parse huge(50mb+) XML files. Here efficiency was very critical piece, as file size was huge. Also we wanted the results of parsing quickly for further analysis so the effective time was less and application performance was unhampered.

We chose SAX Parsing Technique(DOM vs SAX)

There are two ways to parse an xml file, DOM and SAX. SAX being more efficient as it process the xml file incrementally, thereby memory utilization is...

Read complete blog post

6ae6c37c4990ba332de628c6a155eb70
Abhijit Sinha

1) What is Zapier ?

Zapier is an easiest way to do automation as their tagline says “superpower to get your work done”. Its a Web-App which allows different web apps to communicate amongst themselves very easily.

This communication between two apps, is called a zap, associate a pair(trigger and action) with each zap.

Example: Say you receive an email from a very important source, and want to notified quickly and create an event/task in your calendar to perform action related to email. This...

Read complete blog post

What is ActiveRecord::Store?

1) Store provides a simple means of accessing and storing key/value pairs related to a model.

2) Store gives you a thin wrapper around serialize for the purpose of storing hashes in a single column.

In simple words, it is used for storing mutiple columns under a single column. Its serailized/deserialized to save and load the data for easy access.

Example

You have a Music application, you want to cache the last volume adjustment for the user. So that when he...

Read complete blog post

In ActiveAdmin, if your resource model is deriving some data from other models, using some kind of relationship(has_one or has_many).

In this scenarios where you want to search and filter the resource based on the data in its related table, you can follow below:

Suppose you have a model School, and a model Student, now you want to search or filter students based on the school name.

We can filter using join(:schools).where("schools.name like") or say an In Query which is inefficient.

Either...

Read complete blog post

6ae6c37c4990ba332de628c6a155eb70
Abhijit Sinha

Feature is used when you need to save your nested model with the parent model.

Use-Case: Suppose you have a model say Person and it can be associated with N number of Contacts. Using nested form we can associate 1..n contacts to the person.

Approach: For associating a contact to a person, we need to build the contact model with respect to the person model. For has_many relation, @contact = @person.contacts.build and if has_one relation @contact = @person.build_contact.

Now we can use the...

Read complete blog post

6ae6c37c4990ba332de628c6a155eb70
Abhijit Sinha

ActiveRecord::Base#find_in_batches.

This lets you iterate over all the records in cursor-like fashion (only retrieving a set number of records at a time into the memory):

@Subscription.findinbatches(batch_size = 100 ) { |subs| subs.each { |s| ... } }@

iterate over all subscriptions in chunks of 100

find_in_batches supports scopes

@class Subscription < ActiveRecord::Base scope :expired, :conditions = { :expired = true } end @

@Subscription.expired.findinbatches(:batch_size = 100 ) { |subs|...

Read complete blog post

6ae6c37c4990ba332de628c6a155eb70
Abhijit Sinha

Kaltura is an third party video implementation library. Using Kaltura we can host our videos on a dedicated server or cloud.

Advantages: You can host your own CE server to store videos and create players. You can host it on cloud, which is paid as well as free, but for free you can upload less videos and you get less cuztomizations. One can secure the video by streaming the video using RTMP protocol, now the video cant be downloaded via RealPlayer or any web download means. Also the video is...

Read complete blog post

6ae6c37c4990ba332de628c6a155eb70
Abhijit Sinha

MIXIN:

Mixin is a class that is mixed with a module. In other words the implementation of the class and module are joined, intertwined, combined, etc. A mixin is a different mechanism to the extend construct used to add concrete implementation to a class. With a mixin you can extend from a module instead of a class.

MODULES:

Module is a degenerate abstract class. A module can’t be instantiated and no class can directly extend it but a module can fully implement methods. A class can leverage...

Read complete blog post

Purpose When you traverse between pages of website, you have a link to indicate the current page you are on. So dynamically finding which links is to be set active is done by the below article. Please read the article below for better understanding.

There are many primitive ways of doing it but this seems correct as its DRY and KIS.

Article Link highlight-link-based-on-current-page-in-rails

Read complete blog post