Skip to content

Instantly share code, notes, and snippets.

@danielgross
danielgross / mathpix2gpt.py
Last active April 22, 2024 05:19
mathpix2gpt.py
import requests
import time
import os
import sys
import openai
import tiktoken
from termcolor import colored
openai.api_key = open(os.path.expanduser('~/.openai')).read().strip()
@danielgross
danielgross / ai-plugin.json
Created March 23, 2023 22:59
ChatGPT Plugin for Twilio
{
"schema_version": "v1",
"name_for_model": "twilio",
"name_for_human": "Twilio Plugin",
"description_for_model": "Plugin for integrating the Twilio API to send SMS messages and make phone calls. Use it whenever a user wants to send a text message or make a call using their Twilio account.",
"description_for_human": "Send text messages and make phone calls with Twilio.",
"auth": {
"type": "user_http",
"authorization_type": "basic"
},
@danielgross
danielgross / embedbench.py
Last active May 11, 2023 23:19
embedbench.py
# Compare different embedding methods.
import os
import hashlib
import email
import email.policy
import tqdm
import time
import random
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity # for testing
@danielgross
danielgross / jupyter_jump.py
Created February 11, 2023 17:30
Add as final cell to notebook for easy transition to OpenAI
# ~~~magictext~~~
# update FILENAME to your file name
!jupyter nbconvert --to script --output "/tmp/copy" FILENAME.ipynb
# Trim empty lines from /tmp/copy.py
!sed -i '' '/^$/d' /tmp/copy.py
# Trim lines that start with "# In["
!sed -i '' '/^# In\[/d' /tmp/copy.py
# Remove this very section, e.g. anything after "# ~~~magictext~~~"
!sed -i '' '/# ~~~magictext~~~/,$d' /tmp/copy.py
!cat /tmp/copy.py | pbcopy
@danielgross
danielgross / specific_gpt.py
Created January 23, 2023 15:23
A chat interface that drives GPT-3 towards more specific answers.
"""Stream a response from the OpenAI completion API."""
import os
import re
import sys
import time
import random
import openai
openai.api_key = open(os.path.expanduser("~/.openai")).read().strip()
@danielgross
danielgross / gcal_weekview.py
Last active April 28, 2023 01:50
View all day events in upcoming year week by week
# Export all calendars as zip file from Gcal to a folder (e.g. ~/Downloads). Run this file there.
# Requires icalendar and isoweek.
import csv
from icalendar import Calendar, Event
import datetime
import glob
import isoweek
import subprocess
import os
import collections
@danielgross
danielgross / quickadd.py
Last active April 20, 2024 20:55
Quick Add to Google Calendar
"""
Use GPT-3 to generate a calendar event based on natural language input.
I tried having GPT-3 generate the URL directly, but, amusingly, that didn't work well.
"""
import os
import sys
import openai
import datetime
import pytz
@danielgross
danielgross / chatgpt.py
Created December 18, 2022 17:07
Terminal ChatGPT (with API)
#!/usr/bin/env python3
"""Chat with GPT-3 from the Terminal."""
import os
import openai
if os.path.exists(os.path.expanduser("~/.openai")):
openai.api_key = open(os.path.expanduser("~/.openai")).read().strip()
else:
print("Enter your OpenAI API key: ", end="")
openai.api_key = input()
@danielgross
danielgross / screenshot2pdf.py
Created November 19, 2022 15:41
Take screenshots of websites and place into PDF
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from PIL import Image
import io
import time
import os
import sys
import numpy as np
from fpdf import FPDF
@danielgross
danielgross / osx-wifi.sh
Last active November 16, 2019 21:04
OS X WiFi Shortcuts
# Add this to your bash_profile.
# Type `wifi` to list all WiFi networks.
# Type `wifi` "SSID_NAME" "PASSWORD" to connect to one.
# To tether:
# 1. Update tether() with your iPhone SSID and hotspot password.
# 2. Open Control Center.
# 3. Long-press (force touch) Bluetooth.
# 4. Turn OFF Wifi and turn ON "Personal Hotspot". It should read "Discoverable".
# 5. Don't leave that screen or state.