Skip to content

Instantly share code, notes, and snippets.

View AtulKhanduri's full-sized avatar

Atul Khanduri AtulKhanduri

  • Noida
View GitHub Profile
@AtulKhanduri
AtulKhanduri / active_record_objects_autosave.md
Created April 25, 2018 07:06 — forked from demisx/active_record_objects_autosave.md
When Active Record Child Objects are Autosaved in Rails

belongs_to:

  1. Assigning an object to a belongs_to association does not automatically save the object. It does not save the associated object either.

has_one:

  1. When you assign an object to a has_one association, that object is automatically saved (in order to update its foreign key).
  2. In addition, any object being replaced is also automatically saved, because its foreign key will change too
  3. If either of these saves fails due to validation errors, then the assignment statement returns false and the assignment itself is cancelled.
  4. If the parent object (the one declaring the has_one association) is unsaved (that is, new_record? returns true) then the child objects are not saved. They will automatically when the parent object is saved.
@AtulKhanduri
AtulKhanduri / install-comodo-ssl-cert-for-nginx.rst
Created April 22, 2018 20:09 — forked from bradmontgomery/install-comodo-ssl-cert-for-nginx.rst
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

@AtulKhanduri
AtulKhanduri / db_backup_commands.md
Last active December 5, 2017 09:02
Commands to backup & restore database
  1. pg_dump is a nifty utility designed to output a series of SQL statements that describes the schema and data of your database. You can control what goes into your backup by using additional flags.
    Backup: pg_dump -h localhost -p 5432 -U postgres -d mydb > backup.sql

    Restore: psql -h localhost -p 5432 -U postgres -d mydb < backup.sql

    -h is for host.
    -p is for port.
    -U is for username.
    -d is for database.

@AtulKhanduri
AtulKhanduri / read_standard_input.js
Last active November 23, 2017 19:27
Read Standard Input from console in JS using Await, Async & Promise
// Option 1: Using ReadLine
async function read_stdin_using_readline () {
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
@AtulKhanduri
AtulKhanduri / docker-commands.md
Last active November 23, 2017 19:23 — forked from AtulKsol/docker-commands.md
Docker commands

Container's IP Address

  • docker inspect CONTAINER-ID | grep IPAddress

Container IP address using docker-compose

  • docker-compose ip

Stop and remove all container

  • docker stop $(docker ps -a -q)
  • docker rm $(docker ps -a -q)
@AtulKhanduri
AtulKhanduri / linux-commands.md
Last active May 14, 2016 07:32
Linux Commands

Run commands as super user

By default root account is locked under Ubuntu Linux. Therefore, you cannot login as root or use su - command to become a superuser.

You can use below methods to run commands as Adminintrator:

Add sudo before each command

Avoid typing sudo each and every time

sudo -i => This will start /bin/bash as a root shell so that you can enter a root user command without using sudo command.

@AtulKhanduri
AtulKhanduri / local-ssl.md
Created February 14, 2016 20:12
Using SSL in your local Rails environment. Runs localhost in HTTPS.

Using SSL in your local Rails environment

Also check this helpful gist.

For every other project, the requirement of using SSL HTTPS crops up. And I’m sure, just like me, you were annoyed that there doesn’t seem to be a simple way to test your SSL stuff in your local development environment.

Well: Not any more. Here’s how you set up your local Rails environment so that you can use SSL in development if you want or need to.

Note: I’m assuming you don’t want to mess with your local Apache but want to use the regular Rails server command.