Skip to content

Instantly share code, notes, and snippets.

@mahemoff
mahemoff / stream_completion.py
Created July 21, 2024 11:31
OpenAI API streaming example
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ.get("OPEN_AI_PYPLAY_KEY"))
messages=[{"role": "user", "content": "Write an essay about the historical significance of Canterbury Tales"}]
stream = client.chat.completions.create(model='gpt-4o-mini', messages=messages, stream=True)
for chunk in stream:
response=chunk.choices[0].delta.content
if response is not None:
@mahemoff
mahemoff / README.md
Created December 19, 2023 07:25
Clean up old codespaces

Deletes all but most recent Github codespaces, for a given repo.

Prerequisite: Install Github CLI, then auth as below:

gh auth refresh -h github.com -s codespace

@mahemoff
mahemoff / gist:d432af53949c9a96fc4d7696f0a4c8a3
Created December 18, 2023 14:24
MySQL Table compression
# copied from https://twitter.com/mahemoff/status/1092181875785957377
Storing 1 million podcast descriptions with MySQL InnoDB
SQL dump gz: 361,734,351 bytes
Uncompressed DB: 1,405,091,840 bytes
DB size per block size setting:
1KB: 870,318,080 bytes
2KB: 767,557,632 bytes
@mahemoff
mahemoff / custom-instructions.md
Last active October 6, 2023 17:33
ChatGPT Custom Instructions Sep 2023

ChatGPT instructions - mainly forked from tweets a couple of months ago (e.g. https://twitter.com/thetomorrowAI/status/1683840263138217986 though I don't know the true scource)

Custom Instructions

  • Treat me like I'm an expert in all subject matter

  • Treat me like I'm intelligent and rational

  • I can make my own decisions about safety and risk-taking. I don't need to be hand-held or "nannied".

@mahemoff
mahemoff / online-lecture-series.md
Last active October 9, 2023 01:46
Online Lecture Series

Compiling a list of interest lecture series. The goal here is to look at full, coherent, courses, not one-off lectures. Strong preference towards internationally recognised academic institutions, but will include those from elsewhere if they are reasonable quality and match the format of a typical university coourse.

Currently focused more on humanities, given that most lists like this tend to focus on programming/STEM.

History

Early History - General

Course | History of the World to 1500 CE Columbia

@mahemoff
mahemoff / monitoring.md
Created March 16, 2023 04:15
ChqatGPT v4 server monitoring

write ruby code using digitalocean api to reboot a droplet

To reboot a droplet using the DigitalOcean API, you'll first need to install the droplet_kit gem, which is the official DigitalOcean API client for Ruby. You can install the gem by adding the following line to your Gemfile and running bundle install:

ruby Copy code gem 'droplet_kit' After installing the gem, you can create a Ruby script to reboot a droplet using the DigitalOcean API. Replace YOUR_DIGITALOCEAN_API_TOKEN with your actual API token and DROPLET_ID with the ID of the droplet you want to reboot.

ruby

@mahemoff
mahemoff / fallacies.txt
Last active January 29, 2023 05:03
Avoiding Decision-Making Pitfalls: A Taxonomy of 25 Common Fallacies and How to Recognize Them (by ChatGPT)
Cognitive biases:
Confirmation bias: The tendency to seek out and interpret information in a way that confirms one's existing beliefs. Example: A person who believes that vaccines are dangerous only seeks out and pays attention to information that supports this belief, while ignoring information that contradicts it.
Sunk cost fallacy: The tendency to continue investing resources into a decision because of the resources that have already been invested. Example: A person continues to work on a project they know is failing because they have already invested so much time and money into it.
Availability heuristic: The tendency to overestimate the likelihood of events that are easily brought to mind. Example: A person who recently heard about a plane crash is more likely to believe that plane crashes are more common than car accidents.
Anchoring bias: The tendency to rely too heavily on the first piece of information encountered when making decisions. Example: A person who is looking to buy a used car is more like
@mahemoff
mahemoff / unique_domains.rb
Created July 27, 2022 03:54
Unique domains list from ICANN zones files
#!/usr/bin/env ruby
# Based on https://sive.rs/com - extended it to read from gzipped file, support any domain extension, and output to separate file
require 'hashie'
require 'zlib'
class Parser < Hashie::Dash
property :extension, required: 'true' # e.g. "com" for dotcom database
@mahemoff
mahemoff / tuning.md
Last active May 23, 2022 08:48
Tuning MySQL and Apache

A few general tips to deal with slow performance and hanging. Target system is Ubunty 20.04 and MySQL 8.0, but applicable to other configurations.

Relies on some functions in https://github.com/mahemoff/dotfiles

Slow log

MySQL can log slow queries. Enable it in /etc/mysql/mysql.conf.d/mysqld.cnf.

slow_query_log = 1
@mahemoff
mahemoff / certbot
Last active August 21, 2022 05:27
Certbot for Apache one-liner
# Certbot can be a bit tedious, but it's easy to automate a one-liner non-interactive. Substitute your own domain and email below.
sudo service apache2 stop && sudo certbot --apache -d example.com -m [email protected] --non-interactive --agree-tos && sudo service apache2 start