Auto Generate Authority Signed Free SSL Certificates | HTTPS | Nginx

Well, there are a number of SSL Certification Authorities but all of them charges yearly fees for certificates they provide. I feel bad because, they are like middle-men do nothing but sign your certificates. But, if you don’t want to pay them you can get signed certificates from Continue reading

Rails | Avoiding race conditions while updating particular field in DB

It’s okay to make mistakes when you are up to building simple applications. But for mission critical applications like Banking/Payment Processors, you gotta be very careful and keep listening to seniors and experts in critical matters.

Lets say you are working on a feature to update the total amount deposited in a particular account. Simple code will do like

# just after amount is debited from payee's account
def credit_receiver_account(debited_amount)
  update_attribute :total_amount, total + debited_amount

What’s wrong with the code above?

Continue reading

Rails : Import CSV data to database

Actually there are various ways to achieve this. Firstly you can use the PostGreSQL’s copy command. Secondly you can choose to use Ruby to load data.

Using copy command in PG

Create your table:

CREATE TABLE zip_codes 
(ZIP char(5), LATITUDE double precision, LONGITUDE double precision, 
CITY varchar, STATE char(2), COUNTY varchar, ZIP_CLASS varchar);

Copy data from your CSV file to the table: Continue reading

Mock HTTP using VCR with RSpec | Mock Authy | Rails

Well, slower test suite is a nightmare both in your local machine and in your CI server. If your gem provider has built some Mocking APIs then its cool. But, no mocking API and you are writing Unit Test for your models and controller then beware, do not leave your app making HTTP requests everytime.

What to do?

If you cannot mock your library then mock the damn Internet. Simple enough! you can get going in a couple of minutes. Continue reading

Rails : Mass assignment with ids in seeds.rb | PG::UniqueViolation: ERROR

Looks like you can mass-assign records into ActiveRecord models without any problem like

                    { parent_id: 1, name: 'Computer Science', description: 'Readable via Electronic devices.' },
                    { parent_id: 1, name: 'Electronics' },
                    { parent_id: 1, name: 'Law' },
                    { parent_id: 1, name: 'Social' }

But you cannot do like Continue reading

Redux in a nut shell

What is Redux?

Redux is a predictable state container for JavaScript apps.

In this tutorial we will create an awesome Redux app in organized fashion. But at first we will create an app in single file, analyse it and break it down to more manageable chunks of components and organize it in a comprehensible dir-structure. Continue reading

Simply Deploy React.js App to Heroku

If you have read my another post about creating a ToDo app in react you are good to go; if not see this post.

You know that React App is a single page application containing only static assets. So, you only need to setup a mechanism to serve your static assets like CSS, JS, HTML, IMAGE, etc. files when clients ask for. Either you can use market leader HTTP servers like Apache, Nginx, etc or simple Express server that runs in Node.js.

Continue reading