Posts

Debug Nodejs inside docker container

If you want to debug a node js or express application that is running inside a docker container please follow the below steps. Step1:   add pryjs in you package.json and run npm install    or    npm install --save pryjs Step 2:   Go to your docker-compose file and find the specific docker container which you want to debug.   Ex. if your container name is an app then please add the below lines   app:     stdin_open: true     tty: true Step 3:   Go the specific file where you want to debug and require the library     var pry = require('pryjs');   Then add the script to the specific like where you want to stop the execution.     eval(pry.it) Step 4:   Run the docker compose file and attach the specific process     docker-compose up -d && docker attach $(docker-compose ps -q app) It will stop the execution in the specific line once the request will hit that specific line Please check the documentation for a more pry option.

Swap primary keys between two records in the same table in Postgres

What if we need to swap two primary keys on the same table? What's the best and efficient way to do the same? let's check Now:- Let's assume we have a user table which has 3 columns among all the rows I have taken two sample rows which are the target rows for us. Id Name Email 101 Sabyasachi XX@gmail.com 105 Saghosh xxx@gmail.com We need to swap the primary keys (which are unique by nature) between those two records so our desired result will be something like   Id Name Email 105 Sabyasachi XX@gmail.com 101 Saghosh xxx@gmail.com Now lets buield a query using CTE(common table expression) to solve the problem:- with source_user as (   select     id   from     users   where     id = 101 ), destination_user as (   select     id   from     users   where     id

How to add a bootstrap table with fixed header and scrollable body

I am pretty sure that everyone is familiar with bootstrap CSS, if not please take a look(bootstrap). Now Bootstrap has lots of different components and table styling is one of them and they have plenty of different styling options. Now sometimes if we have to display a large amount of data inside a table, the user will have to scroll till the end of the table and after few scroll, they can not see the table header. There is a way to fix this. Please follow the below steps. Step1: Create a bootstrap table first <table class="table table-fixed">   <colgroup></colgroup>   <colgroup class=""></colgroup>   <thead>   <tr>     <th>       <label>         ##       </label>     </th>     <th>       <label class="">         ###       </label>     </th>   </tr>   </thead>   <tbody id="fixed-height">       <tr>         &

Upgrade Postgres 9.4 to 9.6 in MAC.

Postgres 9.6.1 is the current Postgres version, if you want to upgrade the Postgres version in mac it very easy now using homebrew. Just follow the below steps Step 1: Turn PostgreSQL off first:     $ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist     # or, if you're running a current version of Homebrew     $ brew services stop postgresql Step 2: Update brew and upgrade Postgres     $ brew update && brew upgrade postgresql Step 3: Initialize the new empty database     $ initdb /usr/local/var/postgres9.6.1 -E utf8 Step 4: When we update check the currently available version of the system     $ ls /usr/local/Cellar/postgresql/ Which gives you output something like this: 9.4, 9.5.0, 9.6.1 If you have more than two, that’s ok, just get the most recent one (9.6.1) and the last before 9.5.0. Remember that version for the next step. Step 5: Upgrade the version $ pg_upgrade \   -d /usr/local/var/postgres \   -D /usr/local/var/postgre

Insert Bulk data using active record import

Imagine a scenario where you have to create a report and send it to multiple clients, so lets just say you have a report model and you have client and you have report client model. lets first check all the association and model structure. #report model class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients end #report_client class ReportClient < ActiveRecord::Base   belongs_to :report   belongs_to :client end #clients class Client < ActiveRecord::Base   has_many :report_clients   has_many :reports, through: :report_clients end No lets say you want to create a report for 30 clients. You can do that by adding nested attributes in rails. so our report model will became  class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients   accepts_nested_attributes_for :report_clients, :reject_if => proc { |attributes| att

Insert Bulk data using active record import

Imagine a scenario where you have to create a report and send it to multiple clients, so lets just say you have a report model and you have client and you have report client model. lets first check all the association and model structure. #report model class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients end #report_client class ReportClient < ActiveRecord::Base   belongs_to :report   belongs_to :client end #clients class Client < ActiveRecord::Base   has_many :report_clients   has_many :reports, through: :report_clients end No lets say you want to create a report for 30 clients. You can do that by adding nested attributes in rails. so our report model will became  class Report < ActiveRecord::Base   has_many :report_clients   has_many :clients, through: :report_clients   accepts_nested_attributes_for :report_clients, :reject_if => proc { |attributes| att

Postgres database is not running after OSX crash

Every one might have face the problem that Postgres id not running after OSX is crashed. Every time you try to start the Postgres server it will say : - another server might be running; trying to start server anyway You can follow the below steps to get rid of the problem. Step 1: Open your terminal and run   pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start   It will Say   pg_ctl: another server might be running; trying to start server anyway Step 2:  Check the log $ tail -f /usr/local/var/postgres/server.log It will print something like this FATAL:  lock file "postmaster.pid" already exists HINT:  Is another postmaster (PID 326) running in data directory "/usr/local/var/postgres"? FATAL:  lock file "postmaster.pid" already exists HINT:  Is another postmaster (PID 326) running in data directory "/usr/local/var/postgres"? Step 3: Delete the PID file. $ rm /usr/local/var/postgres/postmaster.pid S