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 / 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 / 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 / .htaccess
Created November 18, 2016 08:17
.htaccess for redirecting to www.domain.com and leverage browser catching, compression on
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
## don't touch /forum URIs
#RewriteRule ^forums/ - [L,NC]
## hide .php extension snippet
@datt
datt / environment
Created July 15, 2016 05:53
FIX for 'perl: warning: Setting locale failed.'
# Add following lines in /etc/environment to fix the warnings.
LANGUAGE=en_US.UTF-8
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
LC_TYPE=en_US.UTF-8
@datt
datt / create_deploy.sh
Created July 4, 2016 07:57
create a deploy user with no password.
#Login from root
adduser deploy
# set a pssowrd if asked.
# Run visudo and add following line
%deploy ALL=(ALL) NOPASSWD: ALL