Skip to content

Instantly share code, notes, and snippets.

View Cdaprod's full-sized avatar
🏠
Learn something new everyday!

David Cdaprod

🏠
Learn something new everyday!
View GitHub Profile
@Cdaprod
Cdaprod / UPDATE_OBJECTS_IN_WEAVIATE.py
Created March 11, 2024 15:30
Example of how you might update objects in Weaviate with tokenized data (note: this is a conceptual example and assumes you have a function tokenize_text and a Weaviate client client set up)
from transformers import BertTokenizer
# Assuming you have a tokenizer function
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
# Iterate over objects in Weaviate (pseudo-code)
for object in weaviate_objects:
# Tokenize the text of the object
tokenized = tokenizer(object['text'], padding=True, truncation=True, return_tensors="pt")

Batch Subscribing to Slack GitHub Intergration Over Webhook

Prerequisites

  • Slack Workspace: You need access to a Slack workspace where you can add apps.
  • Python Environment: Ensure you have Python installed on your machine. This guide assumes you are using Python 3.x.
  • iOS Device: An iPhone or iPad with the Shortcuts app and Working Copy app installed.

Step 1: Create a Slack App and Incoming Webhook

  1. Create a Slack App:
@Cdaprod
Cdaprod / wled_esp_flasher.sh
Created March 6, 2024 21:55
Bash script that automates setting up a Python environment, optionally downloads WLED, and flashes firmware to multiple ESP32 devices.
#!/bin/bash
# WLEDFlasher - Effortless WLED Firmware Flashing Tool
cat << EOF
____ ____ _ ____ ____ ___ ____
/ ___| _ \ / \ | _ \| _ \ / _ \| _ \
| | | | | |/ _ \ | |_) | |_) | | | | | | |
| |___| |_| / ___ \| __/| _ <| |_| | |_| |
\____|____/_/ \_\_| |_| \_\\___/|____/
@Cdaprod
Cdaprod / PseudoLanggraphStateMachine.md
Created March 6, 2024 03:34
This pseudocode outlines the creation of a state machine similar to LangGraph using Pydantic for data validation. The Node class represents tasks or agents with their specific functions. The StateGraph manages nodes and transitions based on conditions. This abstract implementation can be extended with more sophisticated logic for conditions, nod…

To create an abstracted LangGraph-like state machine using Pydantic, we will design a system that allows for the creation of nodes (agents) and edges (transitions) in a graph that represents a workflow. The agents will have specific roles or functions, and the transitions between these agents will be dictated by the outcomes of their actions. Pydantic will be used for data validation and settings management, ensuring that the components of our state machine are well-defined and interact correctly.

Step 1: Define the Base Models with Pydantic

First, we need to define our base models for Nodes (Agents) and Edges (Transitions). Pydantic models will ensure that each component of our graph adheres to a specific structure and type, facilitating error handling and data consistency.

Step 2: Implement the Graph Structure

We will create a class for the graph itself, which holds the nodes and edges and manages the workflow's execution. This includes methods for adding nodes, adding edges, and determining the

@Cdaprod
Cdaprod / DynamicETLGraphAlgorithm.md
Last active March 6, 2024 03:35
This approach allows you to build flexible and dynamic ETL pipelines where the flow can adapt based on the data it processes. Each node in the pipeline can perform specific ETL tasks, and the decision on where the data flows next can be made dynamically, enabling complex data processing scenarios tailored to the needs of each dataset.

To create dynamic ETL (Extract, Transform, Load) pipes with dynamic edges and nodes using Pydantic for data validation, we will expand upon the previously discussed abstracted LangGraph-like state machine. This ETL pipeline will dynamically adjust its flow based on the data passed through each node, allowing for flexible data processing scenarios.

Step 1: Define the Data Model and Node Functionality

First, define Pydantic models for the data that will flow through the ETL pipeline. These models ensure that each stage of the ETL process receives and produces data in the expected format.

from pydantic import BaseModel

class DataModel(BaseModel):
@Cdaprod
Cdaprod / TestURLsWithShortcutsIOS.md
Created February 24, 2024 21:42
This guide and script provide a foundational approach to integrating iOS Shortcuts with web services for security analysis, enhancing your ability to quickly assess the safety of URLs on the fly.

Creating an iOS Shortcuts workflow that integrates with the VirusTotal API to test URLs directly from the Share Sheet involves a series of steps. This workflow will capture URLs shared via the Share Sheet, submit them to the VirusTotal API for safety analysis, and then display the analysis results to you. Below is a guide on setting up this workflow, including the necessary scripts to publish this as a gist or integrate it into your iOS device's Shortcuts app.

Preparing Your Environment:

  1. Obtain a VirusTotal API Key:

    • Sign up for a free account at VirusTotal.
    • Navigate to your profile settings to find your API key.
  2. Ensure You Have the Shortcuts App Installed:

    • The Shortcuts app is available by default on iOS devices. Update it to the latest version for the best experience.
@Cdaprod
Cdaprod / minio_client_pydantic.py
Created February 23, 2024 14:59
MinIO SDK Client and Bucket Validation
from typing import Optional
from pydantic import BaseModel, Field
from minio import Minio
class MinIoConfig(BaseModel):
endpoint: str
access_key: str
secret_key: str
secure: bool = Field(default=True, title="Use SSL?")
bucket: Optional[str] = None
@Cdaprod
Cdaprod / OUTPUT.md
Created February 17, 2024 18:42 — forked from isaacarnault/OUTPUT.md
Data collection using Python

Data collection using Python

See output

isaac-arnault-data-collection-P.png

@Cdaprod
Cdaprod / MinIoAgent.py
Created February 14, 2024 21:15
The MinIoAgent handles user queries by parsing statements and constructing the appropriate sequence of calls to the available tools. Each tool is invoked depending on the specified objective, whether it's listing, uploading, downloading, or removing objects. Intermediate steps are captured and presented in the final response. Users can modify th…
import os
import sys
import io
import tarfile
import uuid
from urllib.parse import urlparse
import requests
from pydantic import BaseModel
from rich.console import Console
@Cdaprod
Cdaprod / pydantic-cleaning.md
Last active February 12, 2024 22:23
Clean text with PYDANTIC! :3

To remove newline characters (\n) or punctuation from strings within your Pydantic models, you can enhance your validators to include these additional checks and transformations. Python's str methods and the string module can be very helpful for such tasks.

Here's an example of how you might adjust a Pydantic model validator to remove newline characters and punctuation from each item in a list attribute:

Extending the Pydantic Model with Custom Validation

from pydantic import BaseModel, validator
from typing import List
import string