Skip to content

Instantly share code, notes, and snippets.

View sairamkrish's full-sized avatar

Sairam Krish sairamkrish

View GitHub Profile
@sairamkrish
sairamkrish / views.py
Created August 9, 2018 19:38
Sample django rest endpoint
class InventoryViewSet(viewsets.ModelViewSet):
keycloak_scopes = {
'GET': 'invetory:view',
'POST': 'inventory:add',
'PUT': 'inventory:update',
'DELETE': 'inventory:delete'
}
serializer_class = InventorySerializer
queryset = Inventory.objects.all().order_by('inventory_id')
filter_backends = (filters.DjangoFilterBackend, )
@sairamkrish
sairamkrish / docker-compose.yml
Created August 29, 2018 19:06
Overriding html templates inside superset
version: '3.6'
services:
superset:
image: amancevice/superset:0.25.6
ports:
- "8088:8088"
volumes:
- ./superset-conf/config:/etc/superset
- ./superset-conf/templates/appbuilder/navbar.html:/usr/local/lib/python3.5/dist-packages/superset/templates/appbuilder/navbar.html
@sairamkrish
sairamkrish / object_to_dict_recursive.py
Last active August 24, 2023 23:25
Python object to dictionary - recursively convert
'''
Generic object to dict converter. Recursively convert.
Useful for testing and asserting objects with expectation.
'''
def todict(obj, classkey=None):
if isinstance(obj, dict):
data = {}
for (k, v) in obj.items():
data[k] = todict(v, classkey)
@sairamkrish
sairamkrish / distance_between_two_geo_coordinates
Created January 23, 2019 12:15
Distance between two geo points
'''
Used for testing purpose, during development. Not for production
'''
def distance_between_two_geo_coordinates(start_lat, start_long, end_lat, end_long):
from math import radians, sin, cos, acos
print("Input coordinates of two points:")
slat = radians(start_lat)
slon = radians(start_long)
elat = radians(end_lat)
@sairamkrish
sairamkrish / Dockerfile
Created March 6, 2019 12:05
Dockerfile for NodeJS application
FROM node:10.15.2-alpine
WORKDIR /home/app
EXPOSE 3000 3000
ADD yarn.lock package.json ./
RUN yarn install
COPY . .
ENTRYPOINT [ "yarn","start" ]
docker build -t myapp .
version: "3"
services:
postgres:
image: postgres:11.2-alpine
environment:
POSTGRES_PASSWORD: '!abcd1234'
POSTGRES_USER: purplecow
POSTGRES_DB: purple_cow
volumes:
- ./postgres-data:/var/lib/postgresql/data
@sairamkrish
sairamkrish / ConvertPropertiesToCfn.java
Last active May 3, 2019 13:15
This class helps to convert a property file entries into cloudformation script to add them as SSM::Parameter
package java_experiments;
import java.io.IOException;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
/*
* This class helps to convert a property file entries into cloudformation script to add them as SSM::Parameter
@sairamkrish
sairamkrish / Dockerfile
Created November 7, 2019 09:30
Openresty based custom Docker
FROM openresty/openresty:alpine-fat
RUN mkdir /var/log/nginx
RUN apk add --no-cache openssl-dev
RUN apk add --no-cache git
RUN apk add --no-cache gcc
RUN luarocks install lua-resty-openidc
ENTRYPOINT ["/usr/local/openresty/nginx/sbin/nginx", "-g", "daemon off;"]
@sairamkrish
sairamkrish / nginx.conf
Last active November 8, 2019 13:42
Nginx configuration to work with Keycloak as Auth layer
server {
listen 80 default_server;
root /opt/nginx/html;
resolver 127.0.0.11 valid=1s ipv6=off;
access_by_lua '
local opts = {
redirect_uri_path = "/redirect_uri",
accept_none_alg = true,
discovery = "http://host.docker.internal:3333/auth/realms/myrealm/.well-known/openid-configuration",
client_id = "nginx",