Posts

NodeJs Interview Questions

Image
Node.js has over 450K modules as of this writing, and is one of the popular frameworks for fast and robust frameworks. Typically they are implemented with microservices. Below are some NodeJs interview questions, you need to prepare 1. Have you incurred any memory leak issues in Node.js memory leaks occur where there are short lived objects assoicated with a long term object e.g  const req = new Map() app.get("/", (req,res_ => {   request.set(req.id, req)   res.send(200).send("hello world") }             Identify it using Sample Heap Profiler.           For more info refer 2. Explain what is Exception Handling you used in Node.js     Node.js exception handling is different than traditional Java based exception handling, there are multiple ways exception can be handled based on the need.     Overall there are two types of Exception System Exceptions...

Rails Goodness: bundle exec when Ruby versions mismatch errors

Rails is sometiems wierd, it complains that the ruby version you are running is different than what is specified in Gemfile. But when I see the version, using $ ruby -v, it all looks good. Only solution is to force rails to look for ruby version, inside the directory you are working on, and the way to do it is, using bundle exec, like so   » RAILS_ENV=development bundle exec rake app:run   Thank you!!

Git: How to generate a diff file in git

Tools like reviewboard, allow you the generate code reviews, although they have a rbt tool to generate the code review with diff, sometimes there is a need to generate this diff file manually and upload it, Below command  $  git show --full-index > ~/mytest.diff will generate the diff file which you can use for the same

Git: How to Squash your commits into one commit before merging

When you are doing a feature development, typically there are many local commits which happen, its always a good idea that squash all those commits into one commit and then merge them to the master branch. Below are the steps to do the same #Step1 : Start git rebase in interactive mode $ git rebase -i master #once you do this, you will all your commits in an editor likewise pick 1b6f7fed87 feature1 pick 1b6f7fed85 old commit1 pick 1b6f7fed83 old commit2 pick 1b6f7fed81 old commit3 # Rebase 806f77feab..1b6f7fed87 onto 806f77feab (1 command) # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # d, drop = remove commit # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove...

Rails Goodness : What is Jsonify in Rails, Why is needed for REST based controllers

JSONIFY is one of the original ways on how you can Rails converts its Models to JSON Views. With .jsonfiy in your View, you can move the shenanigans of converting the models to JSON views .jsonify file. It will also allow you to filter out  or convert the model to the desired JSON output. If you are using pure REST controllers with no views, you need to have a .jsonfiy file (blank file in view folder is fine as well), for the controllers and rspec to work. sample .jsonfiy file json.applications(@applications) do |app| json.id app.id json.name app.name.force_encoding(Encoding::UTF_8) json.guid app.guid.to_s json.icon app.icon_path json.created_at app.created_at.localtime json.created_at_human l(app.created_at.localtime, :format => :human_date) json.updated_at app.updated_at.localtime json.updated_at_human l(app.updated_at.localtime, :format => :human_date) end

Rails Goodness : How to Test/Update Your Migration, Add a forgotten index

Once you have create a migration say, class CreateEmployees < ActiveRecord::Migration def change create_table :employees do | t | t.string :first_name t.string :last_name t.string :icon t.integer :emp_id t.timestamps end end end And now lets say you need to add an index to it, below are the steps Step1. Rollback the current migration   RAILS_ENV=development rake db:rollback             Step2 Add the Index to the migration manually class CreateEmployees < ActiveRecord::Migration def change create_table :employees do | t | t.string :first_name t.string :last_name t.string :icon t.integer :emp_id t.timestamps end add_index :employees, [:first_name] end end Step3. Test the migration by moving 10 steps behind in schema.rb and then redoing till current   RAILS_ENV=development rake db:migrate:redo STEP =10 The Steps can be any number, just to ensure robu...

Rails - Part1 - Employee CRUD API - Create a table , model and migration in Rails

Rails is a convention over configuration framework, Rails4 makes life simpler on how you can quickly put things in perspective. In this Series, we will start with a Employee Model, Create its corresponding tables, migrations and then expose the Employee Model in the Rails API. https://github.com/makrand-bkar/emp-hello Part1 - We will create the Model, its table and corresponding Factory and test API. Problem Statement Lets say we want to create a Simple Employee  table Employee {   first_name : string,   last_name :  string,   icon          :  string,   emp_no    :  integer } Assumptions I am assuming that you already have rails project running and we will just adding to the existing product. You can clone the initial project from https://github.com/makrand-bkar/emp-hello Step1 : Create a Model for Employee RAILS_ENV =development rails g model Employee first_name: string last_name: st...