Skip to content

Instantly share code, notes, and snippets.

View jph00's full-sized avatar
🦘
roo

Jeremy Howard jph00

🦘
roo
View GitHub Profile
@jph00
jph00 / discord-app-cmd.md
Created August 18, 2024 06:02
Discord application commands

Discord Application Commands

Application commands are native ways to interact with apps in the Discord client. There are 3 types of commands accessible in different interfaces: the chat input, a message's context menu (top-right menu or right-clicking in a message), and a user's context menu (right-clicking on a user).

Application Command Object

Application Command Naming

CHAT_INPUT command names and command option names must match the following regex ^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$ with the unicode flag set. If there is a lowercase variant of any letters used, you must use those. Characters with no lowercase variants and/or uncased letters are still allowed. USER and MESSAGE commands may be mixed case and can include spaces.

@jph00
jph00 / discord-oauth.md
Created August 18, 2024 05:15
Discord oauth

OAuth2 Discord information

OAuth2 enables application developers to build applications that utilize authentication and data from the Discord API. Within Discord, there are multiple types of OAuth2 authentication. We support the authorization code grant, the implicit grant, client credentials, and some modified special-for-Discord flows for Bots and Webhooks.

Shared Resources

The first step in implementing OAuth2 is registering a developer application and retrieving your client ID and client secret. Most people who will be implementing OAuth2 will want to find and utilize a library in the language of their choice. For those implementing OAuth2 from scratch, please see RFC 6749 for details. After you create your application with Discord, make sure that you have your client_id and client_secret handy. The next step is to figure out which OAuth2 flow is right for your purposes.

OAuth2 URLs
@jph00
jph00 / fasthtml-eg.sml.md
Last active July 8, 2025 04:35
FastHTML by example (small)

FastHTML By Example

An alternative introduction

There are lots of non-FastHTML-specific tricks and patterns involved in building web apps. The goal of this tutorial is to give an alternate introduction to FastHTML, building out example applications to show common patterns and illustrate some of the ways you can build on top of the FastHTML foundations to create your own custom web apps. A secondary goal is to have this be a useful document to add to the context of an LLM to turn it into a useful FastHTML assistant - in fact, in some of the examples we’ll see this kind of assistant in action, thanks to this custom GPT.

Let’s get started.

FastHTML Basics

@jph00
jph00 / fasthtml-eg.md.txt
Last active October 10, 2024 15:27
fasthtml by example
# FastHTML By Example
An alternative introduction
There are lots of non-FastHTML-specific tricks and patterns involved in building web apps. The goal of this tutorial is to give an alternate introduction to FastHTML, building out example applications to show common patterns and illustrate some of the ways you can build on top of the FastHTML foundations to create your own custom web apps. A secondary goal is to have this be a useful document to add to the context of an LLM to turn it into a useful FastHTML assistant - in fact, in some of the examples we’ll see this kind of assistant in action, thanks to this custom GPT.
Let’s get started.
## FastHTML Basics
@jph00
jph00 / cf_adddns.py
Created July 18, 2024 21:55
Add a cloudflare DNS record (A or CNAME)
# https://github.com/cloudflare/cloudflare-python/blob/main/api.md
from fastcore.script import *
from cloudflare import Cloudflare
@call_parse
def add_dns_record(
record_type: str, # Type of DNS record (CNAME or A)
target: str, # Target IP address or domain name
record: str, # Record name (without the zone)
zone: str, # Zone name
@jph00
jph00 / contrastive.js
Created July 5, 2024 22:07
Chrome tampermonkey helper for the elderly
// ==UserScript==
// @name Keyboard Shortcut Scripts
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Run scripts with keyboard shortcuts
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
@jph00
jph00 / starlette.md
Created June 26, 2024 05:23
Starlette docs

index.md

starlette

✨ The little ASGI framework that shines. ✨

@jph00
jph00 / tfm_ast.py
Last active May 25, 2024 02:15
Function to transform each node of `tree` matching types in `names` by passing them to `func`
import ast
from fastcore.utils import *
from fastcore.utils import _get_class
def tfm_ast(tree:ast.AST, func:callable, *names, **kwargs):
"Transform each node of `tree` by passing it to `func`"
def f(self, node):
res = func(node, **kwargs)
return res if res else node
@jph00
jph00 / flash-prefill.txt
Created May 19, 2024 03:14
Examples of situations where gemini-flash ignores the provided prefill. Switching to pro works fine however.
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=$GOOGLE_API_KEY -H 'Content-Type: application/json' -X POST -d '{ "contents":[ {"role": "user", "parts":[{"text": "Write a story about a magic backpack."}] }, {"role": "model", "parts":[{"text": "There was never"}] } ] }'
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=$GOOGLE_API_KEY -H 'Content-Type: application/json' -X POST -d '{ "contents":[ {"role": "user", "parts":[{"text": "What is your favorite color?"}] }, {"role": "model", "parts":[{"text": "Orange is"}] } ] }'
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash-latest:generateContent?key=$GOOGLE_API_KEY -H 'Content-Type: application/json' -X POST -d '{ "contents":[ {"role": "user", "parts":[{"text": "List 4 colors."}] }, {"role": "model", "parts":[{"text": "- "}] } ] }'
curl https://generativelanguage.googleapis.com/v1beta/mode
@jph00
jph00 / install.sh
Created January 31, 2024 05:42
Install python GPU basics
conda install cuda -c nvidia/label/cuda-12.1.0
conda install 'pytorch>2.0.1' torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
conda install scipy matplotlib pandas notebook