Skip to content

Instantly share code, notes, and snippets.

View hagemt's full-sized avatar
🌈
Always Learning; lately about LLMs

Tor E Hagemann hagemt

🌈
Always Learning; lately about LLMs
View GitHub Profile
@hagemt
hagemt / starter.zshrc
Created November 21, 2023 19:30
Starter dotfile(s) for zsh w/ Homebrew, intended for macOS machines as a starting point
# ~/.devrc just has env vars that I didn't like sharing (e.g. Homebrew GH token)
[[ ! -s "$HOME/.devrc" ]] || source "$HOME/.devrc"
export OPT_HOMEBREW=/opt/homebrew # brew --prefix ## /usr/local on Intel vs. M1+
[[ ! -d "$OPT_HOMEBREW" ]] || FPATH="$OPT_HOMEBREW/share/zsh-completions:$FPATH"
autoload -Uz compinit
compinit -u
setopt interactive_comments
# these lines must come after compinit, a few nice addons:
@hagemt
hagemt / README.md
Last active November 6, 2023 23:12
Getting started w/ langchain + experimental stuff (in separate "beta" section) based upon https://www.youtube.com/watch?v=aywZrzNaKjs

tl;dr

For GPT, put your OPENAI_API_KEY in a .env file, and then run bash demo.sh or bash demo.sh beta if desired

For embeds, try out https://pinecone.io + set PINECONE_API_KEY and PINECONE_ENV + an index named lc-quickstart

Download + unzip, read through the code, and watch the video / read more on: https://python.langchain.com/docs

WARNING

@hagemt
hagemt / lovesac.py
Last active December 5, 2022 21:22
Clearance items for modular couch products, etc. (python3.11 async version, to compare)
#!/usr/bin/env python3.11
"""USAGE: ./lovesac.py
Print names of all current clearance items
"""
# pylint: disable=missing-function-docstring
import asyncio
import logging
import os
import time
@hagemt
hagemt / vim.zsh
Last active April 14, 2024 00:41
Automatic vim setup
#!/usr/bin/env zsh
set -euo pipefail
#set -x ## debug
: "${ROOT_DIR:=${HOME:-/root}}"
function fatal_error {
[[ -z "$*" ]] || echo 1>&2 "--- FATAL: $*"
exit 1
@hagemt
hagemt / 00_macOS.md
Last active March 4, 2022 01:56
Kafka for Developers Guide(s)

Should I care? Business is hard enough; sell me!

Yes. Real-time apps feel like magic for users. But, most magic is explain-able; here's one peek at a minimal solution.

image

Your engineers tell you it'll take years to build this up, but what if they weren't starting from scratch?

Kafka pushes around data (organized I/O via "topical" streams) allowing messages to "flow" between systems of record.

@hagemt
hagemt / zeller.js
Last active February 4, 2023 00:04
NodeJS exercise in commenting code/test
/* global console, process */
//
// mild JS surprises in the Date API
// - getDay() returns 0=Sunday day of week, vs. getDate()'s day of month
// - getMonth() returns 0 for January, which isn't how getDate() works
// - getYear() vs. getFullYear() for year X vs. 1900 + X
//
// JS puts 0=Sunday first, but Zeller considers 0=Saturday (modulate once left)
const days = Object.freeze(['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'])
@hagemt
hagemt / rProxy.go
Last active August 10, 2021 16:32
A slightly better reverse proxy in Golang w/ Prometheus
package main
import (
"context"
"fmt"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
"net/http/httputil"
@hagemt
hagemt / uniques.go
Last active August 7, 2021 21:50
A "set" in golang, using a map to eliminate duplicates from a slice of strings
// uniques returns a sorted collection of n strings (duplicates are collapsed)
func uniques(before []string) []string {
after := make([]string, 0, len(before))
index := make(map[string]bool, len(before))
for _, s := range before {
if _, ok := index[s]; !ok {
after = append(after, s)
index[s] = true
}
}
@hagemt
hagemt / uProxy.go
Created July 23, 2021 06:07
Dumb reverse proxy in 100 SLOC
package main
import (
"context"
"fmt"
"io"
"log"
"net/http"
"os"
"os/signal"
@hagemt
hagemt / Makefile
Created June 10, 2021 20:51
Video to GIF with text using CLI tools
.PHONY: draw gif vid
# USAGE: drop this Makefile in an empty directory
# install ffmpeg and youtube-dl, on macOS via https://brew.sh
# run make TAG=YOUTUBE_ID DRAW_TEXT='Your Words'
# YEE
GIF ?= $(shell pwd)/you.gif
TAG ?= q6EoRBvdVPQ
URL ?= https://www.youtube.com/watch?v=$(TAG)