Skip to content

Instantly share code, notes, and snippets.

Amit Saxena amitsaxena

Block or report user

Report or block amitsaxena

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
amitsaxena /
Created Nov 6, 2019
How to clone a website and host it on a domain of your choice on AWS S3
# Install wget and AWS CLI and set up your AWS credentials
# STEP 1
# Create a mirror of the website and re-write links
# --wait specifies that there is a wait of 1 second after each request.
# Be gentle with someone else's server. Also you risk being blocked if your request rate is too high
# Use -U to spoof user agent to that of an actual browser in case the server is blocking you from making requests
wget --mirror --convert-links --html-extension --wait=1 -o log
amitsaxena /
Created Jun 20, 2018
Generate a free Let’s Encrypt wildcard SSL certificate for your domain
curl | sh
# Open a new terminal window after executing above command
# Create a cloudflare account and get your API key from the profile section
export CF_Key=replace_with_cloudflare_api_key
# Generate wildcard certificate for * --issue -d -d '*' --dns dns_cf
amitsaxena / bootstrap.js
Created Sep 6, 2017
If you are using sails with waterline and struggling with timezones, try this first
View bootstrap.js
// Add the following to your config/bootstrap.js file
process.env.TZ = 'UTC';
amitsaxena / migrations.js
Last active Sep 2, 2017
Quickstart guide: Migrations with node.js
View migrations.js
// Install required modules as below:
npm install -g db-migrate
npm install -g db-migrate-mysql
// Create a database.json file:
"development": {
"driver": "mysql",
"host": "localhost",
amitsaxena / s3_bucket_policy.json
Last active Jun 20, 2016
How to return a 404 response code for CloudFront requests (S3 origin) of a non-existent S3 object:
View s3_bucket_policy.json
"Version": "2008-10-17",
"Id": "PolicyForCloudFrontPrivateContent",
"Statement": [
"Sid": "1",
"Effect": "Allow",
"Principal": {
"AWS": "Enter your CloudFront Origin Access Identity here"
amitsaxena / active_admin_custom_filter.rb
Last active Oct 24, 2019
How to write an Active Admin custom filter (custom search)
View active_admin_custom_filter.rb
ActiveAdmin.register MyModel do
filter :custom_field, :as => :string, :label => "Custom Field Display Name"
class MyModel < ActiveRecord::Base
search_methods :custom_field_search
def self.custom_field_search(name)
# This method should return an ActiveRecord::Relation Object with MyModel objects
# Put in your complex search logic here
amitsaxena / gist:689d29f23d01bd563839
Last active Aug 29, 2015
Ruby text only spinner/loader/processing/progress indicators && some FUN
View gist:689d29f23d01bd563839
# Loader for infinite time
["|", "/", "-", "\\"].each{|v| STDOUT.write "\r#{v}"; sleep 0.5} while 1
# In case you want to run it for a few seconds (~ 20s in the example below)
10.times{ ["|", "/", "-", "\\"].each{|v| STDOUT.write "\r#{v}"; sleep 0.5} }
# Progress Bar
100.times{STDOUT.write "|"; sleep 0.1}
# Another kind of loading indicator
amitsaxena / gist:9cb0712e572c39a41edc
Last active Oct 24, 2019
CustomURL: Launch app if app is installed, else open an alternate URL (Android all browsers)
View gist:9cb0712e572c39a41edc
<script type="text/javascript">
var custom = "myapp://custom_url";
var alt = "";
var g_intent = "intent://scan/#Intent;scheme=zxing;;end";
var timer;
var heartbeat;
var iframe_timer;
function clearTimers() {
amitsaxena / get_s3_file_sizes_recursively.rb
Last active Aug 29, 2015
Get file size of all the files at a given path on Amazon S3 - recursively, and dump in a CSV
View get_s3_file_sizes_recursively.rb
# Using aws-sdk gem
@access_key = "access_key"
@secret_key = "secret_access_key"
@bucket = "my_bucket"
:access_key_id => @access_key,
:secret_access_key => @secret_key
amitsaxena / gist:8625016
Created Jan 25, 2014
Custom URL: Launch app if app is installed, else open an alternate URL (iOS Safari only)
View gist:8625016
<script type="text/javascript">
var timer;
window.addEventListener("pageshow", function(evt){
}, false);
window.addEventListener("pagehide", function(evt){
}, false);
You can’t perform that action at this time.