Skip to content

Instantly share code, notes, and snippets.

View GeroZayas's full-sized avatar
🔵
Learning the Norse God

Gero Zayas GeroZayas

🔵
Learning the Norse God
View GitHub Profile
# Stupid simple idea but very useful
# if some condition is met, then we return new value, or charged old value
# Else, we return the (unchanged) original value
def change_if_new(new_thing, old_thing):
if new_thing:
return new_thing
# else
return old_thing
@GeroZayas
GeroZayas / print_all_methods_by_type.py
Last active August 19, 2025 06:32
Function to print all the methods of a module by type in json format
import json
def get_methods_by_type(module):
all_elements = [ele for ele in dir(module)]
ele_dict = {
"public":[],
"private":[],
"dunder":[],
}
for ele in all_elements:
from urllib.parse import urlparse
from urllib.robotparser import RobotFileParser
# Look at this cool function to respect robots.txt
USER_AGENT = (
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36"
)
from fastapi.templating import Jinja2Templates
templates = Jinja2Templates(directory="templates")
@app.get("/items/{id}", response_class=HTMLResponse)
async def read_item(request: Request, id: str):
return templates.TemplateResponse(
request=request, name="item.html", context={"id": id}
@GeroZayas
GeroZayas / bug_buster.py
Created December 27, 2025 11:51
Bug Buster Script - Runs Black, Bandit and Flake8 on all Python files of the given dir
import os
import subprocess
from rich import print
print(
"""
==== 🏆 WELCOME TO BUG BUSTER ====
🧑‍💻 Necessary modules to be installed: `black`, `bandit` and `flake8`
@GeroZayas
GeroZayas / generate_image_gemini_3.py
Created December 28, 2025 09:40
Generate Image with Gemini 3 model
from google import genai
client = genai.Client(api_key=GEMINI_API_KEY)
def generate_image(prompt: str) -> None:
response = client.models.generate_content(
model="gemini-3-pro-image-preview",
contents=prompt,
config=genai.types.GenerateContentConfig(
response_modalities=["IMAGE"],
@GeroZayas
GeroZayas / raylib-zig-compile.sh
Created January 2, 2026 09:00
Compile RAYLIB App with Zig (C99)
zig cc -std=c99 main.c \
-lraylib -lGL -lm -lpthread -ldl -lrt -lX11 \
-o app
@GeroZayas
GeroZayas / activate_env_shortcut.sh
Created January 3, 2026 11:33
ACT Alias to activate virtual env easily (Python)
# Activates a Python virtual environment by searching for common directory names.
function act {
for venv_dir in .venv venv env .env; do
if [ -f "$venv_dir/bin/activate" ]; then
. "$venv_dir/bin/activate"
echo "Virtual environment activated: '$venv_dir'"
return 0
fi
done
@GeroZayas
GeroZayas / fetch_and_pull_all_git_branches.sh
Created January 6, 2026 08:31
Fetch and Pull All Git Branches
# https://stackoverflow.com/questions/10312521/how-do-i-fetch-all-git-branches
git branch -r \
| grep -v '\->' \
| sed "s,\x1B\[[0-9;]*[a-zA-Z],,g" \
| while read remote; do \
git branch --track "${remote#origin/}" "$remote"; \
done
git fetch --all
git pull --all
@GeroZayas
GeroZayas / bigquery_client_from_service_account_file.py
Created February 24, 2026 12:50
Create a BigQuery client with a service account key file
from google.cloud import bigquery
from google.oauth2 import service_account
# TODO(developer): Set key_path to the path to the service account key
# file.
# key_path = "path/to/service_account.json"
credentials = service_account.Credentials.from_service_account_file(
key_path,
scopes=["https://www.googleapis.com/auth/cloud-platform"],