Skip to content

Instantly share code, notes, and snippets.

View gsrai's full-sized avatar

Gagan Srai gsrai

View GitHub Profile
@gsrai
gsrai / README.md
Created May 20, 2024 20:36
Web Dev in Go 1.22

Web Dev in Go 1.22

Go 1.22 now ships with an HTTP server multiplexer, so there is no longer a need to include routing libraries like httprouter or chi.

Basic use of http.ServeMux

package main
@gsrai
gsrai / foo.md
Created February 20, 2023 16:25
C vs C++ vs Rust (and Clojure, Python & Go)

C vs C++ vs Rust (and Clojure, Python & Go)

source

Original

int calculate(int bottom, int top)
{
    if (top > bottom)
@gsrai
gsrai / map.go
Last active January 17, 2023 14:49
get the keys of any map in go
package utils
func GetKeys[K comparable, V any](m map[K]V) []K {
keys := make([]K, 0, len(m))
for k := range m {
keys = append(keys, k)
}
return keys
}
@gsrai
gsrai / .vimrc
Created November 6, 2022 12:09
Basic .vimrc
set termguicolors
" Set compatibility to Vim only.
" be vim no vi.
set nocompatible
" Disable the default Vim startup message.
set shortmess+=I
" Helps force plug-ins to load correctly when it is turned back on below.
@gsrai
gsrai / install_go.sh
Last active April 16, 2024 13:22
Install Go on M1/M2/M3 mac (apple silicon)
#!/usr/bin/env bash
# find filename on https://go.dev/dl/
GO_FILE_NAME="go1.19.3.darwin-arm64.tar.gz"
# usage:
# chmod u+x install_go.sh
# sudo ./install_go.sh
mkdir /tmp/downloads
@gsrai
gsrai / install_python.md
Created September 17, 2022 14:12
python install on mac

Install Python on Mac

  1. brew install pyenv
  2. Add this to your ~/.zshrc:
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/shims:$PATH"
@gsrai
gsrai / Notes.md
Created July 26, 2022 12:48
AWS Cognito User Pool vs Identity Pool

Cognito

Securing something is about restricting access or access control. To control access, you need to differentiate those who have access and those who don't. This inherently requires you to be able to identify the user (authentication). To identify users, you need an identity provider, a service that stores and provides user information aka identity. Once you can identify users, you need to associate a user/s to a permissions list or ruleset.

The Cognito User Pool is an identity provider, and the Cognito Identity Pool federates identities from multiple identity providers and then applys a ruleset via IAM roles.

@gsrai
gsrai / Notes.md
Created July 26, 2022 12:31
AWS IAM and ARN

Identity and Access Management and Amazon Resource Names

An AWS account has resources and users. It also has an account-id.

By default a root user is created, and this user has complete and unrestricted access to all resources in your AWS account.

AWS IAM is used to manage users (identity) and resource access (access management) on an AWS account.

All AWS resources have a unique identifier known as an ARN.

@gsrai
gsrai / index.html
Created June 1, 2022 19:44
How to center a div
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>center a div</title>
<style>
.container {
height: 100vh;
display: flex;
@gsrai
gsrai / main.go
Created May 30, 2022 20:47
Reverse a Linked List
package main
import "fmt"
type Node[T any] struct {
Next *Node[T]
Value T
}
type LinkedList[T any] struct {