Sharing

E8a35961cc9ac2aca01c3a173f5c8d4a
About Rohan Daxini
Ruby, Elixir & C lover | Life Long Learner | Books | Technology | Mindfulness | Gratitude
All blog articles by Rohan Daxini

One of our production web application runs on a dedicated node in DO (Digital Ocean) cloud server. This web application has following services running.

  • Elixir Phoenix API server
  • React.js client server
  • Redis caching server
  • Bots (Slack)

Few days back, Digital Ocean triggered an urgent maintenance for Meltdown and Spectre Mitigations resulting into a reboot of our PROD server. DO did alert us in advance by sending an email notification with schedules. But seems we missed these schedules…

Read complete blog post

E8a35961cc9ac2aca01c3a173f5c8d4a
Rohan Daxini

Ecto’s query syntax does not cater to all types of database queries. fragment is useful to inject custom SQL for composing queries.

Lets take a very simple example to lowercase a target column while comparing a string in where clause in our SQL query. We can usefragmentto inject custom SQL into our query.

email = "[email protected]"

query = from u in User, 
  where: fragment("lower(?)", u.email) == ^email, 
  select: u.email

Repo.all query

In the example above, we have used lower using…

Read complete blog post

Reading Time: 4 mins

While writing a custom Mix task in Elixir, I ran into minor challenges for running / executing an Ecto query to update a database table column from within my mix task. It was not straightforward initially thus I thought to share here. In this short article, we will also see how to pass arguments to our mix task to run dynamic query.

First, what is Mix? Elixir documentation says:

Mix is a build tool that ships with Elixir that provides tasks for creating, compiling,

Read complete blog post

enter image description here

Spoiler Alert: This article is not about Microservices architecture or how microservices works. In this article, I will share what we have learned in scaling one of the large SaaS platform, our ongoing improvements and how Microservices architecture is playing a key role in scaling this SaaS platform.

This SaaS Platform has experienced tremendous growth in the past 18 months. It has now become one of the leading CRMs in North America.

Everyone’s definition of “scale” and “growth” can differ…

Read complete blog post

One of the coolest feature I came across in Elixir - our code documentation becomes our unit tests. I was amazed by its simplicity when I saw it in action in sample app I was writing. I feel this is one of the most incredibly and helpful feature I saw in any modern programming language in recent times. (Python has similar functionality using Python’s doctest.)

Let me explain this by giving a quick demo using few simple examples: Math functions sum and multiply.

Lets say this is our Maths modul…

Read complete blog post

Here are few Rails and general developer tips & tricks to

  • improve code readability
  • do things Rails way
  • improve productivity

They say "Good code is like a good joke: It needs no explanation".


1) idiomatic code

Instead of this code...

def delete(notes)
  notes = notes.where('notes.from = (?)', 'evernote')
  notes.any? && notes.map(&:destroy)
end

Better way is...

def delete(notes)
  notes.where('notes.from = (?)', 'evernote').map(&:destroy)
end

2) Rails way

Instead of this…

Read complete blog post

We recently upgraded one of our app to Ruby 2.2.2

Bundle installed failed ...... crying about well known issue of Error installing gem with native extension, but this time for Gem json -v 1.8.3

Detailed error shows

Fetching: json-1.8.3.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing json:
    ERROR: Failed to build gem native extension.

    /usr/local/rvm/rubies/ruby-2.2.2/bin/ruby -r ./siteconf20151209-13741-vqcxt1.rb extconf.rb
creating Makefile

Read complete blog post

E8a35961cc9ac2aca01c3a173f5c8d4a
Rohan Daxini

Recently I started learning React.js and developed this sample ToDo list App fully in React.js

Here is my github repo for this ToDo app.

The app has basic ToDo functionality to add new todo, edit (inline), delete a todo item, drag & drop to sort or change order.....without any backend to keep things simple for now. Its vanilla html css react.js and jQuery. I have used jQuery plugin jquery-editable for inline text editing of todo.

Rohan Pujari helped me to fix couple of bugs along with guiding…

Read complete blog post

Few days back, we were facing problem establishing communication between a Webview control and a Titanium UI or vice versa.

We were integrating Facebook authentication in our Titanium mobile app using Titanium Facebook mobule where we stumbled upon this issue. We wanted to trigger FB Auth Titanium module specific code on click of an HTML Login button tied with a jQuery click event. The FB auth module checks if Facebook mobile app is installed on the device and opens this mobile app for…

Read complete blog post

Rails has provision to provide order of indexing on a column for better performance of like queries. The varchar_pattern_ops improves the performance of like queries by 4x.

For example, lets have this like query on name column (that has sequential index.)

Select * from users where name like 'John%'

We might have added a regular Rails index in migration for this name column as

add_index :users, :name - This will generate a sequential index.

The same can be made 4 times faster using btree

Read complete blog post

