Skip to content

Instantly share code, notes, and snippets.

View gsrai's full-sized avatar

Gagan Srai gsrai

View GitHub Profile
@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 / install_go.sh
Last active July 1, 2025 02:05
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 / fastestSolution.ts
Last active February 20, 2022 15:43
valid anagram go vs typescript (go is 16x faster and uses 16x less memory 🤯)
function isAnagram(s: string, t: string): boolean {
if (s.length !== t.length) return false
let counter = new Array(26).fill(0);
for (let i = 0; i < s.length; i++) {
counter[s.charCodeAt(i) - 'a'.charCodeAt(0)]++
counter[t.charCodeAt(i) - 'a'.charCodeAt(0)]--
}
return !counter.some(i => i < 0)
};
@gsrai
gsrai / Results.md
Last active May 28, 2023 13:05
Fibonacci (iterative, recursive, memoized)

JS vs Go vs C fib

Running on MacBook Air (M1, 2020) with 16 GB of RAM.

gcc fib.c -O2

n = 40

result = 102334155

@gsrai
gsrai / better_impl.py
Last active May 20, 2022 13:39
Maximum Nesting Depth of the Parentheses in python, java, clojure, javascript and go
def max_depth(s):
arr = [0]
for char in s:
if char == "(":
arr.append(arr[-1] + 1)
if char == ")":
arr.append(arr[-1] - 1)
return max(arr)
s = "( ((X)) (((Y))) )"
@gsrai
gsrai / python3.md
Created August 28, 2020 16:36
How to setup a python environment

How to setup a python environment

python3 -m venv venv
source venv/bin/activate

pip install ...

pip freeze &gt; requirements.txt

@adamscharf
adamscharf / installing_python.md
Last active March 25, 2025 17:18
Managing Python using pyenv, virtualenv, and pyenv-virtualenv

Managing Python using pyenv, virtualenv, and pyenv-virtualenv

Problem: You want to maintain multiple different versions of python and keep packages separated based on projects that you're working on.

Solution: Use the pyenv, virtualenv tools along with the pyenv-virutalenv plugin to manage multiple versions of python and seamlessly integrate them with your projects' virtual environments.

Installation