Skip to content

Instantly share code, notes, and snippets.

View abhishek77in's full-sized avatar

Abhishek Srivastava abhishek77in

View GitHub Profile
@abhishek77in
abhishek77in / db_guidelines.md
Created November 19, 2022 19:06 — forked from adamrdavid/db_guidelines.md
the darndest things
@abhishek77in
abhishek77in / cname_check.rb
Last active September 23, 2022 18:04 — forked from Maysora/cname_check.rb
Ruby DNS CNAME check
require 'resolv'
url = 'www.diagnofy.in'
begin
r = Resolv::DNS.open do |dns|
dns.timeouts = 1
dns.getresource(url, Resolv::DNS::Resource::IN::CNAME)
end
r.name.to_s # => return alias domain
rescue Resolv::ResolvError => e
@abhishek77in
abhishek77in / nginx.conf
Created April 16, 2016 21:36 — forked from thewebfellas/nginx.conf
sample nginx.conf for thin
user nginx;
worker_processes 5;
error_log /var/log/nginx.error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
@abhishek77in
abhishek77in / install_ruby_rpi.sh
Created April 11, 2016 18:48 — forked from blacktm/install_ruby_rpi.sh
A Bash script to install Ruby 2.3 on the Raspberry Pi (Raspbian)
#!/bin/bash
# -----------------------------------------------------------------------
# Installs Ruby 2.3 using rbenv/ruby-build on the Raspberry Pi (Raspbian)
#
# Run from the web:
# bash <(curl -s raw_script_url_here)
# -----------------------------------------------------------------------
# Set up variables
@abhishek77in
abhishek77in / subdomain_validator.rb
Created February 2, 2016 10:20 — forked from stuartbain/subdomain_validator.rb
Custom validator for Subdomains
class SubdomainValidator < ActiveModel::EachValidator
# http://matthewhutchinson.net/2010/10/27/rails-3-subdomain-validation-activemodeleachvalidator
# http://www.rails-dev.com/custom-validators-in-ruby-on-rails-4
def validate_each(object, attribute, value)
return unless value.present?
reserved_names = %w(www ftp mail pop smtp admin ssl sftp)
reserved_names = options[:reserved] if options[:reserved]
if reserved_names.include?(value)
object.errors[attribute] << 'cannot be a reserved name'
@abhishek77in
abhishek77in / backup.rake
Last active April 13, 2021 00:09 — forked from rantoniuk/backup.rake
Rake task for backing up MySQL database to AWS-S3 in Rails Application
namespace :db do desc "Backup database to AWS-S3"
task :backup => [:environment] do
datestamp = Time.now.strftime("%Y-%m-%d_%H-%M-%S")
backup_filename = "#{Rails.root.basename}-#{datestamp}.sql"
db_config = ActiveRecord::Base.configurations[Rails.env]
# process backup
`mysqldump -u #{db_config['username']} -p#{db_config['password']} -i -c -q #{db_config['database']} > tmp/#{backup_filename}`
`gzip -9 tmp/#{backup_filename}`
puts "Created backup: #{backup_filename}"