| Problem | Pattern |
|---|---|
| Background notification | Fire-and-forget + daemon |
| Delayed action | threading.Timer |
| Long-lived worker | Subclass Thread |
| I/O fan-out | ThreadPoolExecutor |
| Pipelines | Threads + Queue |
| Best-effort work | Daemon threads |
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
| ollama> Hi - my name is Anand. I shall call you Amy. | |
| Hello Anand! It's nice to meet you. I'm Amy, and I'll do my best to assist you with any | |
| questions or tasks you may have. How can I help you today? | |
| ollama> What is my name? | |
| Your name is Anand. Is there anything else I can help you with? | |
| ollama> Identify yourself please | |
| I'd be happy to identify myself. I am Amy, a highly advanced language assistant. I'm a | |
| computer program designed to provide accurate and helpful information on a wide range of | |
| topics, from science and history to entertainment and culture. I'm constantly learning | |
| and improving, so there may be occasions where my responses seem uncertain or unclear. |
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 cmd | |
| import json | |
| import os | |
| from pathlib import Path | |
| from elasticsearch import Elasticsearch | |
| from elasticsearch.helpers import bulk | |
| import warnings | |
| warnings.filterwarnings("ignore") | |
| class QueryHelper: |
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 ollama | |
| import cmd | |
| class OllamaShell(cmd.Cmd): | |
| """ A console to ask questions to any LLM supported by ollama """ | |
| prompt = "ollama> " | |
| # Ollama service needs to be running locally | |
| def __init__(self, model='llama3.2:1b'): | |
| self.model = model |
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 cmd | |
| import shlex | |
| import operator | |
| from functools import reduce | |
| class CalcConsole(cmd.Cmd): | |
| """ A console that helps to perform regular arithmetic """ | |
| prompt = "Calc> " |
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 cmd | |
| import shlex | |
| class AddShell(cmd.Cmd): | |
| """ A simple cmd shell that adds numbers at the prompt """ | |
| prompt = "Add> " | |
| def default(self, arg): | |
| items = shlex.split(arg) | |
| nums = [float(i) for i in items] |
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 cmd | |
| import random | |
| import time | |
| class DiceRoll(cmd.Cmd): | |
| """ A custom command prompt for a rolling dice """ | |
| prompt = "dice>>> " | |
| def __init__(self): |
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
| >>> filename='/usr/share/dict/words' | |
| >>> bt.search_word(filename, 'calculate') | |
| ['calculate', 'calculated', 'calculates'] | |
| >>> bt.search_word(filename, 'code') | |
| ['code', "code's", 'coded', 'codeine', "codeine's", 'codependency', "codependency's", 'codependent', | |
| "codependent's", 'codependents', 'codes', 'codex', "codex's"] | |
| >>> bt.search_word(filename, 'search') | |
| ['search', "search's", 'searched', 'searcher', "searcher's", 'searchers', 'searches', 'searching', | |
| 'searchingly', 'searchlight', "searchlight's", 'searchlights'] |
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
| def search_word(filename, prefix): | |
| """ Search a file containing a wordlist and print matching words by prefix """ | |
| wordlist = sorted(filter(None, [item.lower().strip() for item in open(filename)])) | |
| words = [] | |
| idx = bisect.bisect_left(wordlist, prefix) | |
| for idx in range(idx, len(wordlist)): | |
| word = wordlist[idx] |
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
| def IQ(score): | |
| """ IQ function using range dictionary """ | |
| scores_class_dict={0: 'intellectually disabled', | |
| 70: 'below average', | |
| 85: 'average', | |
| 115: 'bright', | |
| 130: 'gifted', | |
| 145: 'highly gifted', | |
| 160: 'exceptionally gifted', |
NewerOlder