Skip to content

Instantly share code, notes, and snippets.

View thorwhalen's full-sized avatar

Thor Whalen thorwhalen

View GitHub Profile
@thorwhalen
thorwhalen / openai_api_costs.py
Last active December 6, 2023 10:32
OpenAI API Cost calculator
api_costs = {
'gpt-4-1106-preview': {"input": 0.01, "output": 0.03, "unit": "$/1K tokens"},
'gpt-4-1106-vision-preview': {"input": 0.01, "output": 0.03, "unit": "$/1K tokens"},
'gpt-4': {"input": 0.03, "output": 0.06, "unit": "$/1K tokens"},
'gpt-4-32k': {"input": 0.06, "output": 0.12, "unit": "$/1K tokens"},
'gpt-3.5-turbo-1106': {"input": 0.0010, "output": 0.0020, "unit": "$/1K tokens"},
'gpt-3.5-turbo-instruct': {"input": 0.0015, "output": 0.0020, "unit": "$/1K tokens"},
'gpt-3.5-turbo': {"training": 0.0080, "input": 0.0030, "output": 0.0060, "unit": "$/1K tokens"},
'davinci-002': {"training": 0.0060, "input": 0.0120, "output": 0.0120, "unit": "$/1K tokens"},
'babbage-002': {"training": 0.0004, "input": 0.0016, "output": 0.0016, "unit": "$/1K tokens"},
@thorwhalen
thorwhalen / Scrape Aix club addresses.ipynb
Created September 9, 2022 12:38
Scrape Aix club addresses
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thorwhalen
thorwhalen / empty_values_options.py
Created August 17, 2022 19:25
Options for a singleton "Empty" value with pickability and repr
from tested import validate_codec
Empty1 = type('Empty', (), {})()
print("\nEmpty1 = type('Empty', (), {})()")
print(f"{validate_codec(Empty1)=}")
_Empty2 = type('Empty', (), {})
_Empty2.__module__ = __name__
@thorwhalen
thorwhalen / Head of state salaries -- extraction and processing.py
Created August 11, 2022 15:59
Head of state salaries -- extraction and processing
# get raw df
import qo
df = qo.get_tables_from_url('https://en.wikipedia.org/wiki/List_of_salaries_of_heads_of_state_and_government')[3]
df = df.set_index('State')
# formatting and extracting salaries
@thorwhalen
thorwhalen / Getting a color name and code mapping.ipynb
Created August 15, 2020 00:07
Scraping and preparing color name and RGB code (hex and dec) mapping.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thorwhalen
thorwhalen / the_color_of_notes.py
Created July 7, 2020 17:41
Looking into the musical notes and color correspondence
"""
I've often seen that “color of musical notes” thing,
and I always wondered about it (especially because I’d like to use it as educational support when I teach my (reluctant)
daughter music).
The mappings I see are not always consistent, but one comes up most often;
the one where the red-to-violet range is mapped to the C-to-B range.
Now this could just so happen to be correct, but the choice that C as the canonical root note of a scale seems
to be arbitrary, whereas red as the first color is a physical reality, leading me to think that:
- The choice of C as the root note was purposely based on the red-to-violet correspondence
- It’s a crock of s**t
@thorwhalen
thorwhalen / compose_functions.py
Last active June 4, 2020 19:47
Perform function composition. That is, get a callable that is equivalent to a chain of callables.
from inspect import signature, Signature
class Compose:
def __init__(self, *funcs):
"""Performs function composition.
That is, get a callable that is equivalent to a chain of callables.
For example, if `f`, `h`, and `g` are three functions, the function
```
c = Compose(f, h, g)
@thorwhalen
thorwhalen / callable_subtypes.py
Last active May 20, 2020 19:56
Investigate the subtypes of various python callables
"""
Code that prints this table (meant to study the type-differences of different callables):
```
MethodType FunctionType has_self qualname_levels dunders
name
class method True False True 2 27
instance method False True False 2 35
static method False True False 2 35
"instantiated" class method True False True 2 27
@thorwhalen
thorwhalen / print_top_level_diagnosis.py
Last active May 14, 2020 15:21
Diagnosis (object kind and import depth) of the imports that can be obtained from the (top level) module.
"""
Prints a diagnosis (object kind and import depth) of the imports that can be obtained from the (top level) module.
That is, those objects that can by imported by doing:
```
from module import obj
```
though the object's code may be several package levels down (say module.sub1.sub2.obj).
```
$ python print_top_level_diagnosis.py numpy