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
| # pip install fastapi uvicorn | |
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| app = FastAPI() | |
| class Item(BaseModel): | |
| name: str | |
| price: float | |
| in_stock: bool = True |
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
| # RAG Pipeline - Complete Working Example | |
| # Install: pip install langchain langchain-openai langchain-community chromadb pypdf | |
| import os | |
| from langchain_community.document_loaders import PyPDFLoader, TextLoader, WebBaseLoader | |
| from langchain.text_splitter import RecursiveCharacterTextSplitter | |
| from langchain_openai import OpenAIEmbeddings, ChatOpenAI | |
| from langchain_community.vectorstores import Chroma | |
| from langchain.chains import RetrievalQA | |
| from langchain.prompts import PromptTemplate |
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
| # Enhanced AI Prompt Generator | |
| You are an AI-powered prompt generator, designed to improve and expand basic prompts into comprehensive, context-rich instructions. Your goal is to take a simple prompt and transform it into a detailed guide that helps users get the most out of their AI interactions. | |
| ## Your process: | |
| 1. **Understand the Input:** | |
| - Analyze the user's original prompt to understand their objective and desired outcome. | |
| - If the prompt is vague or ambiguous, infer the most useful interpretation AND note what clarifying questions you would ask. | |
| - Consider: context, target audience, specific goals, constraints, and preferred depth level. |
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 langchain_openai import ChatOpenAI | |
| from langchain.prompts import PromptTemplate | |
| from langchain.agents import initialize_agent, AgentType | |
| from langchain.tools import Tool | |
| import requests | |
| # 1. Prompt Template | |
| prompt = PromptTemplate( | |
| input_variables=["topic"], | |
| template="Explain {topic} in 3 sentences for a developer audience." |
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 { useCurrentFrame, interpolate, AbsoluteFill } from 'remotion'; | |
| import { spring, useVideoConfig } from 'remotion'; | |
| // A simple fade-in text animation | |
| export const MyVideo: React.FC = () => { | |
| const frame = useCurrentFrame(); | |
| const { fps } = useVideoConfig(); | |
| // Fade in over 30 frames | |
| const opacity = interpolate(frame, [0, 30], [0, 1], { |
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
| # Telegram AI Assistant with GPT-4o | |
| # Install: pip install python-telegram-bot openai | |
| # Setup: Create bot via @BotFather on Telegram, get OpenAI API key | |
| import os | |
| from telegram import Update | |
| from telegram.ext import ( | |
| Application, | |
| CommandHandler, | |
| MessageHandler, |
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
| # pip install requests beautifulsoup4 | |
| import requests | |
| import csv | |
| from bs4 import BeautifulSoup | |
| # Scrape Hacker News front page | |
| url = 'https://news.ycombinator.com' | |
| html = requests.get(url).text | |
| soup = BeautifulSoup(html, 'html.parser') | |
| titles = soup.select('.titleline > a') |
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
| # Add a Claude Code plugin | |
| # Method 1: From GitHub | |
| claude plugin add github.com/user/plugin | |
| # Method 2: From registry | |
| claude plugin search "code review" | |
| claude plugin install best-reviewer | |
| # Method 3: Local development |
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 collections import Counter | |
| # 1. Flatten a nested list | |
| nested = [[1, 2], [3, 4], [5, 6]] | |
| flat = [x for sub in nested for x in sub] | |
| print(flat) # [1, 2, 3, 4, 5, 6] | |
| # 2. Swap two variables | |
| a, b = 10, 20 | |
| a, b = b, a |