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
amitsaxena / generate_certificate.sh
Created Jun 20, 2018
Generate a free Let’s Encrypt wildcard SSL certificate for your domain
View generate_certificate.sh
curl https://get.acme.sh | 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_Email=my.cloudflare@example.com
export CF_Key=replace_with_cloudflare_api_key
# Generate wildcard certificate for *.example.com
acme.sh --issue -d example.com -d '*.example.com' --dns dns_cf
@amitsaxena
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
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
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: http://aawaara.com/post/146226425447/how-to-return-a-404-response-code-for-cloudfront
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
amitsaxena / active_admin_custom_filter.rb
Last active Mar 25, 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"
end
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
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
amitsaxena / gist:9cb0712e572c39a41edc
Last active Jun 17, 2016
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 = "http://mywebsite.com/alternate/content";
var g_intent = "intent://scan/#Intent;scheme=zxing;package=com.google.zxing.client.android;end";
var timer;
var heartbeat;
var iframe_timer;
function clearTimers() {
clearTimeout(timer);
@amitsaxena
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"
AWS.config(
:access_key_id => @access_key,
:secret_access_key => @secret_key
)
@amitsaxena
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){
clearTimeout(timer);
}, false);
window.addEventListener("pagehide", function(evt){
clearTimeout(timer);
}, false);
@amitsaxena
amitsaxena / gist:8601424
Last active Jun 1, 2016
CustomURL: Launch app if app is installed, else open an alternate URL (iOS all browsers)
View gist:8601424
<script type="text/javascript">
var timer;
var heartbeat;
var lastInterval;
function clearTimers() {
clearTimeout(timer);
clearTimeout(heartbeat);
}
You can’t perform that action at this time.