Few weeks back I was reading a blog about concurrency limitations in Ruby (which we all are aware since long) and how Elixir is evolving. Thus I was extremely curious to know this new dynamic functional programming language "Elixir", the two decades old Erlang language & Erlang Virtual Machine (VM) known for running low-latency, distributed and fault-tolerant systems. This article is a result of my curiosity about Elixir and Erlang.

This article does not cover (i.e. out of scope) installation…

Read complete blog post

E8a35961cc9ac2aca01c3a173f5c8d4a
Rohan Daxini

How do we customise Titlebar in ActiveAdmin show view For example, in the attached screenshot, I have breadcrumb as Admin / Orders / Order #11834 in my show view. Instead of that I want to customise it and display it just as "Admin / Orders / Order# 43872378123 & Transaction# MwlDdTc3RW" or just "Admin / Orders / Transaction# MwlDdTc3RW".

Its fairly easy,

In app/admin/order.rb

show title: proc{ |order|
  order.transaction_number.present? ? 
    "Transaction# #{order.transaction_number}" :

Read complete blog post

We have integrated Chargify for one of our application. Recently we observed that few of our test users, that are more than 6 months old, are unable to login in our staging site, which is connected to Chargify TEST Mode.

We noticed that auto cancellations are happening (once a day) for these users in their Chargify subscription records. This was strange behaviour, we thought either this is happening due to our "Dunning" settings or due to "unpaid" state changes for credit card expiry. After…

Read complete blog post

If you are using Sidetiq to set recurrence to schedule background jobs, then you may want to be aware of this known and reported issue with 'recurrence'. (btw, recurrence schedule is done using ice_cube gem)

This is likely an issue in Ruby 1.9.3 but I have posted comments on this article here Link to SO question(http://stackoverflow.com/questions/20936305/sidekiq-sidetiq-recurrence-every-2-hours) along with git issue to clarify if its an issue with Ruby 2.0 and above. References at the bottom…

Read complete blog post

On your MAC OSx, if you have upgraded to latest Ruby 2.1.5 (or even 2.1.2) then there are high chances that you will face issues installing "nokogiri" gem. You might face errors like

ERROR: Failed to build gem native extension.

Following are the steps to resolve these issues on your Mac OSx

1) brew install libxml2

2) Read complete error dump on console while you do "bundle" or "bundle install". You would notice that there are useful tips to fix this on your PC, example

for Building Nokogiri…

Read complete blog post

This post is an extension of Abhijit's article here - http://kiprosh.com/blog/180(Customizing Devise authentication, to disable or enable user authentication.) It helped me to add further customization to check if user has active chargify_subscription and then only proceed to login otherwise show custom message instead of default devise message.

Here is what we did (2 step process).

1) In our user model (specifically user_extensions) override devise method active_for_authentication as follows

Read complete blog post

Title: Issue installing gem 'eventmachine' while Migrating to Ruby 2.2.0 (specifically on OSX 10.10.1 Yosemite and XCode 6.1.1)

On my MAC, having OSX 10.10.1 Yosemite and XCode 6.1.1 (a recent upgrade), I faced couple of critical problems while migrating one of our app to latest Ruby 2.2.0

The bundler would scream for gem "eventmachine" version 1.0.3 or 1.0.4 installation. Errors such as these would terminate/halt bundler to carry out gems installation process on local - Failed to build gem…

Read complete blog post

E8a35961cc9ac2aca01c3a173f5c8d4a
Rohan Daxini

Recently, in one of our in-house app, we faced issues with RSolr that failed all our builds in CircleCI.

We faced following RSolr specific errors in our CircleCI builds for the repo.

RSolr::Error::Http:
RSolr::Error::Http - 500 Internal Server Error
Error: Severe errors in solr configuration.

Check your log files for more detailed information on what may be wrong.

If you want solr to continue after configuration errors, change:

    <abortOnConfigurationError>false</abortOnConfiguratio

Read complete blog post

Recently we had a bug in Knowbuddy app where search was not able to find anything based on sub keywords or sub text.

Example - Lets say we have an article that has keyword "dedicated" in subject or body or in tags. Now if we try to search using keywords say | cat | cate | ted | dedi | dicat | dedi | then outcome was zero search results.

This issue was due to the way indexing was done along with missing query configuration in Solr . We fixed the indexing and seaching conf in…

Read complete blog post

Following is an handy list of frequently used Linux (Ubuntu flavour) console commands

Find Files

find . -name '*.cnf'
find . -name 'hello.workd'

The dot here represents all files and folders in current path

Mysql DUMP - Import and Export

1) Export

mysqldump -u username -p database_name > file_name_to_save.sql

2) Import

mysql -u username -p database_name < filename.sql

Install LAMP on Ubuntu

sudo apt-get install tasksel
sudo tasksel
sudo tasksel install lamp-server

Install

Read complete blog post