Skip to content

Instantly share code, notes, and snippets.

@martingaido
martingaido / ollama-rag.py
Created December 23, 2023 20:58
RAG Ollama
from langchain.llms import Ollama
from langchain.document_loaders import WebBaseLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.embeddings import GPT4AllEmbeddings
from langchain.vectorstores import Chroma
from langchain.chains import RetrievalQA
import gradio as gr
# Initialize variables to store the previous URL and its corresponding data and embeddings
prev_url = None
@martingaido
martingaido / shellCodeValidator.sh
Last active July 20, 2023 23:48
Code Validation for Terminal (bash) using ChatGPT-4
#!/bin/bash
# Replace YOUR_API_KEY with your actual API key
API_KEY="OPEN_AI_API_KEY"
# Clear the screen
clear
# Function to check if the API key is set
check_api_key() {
@martingaido
martingaido / sitemap.py
Created May 25, 2023 20:16
Python script to create sitemap.xml
import requests
from bs4 import BeautifulSoup
from urllib.parse import urlparse, urljoin
def create_sitemap(url):
# Parse the base URL
parsed_url = urlparse(url)
base_url = parsed_url.scheme + "://" + parsed_url.netloc
# Initialize the set of visited URLs
@martingaido
martingaido / xmenu.sh
Created March 6, 2023 23:28
Menu Interactivo en BASH
#!/bin/bash
# Define las opciones del menú
options=("Opción 1" "Opción 2" "Opción 3" "Salir")
# Establece la posición inicial del cursor en la primera opción
selected=0
# Función para mostrar el menú y resaltar la opción seleccionada
function show_menu() {
@martingaido
martingaido / termGPT.sh
Created March 6, 2023 23:14
TerminalGPT
#!/bin/bash
# Replace YOUR_API_KEY with your actual API key
API_KEY="OPEN_AI_API_KEY"
# Get the message from the command line argument
MESSAGE=$1
# Set up the API endpoint
API_ENDPOINT="https://api.openai.com/v1/chat/completions"
/*
Hamming distance is a measure of the difference between
two same-length strings of characters. Simply put, it is
defined as the number of positions at which corresponding
characters in two strings of characters are different.
Formally, the Hamming distance between two same-length
strings of characters, s and t, is defined as the number
of positions at which the corresponding characters are
@martingaido
martingaido / biorhythm.py
Created December 3, 2022 20:19
Script to calculate your biorhythm
from datetime import datetime, timedelta
import math
def calculate_biorhythm(birthday, current_date, rhythm_type):
days_difference = (current_date - birthday).days
if rhythm_type == 'physical':
cycle = 23
elif rhythm_type == 'emotional':
@martingaido
martingaido / lambdaTweetScraper.py
Last active November 30, 2022 21:33
AWS Lambda Function to Scrape Tweets
import json
import snscrape
import snscrape.modules.twitter as sntwitter
import snscrape.modules.facebook as snfacebbok
import snscrape.modules.instagram as sninstagram
import snscrape.modules.mastodon as snmastodon
import snscrape.modules.reddit as smreddit
def lambda_handler(event, context):
@martingaido
martingaido / Iris.csv
Last active November 9, 2022 10:42
Deep Learning with Keras on Iris Dataset
Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm Species
1 5.1 3.5 1.4 0.2 Iris-setosa
2 4.9 3.0 1.4 0.2 Iris-setosa
3 4.7 3.2 1.3 0.2 Iris-setosa
4 4.6 3.1 1.5 0.2 Iris-setosa
5 5.0 3.6 1.4 0.2 Iris-setosa
6 5.4 3.9 1.7 0.4 Iris-setosa
7 4.6 3.4 1.4 0.3 Iris-setosa
8 5.0 3.4 1.5 0.2 Iris-setosa
9 4.4 2.9 1.4 0.2 Iris-setosa
@martingaido
martingaido / text-generator-transformers.py
Created November 9, 2022 00:01
Generating Human-level Text with Contrastive Search in Transformers
# pip install torch
# pip install "transformers==4.24.0"
# usage: python text-generator-transformers.py 'some text'
import sys
import torch
from transformers import GPT2Tokenizer, GPT2LMHeadModel
arg = sys.argv