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 / flatten_hash.rb
Created August 8, 2014 19:41
Flatten ruby hash, Could be used to convert nested ruby hash (or json) to csv
def flatten_hash(hash, results = {}, parent_key = '')
return results unless hash.kind_of?(Hash)
hash.keys.each do |key|
# current_key = "#{parent_key}[#{key}]" # uncomment this if you want to keep parent key as a partof key for flattened hash (csv column name)
current_key = key
if hash[key].kind_of?(Hash)
results = flatten_hash(hash[key], results, current_key)
else
if hash[key].kind_of?(Array)
@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 / caddy_ec2_ubuntu22_04.sh
Last active September 23, 2022 11:17
Script to install caddy on ubuntu 22.04 aws ec2
#!/bin/bash
sudo apt update
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
caddy version
sudo systemctl status caddy
sudo systemctl enable caddy
@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}"
@abhishek77in
abhishek77in / report.rb
Created December 9, 2012 19:31
Create a PDF Document using Prawn Library with header, footer and page numbering.
require "prawn"
Prawn::Document.generate("report.pdf") do
10.times do
start_new_page
end
repeat :all do
move_down 50
@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 / heroku-db.sh
Last active December 16, 2018 03:36
Import heroku database to local machine
heroku pg:backups:capture --app sushi
curl -o latest.dump `heroku pg:backups public-url --app sushi`
curl -o latest.dump `heroku pg:backups:url b001 --app sushi`
pg_restore --verbose --clean --no-acl --no-owner -d <app_name>_development latest.dump
# Restore data from trial server
curl -o latest.dump `heroku pg:backups public-url --app labsmart-trial`
be rake db:drop db:create
pg_restore --verbose --clean --no-acl --no-owner -d azurite_development latest.dump
var printPage = (function () {
var style = document.createElement('style');
$(".columns").append(style)
return function (rule) {
style.innerHTML = rule;
};
}());
printPage.size = function (marginTop) {
printPage('@media print { @page {margin-top: ' + marginTop + 'cm} }');
@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;
}