Skip to content

Instantly share code, notes, and snippets.

@johnjosephhorton
johnjosephhorton / dialog.txt
Created April 13, 2024 12:24
Creating a simple dialog between two agents
(venv) john@Johns-MacBook-Air agent_dialog % python -i AgentDialog.py
John: Hello Robin, I was thinking about going hiking today. Are you interested in joining me?
Robin: Hello John, hiking sounds like a great idea! I was actually hoping to go biking today, but a hike could be a nice compromise. Where were you thinking of hiking?
John: That's great to hear, Robin! I was thinking of hitting the trails at the Green Mountain Forest. There are some fantastic views and the terrain is just right for a good day's hike. How does that sound to you?
Robin: Green Mountain Forest sounds wonderful, John! I've heard the trails there are quite scenic. And you're right, it seems like the perfect place for a good day's hike. Let's do it! What time were you thinking of starting?
John: I'm glad you're on board, Robin! How about we start early to make the most of the day? Meeting at 8:00 AM would give us plenty of time to enjoy the trails. Does that work for you?
Robin: That sounds like a plan, John! Meeting at 8:00 AM works for
@johnjosephhorton
johnjosephhorton / looking_for_domain_name.py
Created January 28, 2024 22:50
A script to search for english word domain names that might be available
import aiohttp
import asyncio
http_status_codes = {
100: "Continue",
101: "Switching Protocols",
102: "Processing",
200: "OK",
201: "Created",
202: "Accepted",
from jinja2 import Template
from jinja2 import Environment, meta
class Question:
"""This class reprsents a question sent to an LLM (or human).
It uses the jinja2 templating language to generate the prompt.
For details on jinja2: https://jinja.palletsprojects.com/en/3.0.x/
This templating language gives us lots of flexibility in how we ask questions.
"""
def __init__(self, template_string):
@johnjosephhorton
johnjosephhorton / lazy_way_to_install_all_R_packages.sh
Created July 26, 2019 13:46
Lazy way to get all the packges you use & then install them at once
# Find all your R files & get just the package names, uniquely
find ../analysis/ -name *R -print0 | xargs -0 grep -h 'library*' | sed 's/library//g' | sed 's/#//g' | sed 's/ //g' | sort | uniq|\
sed 's/(//g' | sed 's/)//g' > package_list.txt
# Install each package
cat package_list.txt | xargs -I {} Rscript -e 'install.packages("{}")'
#!/usr/bin/Rscript --vanilla
suppressPackageStartupMessages({
library(magrittr)
library(dplyr)
library(foreign)
library(plm)
library(reshape2)
library(stargazer)
library(ggplot2)
@johnjosephhorton
johnjosephhorton / Makefile
Last active August 8, 2018 15:12
Real world Makefile for a paper
project_name = hot_towel
ts := $(shell /bin/date "+%Y-%m-%d---%H-%M-%S")
params =
# DONE
params += params_exp_details.tex
params_exp_details.tex: ../analysis/params_exp_details.R
cd ../analysis && ./params_exp_details.R
@johnjosephhorton
johnjosephhorton / uc_salaries_by_dept_and_rank.R
Created May 31, 2018 21:16
UC salaries by rank & dept
library(XML)
library(ggplot2)
df <- readHTMLTable("http://projects.dailycal.org/paychecker/departments/")[[1]]
DeMoney <- function(x) as.numeric(gsub(",", "", gsub("\\$", "", as.character(x))))
money.columns <- c("All", "Professor", "Associate professor", "Assistant professor",
"Lecturer")
library(geofacet) # my forked version
library(ggplot2)
library(jsonlite)
library(ggrepel)
# grab top cities
cities <- fromJSON("https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json")
n <- 50
x <- cities$longitude[1:n]
library(lfe)
library(stargazer)
set.seed(6152011)
# Number of cities
L <- 1000
# Number of industries
K <- 3
SimExperiment <- function(num.groups, sample.size, beta, randomize.by.group = FALSE){
"Simulate running an analysis of the experiment with linear regression"
df <- CreateClusteredData(num.groups, sample.size, beta, randomize.by.group = randomize.by.group)
m <- lm(y ~ trt, data = df)
c(as.numeric(coef(m)[2]), as.numeric(sqrt(diag(vcov(m))[2])))
}