Skip to content

Instantly share code, notes, and snippets.

View datt's full-sized avatar
🏠
Working from home

Dattatraya Dongare datt

🏠
Working from home
View GitHub Profile
@datt
datt / postgres_backup.sh
Last active November 6, 2023 10:33
Postgres Backup script
#!/bin/bash -x
export PGPASSWORD=myPGPassword
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
#Script Begin
DATE=`date +%d_%m_%Y_%H_%M`
if ! /usr/bin/pg_dump -O -U postgres -h localhost project_production -f /root/backups/postgres/daily/project_production_pg_$DATE.sql; then
/bin/echo "#########################################################" >> /var/log/postgres_backup.log
/bin/echo "Postgres Backup backup failed on `date +%d-%m-%Y`" >> /var/log/postgresql_backup.log
@datt
datt / database.yml.myql
Last active April 7, 2021 13:31
Rails Database yml examples for postgres sqlite and mysql
# Install the MySQL gem:
# gem install mysql2
default: &default
adapter: mysql2
encoding: utf8mb4
reconnect: false
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: root
password:
@datt
datt / install.sh
Last active January 11, 2021 08:02
rails setup commands on aws
sudo apt-get install git
sudo apt-get install nginx
sudo apt-get install nodejs
sudo apt-get install imagemagick
sudo apt-get install libpq-dev #postgres ext lib required
sudo apt update
sudo apt-get install libmagick++-dev #imagemagick dependency
# Installing Ruby using .rbenv
sudo apt install git curl autoconf bison build-essential \
@datt
datt / tic_tac_toe.rb
Created August 8, 2020 01:11
Tic Tac Toe solution in Ruby
class TicTacToeBoard
SYMBOLS = ['X', 'Y']
WINNING = [
[0,1,2], [3,4,5], [6,7,8],
[0,3,6], [1,4,7], [2,5,8],
[0,4,8], [2,4,6]
]
def initialize()
@board = [['','',''], ['','',''], ['','','']]
end
@datt
datt / longest_distinct_substring.rb
Created July 31, 2020 16:56
Finding length of longest substring code in Ruby. Uses Ruby's core methods, may not be efficient for other languages. Probably one of the fastest solution implemented in Ruby, suggestions are welcomed.
# Rough Algo
# 1. Initialize last_distinct with first character
# 2. Iterate character by character
# 3. if no repeating char, Push current character in last_distinct
# 4. Repeat 3 until repeating char found
# 5 if repeating char found
# 6 if repeating char at first place, drop and rotate
# 7. if repeating char not at first place, reset with char and set longest.
class LongestDistinctSubstring # Finds length of the longest substring
@datt
datt / CRUDActions
Created August 6, 2018 13:49 — forked from prcongithub/CRUDActions
Simple Lightweight module for clean, dynamic and highly optimised API controllers
require 'active_support'
module CRUDActions
extend ActiveSupport::Concern
included do
before_action :set_resource, only: [:show, :update, :destroy]
after_action :set_response_headers, only: [:index]
end
# Returns count of records matching the scope
@datt
datt / letsencrypt_2017.md
Created May 18, 2018 11:42 — forked from cecilemuller/letsencrypt_2020.md
How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

How to setup Let's Encrypt for Nginx on Ubuntu 16.04 (including IPv6, HTTP/2 and A+ SLL rating)

There are two main modes to run the Let's Encrypt client (called Certbot):

  • Standalone: replaces the webserver to respond to ACME challenges
  • Webroot: needs your webserver to serve challenges from a known folder.

Webroot is better because it doesn't need to replace Nginx (to bind to port 80).

In the following, we're setting up mydomain.com. HTML is served from /var/www/mydomain, and challenges are served from /var/www/letsencrypt.

@datt
datt / rails.logrotate
Created March 3, 2018 16:01 — forked from constantinoneto/rails.logrotate
Logrotate for Rails
#
# File: /etc/logrotate.d/rails
# Test: logrotate -f /etc/logrotate.d/rails
#
/var/www/*/log/*.log {
daily
dateext
notifempty
missingok
rotate 30
@datt
datt / install-comodo-ssl-cert-for-nginx.rst
Created April 12, 2017 11:40 — 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

@datt
datt / postgres_useful_commands.sh
Last active April 2, 2017 13:37
useful database commands for dump i.e. backup and restore postgresql and mongodb
#resetting the password of postgresql
sudo -u postgres psql postgres
postgres=# \password postgres
# restoring postgres dump database
pg_restore -c -i -U postgres -h localhost -d database_name -v "dump_file" -W
pg_restore --verbose --host localhost --username postgres --clean --no-owner --no-acl --dbname database_name dump_file.dump
# for mac: full path is required.
Applications/Postgres.app/Contents/Versions/9.4/bin/pg_restore -c -i -U postgres -h localhost -d database_name -v "dump_file" -W