Skip to content

Instantly share code, notes, and snippets.

View lavjain's full-sized avatar

Lav Jain lavjain

View GitHub Profile
@lavjain
lavjain / cloudshell.md
Created November 15, 2024 02:23
Cloud Shell commands

Cloud Shell External IP Address

export CLOUD_SHELL_IP=$(curl ifconfig.me)
echo Cloud Shell IP: $CLOUD_SHELL_IP
@lavjain
lavjain / Dockerfile
Created October 10, 2024 02:34
Running postgreSQL using Docker 101
FROM ubuntu
RUN apt update -y && apt install -y postgresql-client
ENV PGUSER=postgres
ENV PGPASSWORD=admin
ENV PGHOST=127.0.0.1
ENV PGPORT=5432
@lavjain
lavjain / git.md
Created October 9, 2024 21:20
Helpful Git Commands

Alias

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status

Store Credentials

@lavjain
lavjain / purge_older_pip_packages.py
Last active October 9, 2024 21:03
Python script to delete older packages from pip cache (while retaining the latest)
import os
import subprocess
import re
from packaging.version import parse
# Get the cache directory
cache_dir = subprocess.run(["pip", "cache", "dir"], capture_output=True, text=True).stdout.strip()
# Get the list of cached files
cached_files = subprocess.run(["pip", "cache", "list"], capture_output=True, text=True).stdout.strip().splitlines()
@lavjain
lavjain / gist:79473f25f162feb8f775cef4834223cb
Created June 1, 2024 02:21
Print AutoML Model Evaluation Metrics (Protobuf to Dict)
import json
from google.cloud import aiplatform
def extract_metrics_dict(metrics_value):
"""Extract metrics from various protobuf structures into a JSON-serializable dictionary."""
if isinstance(metrics_value, (int, float, str, bool)):
return metrics_value # Base case: simple value
elif hasattr(metrics_value, "value"):
return metrics_value.value # Handle scalar values
elif hasattr(metrics_value, "items"): # Check if it's a MapComposite
source="solutions-template-e2etest/microservices"
target="{{cookiecutter.project_id}}/microservices1"
echo $source $target
cd $source
pwd
find . -type d -print | (
cd - > /dev/null
pushd $target > /dev/null
pwd
while read dirnamewithpath; do
docker login -u oauth2accesstoken -p "$(gcloud auth print-access-token)" https://gcr.io
docker pull gcr.io/<project>/<image>
# Copy credentials file to your home directory
docker run -it --entrypoint /bin/bash -v /home/$USER:/root gcr.io/<project>/<image>
@lavjain
lavjain / gcrgc.sh
Created May 4, 2023 00:28 — forked from ahmetb/gcrgc.sh
Script to clean up Google Container Registry images pushed before a particular date
#!/bin/bash
# Copyright © 2017 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
Actions (Verb)
--------------
d delete
c change
> indent
v visual mode
y yank
. repeat
Motions (Noun)