Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 / 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 / migrations.js
Last active September 2, 2017 12:05
Quickstart guide: Migrations with node.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 June 20, 2016 22:19
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
{
"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 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:689d29f23d01bd563839
Last active August 29, 2015 14:07
Ruby text only spinner/loader/processing/progress indicators && some FUN
# 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