Skip to content

Instantly share code, notes, and snippets.

View pranavcode's full-sized avatar

Pranav Kulkarni pranavcode

View GitHub Profile
#!/bin/bash
# Specify the desired volume size in GiB as a command-line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}
# Get the ID of the environment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data//instance-id)
# Get the ID of the Amazon EBS volume associated with the instance.
VOLUMEID=$(aws ec2 describe-instances \
@pranavcode
pranavcode / gzip_s3_and_json_py3.py
Created September 5, 2020 22:00 — forked from a-hisame/gzip_s3_and_json_py3.py
To use gzip file between python application and S3 directly for Python3
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''To use gzip file between python application and S3 directly for Python3.
Python 2 version - https://gist.github.com/a-hisame/f90815f4fae695ad3f16cb48a81ec06e
'''
import io
import gzip
import json
@pranavcode
pranavcode / hello.html
Created June 2, 2019 15:16
Numbers within String input HTML/JavaScript
<html>
<head>
<title>Numbers within String input HTML/JavaScript</title>
<script type="text/javascript">
function qa_calculate_1(inp) {
if (!inp) {
return "Invalid Input: Nothing entered";
}
var re = /[+-]?[0-9]+/g;
var m;

Please follow these simple steps to make sure your PR gets enough attention, is reviewed and merged.

Checklist for REQUESTER

  1. You have a good, informative and precise TITLE to tell exactly what your PR is about.

  2. You have a great DESCRIPTION to describe what has been achieved in this PR.

    • Refer to an open issue that gets resolved with this PR.
    • Talk about the approach taken for the solution.
  • Include images, screenshots and diagrams relevant to understand the PR better.
@pranavcode
pranavcode / consul-intentions.sh
Last active January 5, 2020 11:07
Velotio - HashiCorp Consul Part 2 - Adding Consul intentions to allow or deny connection between services
# Allow connection from Django App (Web) to MongoDB Primary instance (DB)
$ consul intention create -allow web mongo-primary
Created: web => mongo-primary (allow)
# Allow connection from Django App (Web) to MongoDB Secondary instance (DB)
$ consul intention create -allow web mongo-secondary
Created: web => mongo-secondary (allow)
# Deny connection from Fabio (LB) to MongoDB Primary instance (DB)
$ consul intention create -deny fabio mongo-primary
@pranavcode
pranavcode / run-consul-connect-proxy.sh
Created April 1, 2019 19:07
Velotio - HashiCorp Consul Part 2 - Running a Consul Connect Sidecar Proxy for Django Web Application instance
$ consul connect proxy -sidecar-for web
@pranavcode
pranavcode / django-consul-connect.json
Last active April 1, 2019 19:07
Velotio - HashiCorp Consul Part 2 - Enable Consul Connect Sidecar Service for Django App and MongoDB Primary
{
"service": {
"name": "web",
"port": 8000,
"tags": [
"web",
"application",
"urlprefix-/web"
],
"connect": {
@pranavcode
pranavcode / enable-consul-connect.json
Created April 1, 2019 16:30
Velotio - HashiCorp Consul Part 2 - Enable Consul Connect in server configuration
{
"connect": {
"enabled": true
}
}
@pranavcode
pranavcode / django-settings.py
Created April 1, 2019 14:55
Velotio - HashiCorp Consul Part 2 - Using python-consul to consume Consul's KV store to configure Django Web Application
# Set DEBUG flag using Consul KV store
index, data = consul_client.kv.get('web/debug')
DEBUG = data.get('Value', True)
# Set ALLOWED_HOSTS dynamically using Consul KV store
ALLOWED_HOSTS = []
index, hosts = consul_client.kv.get('web/allowed_hosts')
ALLOWED_HOSTS.append(hosts.get('Value'))
@pranavcode
pranavcode / consul-connection.py
Created April 1, 2019 14:50
Velotio - HashiCorp Consul Part 2 - Using python-consul to connect to Consul's KV store to fetch configuration parameter
import consul
consul_client = consul.Consul(
host='consul_server',
port=8500,
)