Skip to content

Instantly share code, notes, and snippets.

from string.templatelib import Template
def render_plain(template: Template) -> str:
parts = []
# interleave strings and interpolation values
for literal, value in zip(template.strings, template.values + ("",)):
parts.append(literal)
parts.append(str(value))
return "".join(parts)
@everythingpython
everythingpython / t-strings-1.py
Created August 30, 2025 16:38
Using t-strings - Example 1
a = "Abhiram"
c = t"Hello {a}"
print(c)
# Template(strings=('Hello ', ''), interpolations=(Interpolation('Abhiram', 'a', None, ''),))
@everythingpython
everythingpython / install_python3.14.md
Created August 30, 2025 16:34
Install python3.14 in WSL/Linux
@everythingpython
everythingpython / ExplainXSquared.py
Created April 7, 2025 18:08
Explain X Squared - 3B1B style Manim program
from manim import *
class ExplainXSquared(Scene):
def construct(self):
# Title
title = Text("Understanding x²", font_size=48)
title.to_edge(UP)
self.play(Write(title))
self.wait(1)
@everythingpython
everythingpython / data_models.py
Created August 26, 2024 20:08
data models for llm_scraper
from pydantic import BaseModel
class AIResponse(BaseModel):
name: str
url: str
topic: str
class AIResponseList(BaseModel):
responses: list[AIResponse]
@everythingpython
everythingpython / strings.py
Created August 26, 2024 20:07
For hn_scraper
def get_sys_prompt(content_full):
prompt = f"Please go through the content and for each title \
return the topic of the content. If it's about Python, return Python. \
If it's about GenAI, return GenAI. Else return irrelevant:\n\n{content_full}"
return prompt
hacker_news_latest_url = "https://hacker-news.firebaseio.com/v0/newstories.json?print=pretty"
def hacker_news_get_article_url(i):
@everythingpython
everythingpython / keys.py
Created August 26, 2024 20:07
keys for hn_scraper
anthropic = "<add-anthropic-secret-key-here"
openai_key = "<add-openai-key-here>"
@everythingpython
everythingpython / hn_scraper_llm_topics.py
Created August 26, 2024 20:01
Scraping HN articles of interest and then using LLM to get their topics
import json
import os
import urllib.request
from data_models import AIResponseList
import requests
from anthropic import Anthropic
from openai import OpenAI
from strings import *
from keys import *