Skip to content

Instantly share code, notes, and snippets.

var arr = [{"name":"John","age":10},
{"name":"Ron","age":11},
{"name":"Robin","age":12},
{"name":"Sean","age":45},
{"name":"Sarah","age":40}
];
function sort(array){
array.sort(function(a, b){
return a.age - b.age;
});
@Harsimran1
Harsimran1 / token.go
Last active February 9, 2022 01:14
JWT Email Token
package email
import (
"crypto/rsa"
"time"
jwt "github.com/dgrijalva/jwt-go"
"github.com/pkg/errors"
)
@Harsimran1
Harsimran1 / main.go
Last active February 4, 2024 03:45
Gracefully shutdown go api server connected to database
package main
import (
"context"
"database/sql"
"fmt"
"os/signal"
"syscall"
"time"
@Harsimran1
Harsimran1 / main.go
Created February 17, 2019 14:40
Minimal http server connected with database
package main
import (
"database/sql"
"fmt"
"log"
"net/http"
// pq is postgres driver for database/sql
_ "github.com/lib/pq"
@Harsimran1
Harsimran1 / 1.Dockerfile
Last active June 10, 2019 22:10
Dockerfiles
# Accept the Go version for the image to be set as a build argument.
# Default to Go 1.12
ARG GO_VERSION=1.12
FROM golang:${GO_VERSION}
# Set the environment variables for the commands passed to the stage when using
# `docker build --target code`. Leave CGO available for the race detector.
# Set the working directory outside $GOPATH to enable the support for modules.
@Harsimran1
Harsimran1 / deployment.yaml
Created December 12, 2019 21:50
k8s deployment.yaml with unprivileged nginx user
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
@Harsimran1
Harsimran1 / deployment.yaml
Created December 15, 2019 11:18
Deploymeny yaml with external volume mounts for nginx.confg
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
data:
nginx.conf: |
worker_processes 3;
pid /tmp/nginx.pid; # Changed from /var/run/nginx.pid
error_log /var/log/nginx/error.log;
@Harsimran1
Harsimran1 / nginx.conf
Last active November 5, 2020 12:04
Nginx conf with ssl termination.
server {
listen 80;
server_name _;
# Redirect all traffic to SSL
return 301 https://$host$request_uri;
}
server {