Skip to content

Instantly share code, notes, and snippets.

View santosh's full-sized avatar
:octocat:

Santosh Kumar santosh

:octocat:
View GitHub Profile

Authenticate A Golang API With JSON Web Tokens

JSON Web Tokens refresher

The client sends login credentials, the server checks matches the credentials

@santosh
santosh / website_optimization.md
Last active October 15, 2020 15:50
Before pushing a site into production, double check these points.

This is an incomplete list:

  • Make spritesheet of all images.
  • Use CDN for static websites
  • Use Audit tools (Chrome)
  • Google PageSpeed
    • Minify the CSS and JavaScript you are using
    • Reduce the HTTP request
    • Optimize the images as much possible
@santosh
santosh / find_command.md
Last active September 19, 2020 03:22
Useful find command.

Note this command.

find . -not -path '*/\.*' -iname '*' -maxdepth 1 -mtime -1

Let's cut it open and see what's happening.

  1. find .: This says find in the current directory (. is cwd).
  2. -not -path '*/\.*': This says not to match dot (hidden) files.
  3. -iname '*': This says match * (any name). The i in iname is for case-insensitive.
  4. -mtime -1: This says only match files which are modified less than 1 day(s) ago. If - is turned to +, it will say only match files which are not modified after one day which is same as matching every file which are modified after one day.
@santosh
santosh / copy-from-bucket-to-bucket.go
Last active September 11, 2020 07:43
Some fiddling with AWS Go's SDK. Experiments done with S3.
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
@santosh
santosh / data.txt
Last active September 10, 2020 18:05
Plotting in Go with gonum/plot.
6.1101,17.592
5.5277,9.1302
8.5186,13.662
7.0032,11.854
5.8598,6.8233
8.3829,11.886
7.4764,4.3483
8.5781,12
6.4862,6.5987
5.0546,3.8166
@santosh
santosh / github.go
Last active September 5, 2020 05:13
Webpage OAuth flow example with GitHub.
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
const clientID = "<your client id here>"
@santosh
santosh / worker_pool.go
Created August 18, 2020 04:47
Worker pool with buffered channel.
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
// Worker pool is a collection of threads which are waiting
  • Add concurrency.
  • Now deal with it.
  • Mutexes, somaphores, context switching
  • Check for race condition.
@santosh
santosh / interface.go
Last active July 7, 2020 19:33
Getting started with interfaces.
package main
import "fmt"
type SalaryCalculator interface {
CalculateSalary() int
}
type Permanent struct {
empId int
@santosh
santosh / flaskCookie.py
Created November 2, 2017 07:32
Set cookies in flask. #Flask #Python
from flask import Flask, request, make_response, redirect
app = Flask(__name__)
@app.route('/')
def index():
response = make_response('<h1>This document carries a cookie!</h1>')
response.set_cookie('answer', '42')
return response
if __name__ == '__main__':