Skip to content

Instantly share code, notes, and snippets.

View crazyoptimist's full-sized avatar
🐌
crawling

crazyoptimist crazyoptimist

🐌
crawling
View GitHub Profile
@crazyoptimist
crazyoptimist / prompt.sh
Created March 14, 2024 07:39
Minimal Bash Prompt
# new line + workdir + $
export PS1="\n\w $ "
export PROMPT_DIRTRIM=2
@crazyoptimist
crazyoptimist / minimum-reorient.go
Created February 28, 2024 08:11
There is a network with N roads and N + 1 cities. The cities are labeled with distinct integers within the range [O..N]. Roads connect the cities in such a way that there is exactly one way to travel between any two of the cities. In other words, the network forms a tree.
package main
import (
"strconv"
)
func solution(A []int, B []int) int {
n := len(A)
graph := make([][]int, n+1)
// track visited nodes when traversing the graph
@crazyoptimist
crazyoptimist / semaphore.go
Last active February 4, 2024 03:46
Semaphore Concurrency Pattern with Buffered Channel in Go
package main
import (
"fmt"
"time"
)
const (
NUM_WORKERS = 100
NUM_JOBS = 1000
@crazyoptimist
crazyoptimist / workerpool.go
Last active February 3, 2024 04:05
Worker Pool Concurrency Pattern in Go
package main
import (
"fmt"
"sync"
)
const (
NUM_WORKERS = 10
NUM_JOBS = 10000
@crazyoptimist
crazyoptimist / compose.yaml
Last active April 10, 2024 00:56
Kafka Cluster Setup with Provectus KafkaUI for Local Development Environment
name: kafka_cluster
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.5.3
container_name: zookeeper
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
@crazyoptimist
crazyoptimist / deploy_spa.yml
Created June 7, 2023 10:54
Deploy SPA into AWS Cloudfront & S3
name: Deploy SPA
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
@crazyoptimist
crazyoptimist / build_spa.yml
Created June 7, 2023 10:52
Build SPA in GHA
name: Build SPA
on:
pull_request:
types: [opened, edited, synchronize, reopened, closed]
branches:
- main
jobs:
build:
@crazyoptimist
crazyoptimist / monitor-memory-usage.ts
Created June 6, 2023 07:43
Monitor Memory Usage in NodeJS
function formatMemoryUsage(data: number) {
return `${Math.round((data / 1024 / 1024) * 100) / 100} MB`;
}
function getCurrentMemoryUsage(): Object {
const memoryData = process.memoryUsage();
return {
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`,
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
@crazyoptimist
crazyoptimist / verify-cognito-jwt.ts
Last active August 11, 2023 16:43
Verify Cognito JWT tokens
import {
CognitoJwtVerifier,
CognitoJwtVerifierSingleUserPool,
} from 'aws-jwt-verify/cognito-verifier';
const verifier: CognitoJwtVerifierSingleUserPool<{
userPoolId: string;
tokenUse: 'access' | 'id';
clientId: string;
}> = CognitoJwtVerifier.create({
@crazyoptimist
crazyoptimist / rbenv-install.sh
Last active January 4, 2023 18:11
Install rbenv on Ubuntu/Debian
# Install build dependencies for ruby(https://github.com/rbenv/ruby-build/wiki#suggested-build-environment)
sudo apt-get install -y autoconf bison patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev
# Install rbenv using git
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'eval "$(~/.rbenv/bin/rbenv init - bash)"' >> ~/.bashrc
source ~/.bashrc
# Install ruby-build plugin for rbenv
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
# List available ruby versions
rbenv install --list