Skip to content

Instantly share code, notes, and snippets.

import argparse
import google.generativeaimport argparse
import google.generativeai as genai
import os
from PIL import Image
import pyheif
def load_image(image_path):
"""
Loads an image from a file, discerning the format by its extension.
@jon2allen
jon2allen / dedupe_analzyer_sentence.py
Created August 22, 2025 02:42
dededupe_sentence_analyzer.
#!/usr/bin/env python3
import argparse
import glob
from collections import defaultdict
import os
def analyze_files(file_glob, limit):
"""
Analyzes a collection of text files to find duplicate sentences and calculate
potential deduplication savings.
@jon2allen
jon2allen / chinese_food_parser1.py
Last active August 18, 2025 00:42
spaCy rules base chinese food text parser
import argparse
import spacy
from spacy.language import Language
def create_ner_model():
"""Create and return a spaCy model with rule-based NER for Chinese food entities."""
# Define entity lists
fruits = [
'苹果', '香蕉', '橘子', '橙子', '葡萄', '草莓', '芒果', '西瓜',
'菠萝', '梨', '桃子', '柠檬', '樱桃', '猕猴桃', '石榴', '椰子',
@jon2allen
jon2allen / compare2.py
Last active August 1, 2025 18:01
python logging with AI
import argparse
import sys
def compare_scripts(original_file: str, modified_file: str):
"""
Compares two Python scripts to ensure every line from the original
exists in the modified version.
The comparison ignores empty lines and leading/trailing whitespace
to focus on the core code content.
@jon2allen
jon2allen / conv_gemini_try7.py
Created July 28, 2025 22:26
python conversion with AI styling hints.
#!/usr/bin/env python
import argparse
import markdown
import os
import re
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.prompts import ChatPromptTemplate
from langchain.schema.output_parser import StrOutputParser
# --- Style Generation and Validation (Updated with LangChain) ---
@jon2allen
jon2allen / conv_gemini_try1.py
Created July 27, 2025 21:18
Recipe from Markdown to HMTL converter. Pyhton
#!/usr/bin/env python
import argparse
import markdown
import os
def create_html_from_markdown(input_files, output_file):
"""
Converts a list of markdown recipe files into a single HTML file.
Args:
@jon2allen
jon2allen / cli_app.py
Created July 26, 2025 19:11
todo_app - 2nd refactor
# cli_app.py
import argparse
from datetime import datetime
# Import the concrete FlatFileStore, as CLI app is responsible for choosing the implementation
from flat_file_store import FlatFileStore
from todo_manager import TodoManager
def main():
"""
Main function to parse arguments and execute Todo DSL commands.
@jon2allen
jon2allen / cli_app.py
Created July 26, 2025 18:47
todo_app - part2
# cli_app.py
import argparse
from datetime import datetime
from flat_file_store import FlatFileStore
from todo_manager import TodoManager
def main():
"""
Main function to parse arguments and execute Todo DSL commands.
"""
@jon2allen
jon2allen / flat_file_store.py
Created July 19, 2025 22:09
todo_manager.py - from gemini article on medium.
# flat_file_store.py
import json
import os
class FlatFileStore:
"""
A simple flat-file storage class for Todo items.
It reads and writes todo data to a JSON file.
"""
@jon2allen
jon2allen / gist:c5f6c94b79a6989793063c17ecc8be08
Created July 15, 2025 02:29
gemini podcast app - with load and save feature.
import React, { useState, useEffect, useRef } from 'react';
// Main App component for Jon's Podcast Creator
const App = () => {
// State for the podcast topic input by the user
const [topic, setTopic] = useState('');
// State for the generated podcast transcript
const [transcript, setTranscript] = useState('');
// State to manage loading status during AI generation
const [isLoading, setIsLoading] = useState(false);