Evernote Create Note - EDAMUserException - ENML_VALIDATION

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][1] 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][2] If you refer the code in the above blog to create a note - just this particular snippet - n_body = "" n_body += "" n_body += "#{note_

Customizing Devise authentication, to disable or enable user authentication.

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, 'active_for_authentication?'. After authenticating a user and in each request, Devise checks if your model is active by calling model.active_for_authentication? 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 active_for_authentication? super && !is_locked end Instead of !is_locked, we can also add a custom method which:

Spec Improvements

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. 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 variables. This will create the data only once, and as long as we never change

XML Parsing with Ruby

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 minimum. Whereas a DOM parser, builds a tree representation of the entire document in memory

Zapier

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 entire task can be configured in Zapier to track a particular email, send you a

Rails Store - A solution to store multiple value in single column.

What is ActiveRecord::Store? Store provides a simple means of accessing and storing key/value pairs related to a model. 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 returns back, same volume level is applied, similarly other volume related settings. Now you can

Active Admin - adding custom search(outside the resource model)

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 way ActiveAdmin does not provide default filters based on

Nested Forms

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 @contact in the view, for this we use fields_for tag. And

ActiveRecord - Find in Batch

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.find_in_batches(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.find_in_batches(:batch_size => 100 ) { |subs| ... }@ _Disadvantage: _ You can’t specify :order or :limit in the options. Where to use it: Large Dataset, where you need to loop through

Integrating Kaltura

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 supported across all browsers and all devices including iOS devices.