Skip to content

Instantly share code, notes, and snippets.

@amitsaxena
amitsaxena / bootstrap.js
Created September 6, 2017 14:57
If you are using sails with waterline and struggling with timezones, try this first
// Add the following to your config/bootstrap.js file
process.env.TZ = 'UTC';
@amitsaxena
amitsaxena / gist:8601424
Last active October 18, 2019 21:51
CustomURL: Launch app if app is installed, else open an alternate URL (iOS all browsers)
<script type="text/javascript">
var timer;
var heartbeat;
var lastInterval;
function clearTimers() {
clearTimeout(timer);
clearTimeout(heartbeat);
}
@amitsaxena
amitsaxena / active_admin_custom_filter.rb
Last active October 24, 2019 11:42
How to write an Active Admin custom filter (custom search)
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:9cb0712e572c39a41edc
Last active October 24, 2019 12:37
CustomURL: Launch app if app is installed, else open an alternate URL (Android all browsers)
<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 / clone_website.sh
Created November 6, 2019 02:07
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 https://aawaara.com/
@amitsaxena
amitsaxena / cloudflare_worker_to_proxy_requests.js
Last active March 10, 2021 01:53
Cloudflare worker to proxy requests (any HTTP method) to a different origin
const base = "https://newsubdomain.example.com"
async function handleRequest(request) {
// Make a copy to allow mutation.
request = new Request(request);
// To override default caching mechanism and respect Cache-Control.
request.cf.cacheEverything = true;
// Extract path from request URL.
@amitsaxena
amitsaxena / generate_certificate.sh
Created June 20, 2018 00:22
Generate a free Let’s Encrypt wildcard SSL certificate for your domain
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 / dsvpn.sh
Last active July 24, 2022 12:54
Set up your own VPN server using DSVPN
# SSH to the EC2 instance and run these commands there
$ sudo yum update && sudo yum install gcc gcc-c++ make
$ sudo yum install git && git clone https://github.com/jedisct1/dsvpn.git && cd dsvpn
$ make
$ dd if=/dev/urandom of=vpn.key count=1 bs=32
$ base64 < vpn.key
# Copy the value obtained as output of the command above and use it on the client side
$ sudo ./dsvpn server vpn.key auto 1947
# Run these locally on your machine
@amitsaxena
amitsaxena / gist:0115d1d28fa90a5324560716b586d496
Last active January 24, 2024 23:08
Useful SQL queries for debugging
// Change SQL client timeout
set statement_timeout = '0s';
set statement_timeout = '10s';
// Change timeout globally
alter database mentimeter set statement_timeout = '10s';
// Time queries