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 / 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
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;
}
@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 / 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 / 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
@abhishek77in
abhishek77in / endless-scroll.js
Last active December 26, 2015 21:59
Simple script for implementing endless scroll
var offset = 4;
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() > ($(document).height() - 150)) {
loadMore(offset);
offset = offset + 4;
}
});
function loadMore(offset) {