Skip to content

Instantly share code, notes, and snippets.

View grafuls's full-sized avatar
🐍
Hissing

Gonzalo Rafuls grafuls

🐍
Hissing
  • Red Hat, Inc
  • Czech Republic
View GitHub Profile
@grafuls
grafuls / hostname2meta.py
Created April 9, 2025 14:01
Quads hostname2meta converter
#! /usr/bin/env python3
import re
from quads.quads_api import QuadsApi
from quads.config import Config
quads = QuadsApi(Config)
hosts = quads.get_hosts()
pattern = r"^(?P<rack>[^-]+)-(?P<uloc>[^-]+)-(?P<blade>[^-]+)-(?P<host_type>[^.]+)\.(?P<domain>.+)$"
@grafuls
grafuls / hue_master_switch.ino
Created December 6, 2024 08:12
Controlling HUE lights via D1 mini
#define POTENTIOMETER_PIN A0
#define CHANGE_THRESHOLD 2
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ArduinoJson.h>
#include <ESP8266HTTPClient.h>
// Replace with your network credentials
const char* ssid = "{SSID}";
@grafuls
grafuls / brave.sh
Last active November 11, 2024 11:01
Finds and brings to front a google meet tab on brave browser
/usr/bin/brave-browser-stable %U --remote-debugging-port=9222 --remote-allow-origins=http://localhost:9222
@grafuls
grafuls / meat.py
Created October 18, 2024 15:49
Find a firefox window, scroll tabs till it finds a google meet one, press ctrl+d to unmute.
#! /usr/bin/env python
import subprocess
from subprocess import CalledProcessError
import time
def get_active_window_title():
try:
window_title = subprocess.check_output("xdotool getactivewindow getwindowname", shell=True).decode('utf-8').strip()
return window_title
- model: Dell R630
quantity: 45
specs:
- 2x Intel Xeon E5-2683 v3 (28 total cores, 56 threads)
- 128GB
- 2x 1TB Disk
- model: Dell R640
quantity: 334
specs:
@grafuls
grafuls / commander.py
Created May 3, 2024 13:30
Command Design Pattern
from functools import partial
class CommandException(Exception):
def __init__(self, message):
self.message = message
class Command:
"""
@grafuls
grafuls / main.py
Created March 4, 2024 15:44
Semantic search on MongoDB
#! /usr/bin/env python
from llama_index.core import SummaryIndex
from llama_index.readers.mongodb import SimpleMongoReader
from langchain_community.llms import HuggingFaceEndpoint
import os
os.environ["HUGGINGFACEHUB_API_TOKEN"] = {HUGGINGFACE_API_TOKEN}
@grafuls
grafuls / main.py
Last active February 16, 2024 15:35
Gitlab to Jira webhook translator
#! /usr/bin/env python
from flask import Flask, request
import requests
import json
import os
JIRA_WEBHOOK_ID = os.getenv("JIRA_WEBHOOK_ID")
JIRA_WEBHOOK = f"https://issues.redhat.com/rest/cb-automation/latest/hooks/{JIRA_WEBHOOK_ID}"
@grafuls
grafuls / quads-setup.py
Created January 30, 2024 15:02
Quads setup script which iterates through the key value pairs on the quads.yml configuration file and provides the defined values as defaults for the inputs
#! /bin/env python
import yaml
def prompt_user(config):
for key in config.keys():
if isinstance(config[key], dict):
config[key] = prompt_user(config[key])
else:
# Convert the key into a human-friendly format
prompt = ' '.join(word.capitalize() for word in key.split('_'))
@grafuls
grafuls / grafer.py
Created December 22, 2023 16:23
Python generated grafana dashboards
from grafanalib.core import (
Dashboard, Graph,
OPS_FORMAT, Row,
single_y_axis, Target
)
dashboard = Dashboard(
title="Python generated dashboard",
rows=[