Photo upload from phone-gallery or phone-camera in Ember-Cordova Application

Currently am working on Ember Application, and for the same we have also developed cordova application using ember-cli-cordova plugin https://github.com/poetic/ember-cli-cordova In this application, we have a photo upload feature. Using cloudinary.js, we upload it directly to cloudinary on photo-selection. In web-application, we have added a hidden file input field, and on-click of "Add Image" button, we triggered click event on that file-input. In Cordova-App, It works fine and just allows us to upload images from phone-gallery, but does not allows us to use phone-camera to take a pic and upload it. (Note: In

Preloading associations while using find_by_sql

To preload the associated records we generally use #includes, #preload or #eager_load for more information please see this blog This will work perfectly if we preload associations for an ActiveRecord::Relation, but in case if we want to load associated records for an Array, these methods will fail Let's consider this example class Company < ActiveRecord::Base has_many :users end class User < ActiveRecord::Base belongs_to :company end Say we have a query, which is performing joins and also have sub queries, then we would need to use find_by_sql, to generate the query. But find_

Quick dive into Elixir, Phoenix and Erlang ecosystem

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 steps of Elixir & Erlang on Mac, Ubuntu or Windows machine as lot of help is already

How to auto run `rake db:migrate` after deploying to Heroku

As you know Heroku **does not ** run rake db:migrate automatically. Most of the time we all face this issue of not running migrations on Heroku post deployment. Either we forget or for some reason we miss it. However there are some gems/plugins that help us overcome these issues. Even when we use [heroku auto deployment] [12] feature, there also we need to run rake db:migrate manually and Heroku will not run it automatically for us. That means it is not fully automatic. When I setup heroku auto-deployment I wanted everything to happen automatically, why should I run

Auto-Deployment with Heroku of Github/Bitbucket Source Code

While we deploy our changes to heroku, we use deployment scripts or setup yml in CI server. However Heroku has come up with an auto-deployment feature and for that we do not need to use even command line tools. To take advantage of this feature you should use Github/Bitbucket version control system If your Github/Bitbucket repo is setup and you have already pushed your code to Github then you are good to start with heroku I assume that you already have Heroku account and heroku-toolbelt is setup on your system. Now create an app on heroku for your

Access files from sftp server

In one of the feature, we had to import xlsx which was exported from sqlite database dump. The rows had few image names which was uploaded to sftp server. We had to upload those to images on S3. Importing xlsx row data was simple but the challenge was how to upload images from sftp server to S3. This is where net-sftp gem came to our rescue (though its not managed anymore). To get this working, we need 4 things: host, username and password using which we are going to login to sftp server and path where images are uploaded. We

ActiveRecord::RecordNotUnique (duplicate key value violates unique constraint). Key already exists.

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 111, but that 'id' already exist. The primary key which is suppose to auto-increment and generate an unique id

Using Stripe API for Payment Transactions and generating Sales Report

Recently we had requirement to generate weekly sales report in one of the E-commerce apAs we were using Stripe services for payment handling, I studied some of Stripe API methods and how it actually works. So in this article I will briefly explain how we can handle payment through Stripe and how we can get sales data from Stripe. Firstly these are few basic steps to start using Stripe API: Add 'stripe' gem to your gemfile. bundle it You will get secret and public key pairs for live and test mode each from your Stripe account. You need to set

RUBY Quick Tip : Share your local folder with everyone over LAN

This is very useful Ruby command to share your local folder with everyone on the same network. Thanks to Rohan! As we were working on something and he wanted me to share my local folder quickly. Rohan shared this Ruby command with me and since then every now and then I am using it in office to share stuff with teams. Command is: ruby -rwebrick -e 'WEBrick::HTTPServer.new(:Port=>PORT_NUMBER,:DocumentRoot=>”DIRECTORY_PATH").start' e.g. ruby -rwebrick -e 'WEBrick::HTTPServer.new(:Port=>2121,:DocumentRoot=>”/home/public/picture").start' PORT_NUMBER - Port to listen a request DIRECTORY_

Javascript - Shorthand for Switch statement

You might have seen similar code in javascript. I wanted to understand how it is working. As it does not look like a ternary expression. return { "false": React.DOM.a({ href: "javascript:void(0)", onClick: this.linkClicked }, "Click Me Now"), "true": React.DOM.span({}, "You have clicked") }[this.state.clicked]; While discussing with team we found that, it is nothing, but a SWITCH CASE click her to see shorthand for js So when we execute above mentioned code, if "this.state.clicked" is TRUE then it will show SPAN with text 'You have clicked'". This is just