This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import subprocess | |
| from rich import print | |
| print( | |
| """ | |
| ==== 🏆 WELCOME TO BUG BUSTER ==== | |
| 🧑💻 Necessary modules to be installed: `black`, `bandit` and `flake8` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| zig cc -std=c99 main.c \ | |
| -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 \ | |
| -o app |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"], |
OlderNewer