Skip to content

Instantly share code, notes, and snippets.

Avatar

Santosh Kumar santosh

View GitHub Profile
@santosh
santosh / main.go
Last active Jun 17, 2021
progressively learning goroutines
View main.go
package main
import (
"fmt"
"math/rand"
"time"
)
func boring(msg string, c chan string) {
for i := 0; ; i++ {
@santosh
santosh / index1.html
Created Apr 16, 2021
CSS Grid for beginners.
View index1.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Grid</title>
<style>
.container {
display: grid;
View README.md

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 Oct 15, 2020
Before pushing a site into production, double check these points.
View website_optimization.md

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 Sep 19, 2020
Useful find command.
View find_command.md

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 Sep 11, 2020
Some fiddling with AWS Go's SDK. Experiments done with S3.
View copy-from-bucket-to-bucket.go
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 Sep 10, 2020
Plotting in Go with gonum/plot.
View data.txt
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 Sep 5, 2020
Webpage OAuth flow example with GitHub.
View github.go
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
const clientID = "<your client id here>"
@santosh
santosh / worker_pool.go
Created Aug 18, 2020
Worker pool with buffered channel.
View worker_pool.go
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
// Worker pool is a collection of threads which are waiting
View advance_level_programming.md
  • Add concurrency.
  • Now deal with it.
  • Mutexes, somaphores, context switching
  • Check for race condition.