Display line numbers in GNU Nano text editor

These days developers go for heavy text-editors and IDEs like InteliJ, PyCharm, RubyMine, Sublime Text with much more extensions, Vim, Emacs, etc. However, in case of the later two they are not memory and processor heavy however they have very steep learning curves.

On the other hand, GNU Nano come as a life saver. It requires a few MB of RAM(say 3-4 MB) and uses very less CPU resource. Nano is a much powerful tool with much more features.

Continue reading

Advertisements

Memory Management Techniques in C

 

Computer’s primary memory is divided into four segments, namely: data, stack, heap and code.

What is Memory Management?

You are already familiar with the notion that Memory is most expensive resource in the system. Therefore you only use and ask for amount of memory that will suffice. As soon as you are done, you free up the memory so that OS can sell those memory blocks to some other needy software. This practice of using memory wisely is known as Memory Management. Continue reading

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 letsencrypt.org. 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
end

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

Category.create([
                    { 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