Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile

Git Cheat Sheet

Commands

Getting Started

git init

or

@tombulled
tombulled / app.py
Created November 15, 2020 20:37
Stream a file, in this case an mp4 video, supporting range-requests using starlette
from starlette.applications import Starlette
from starlette.responses import StreamingResponse
from starlette.requests import Request
from starlette.routing import Route
from pathlib import Path
from typing import IO, Generator
"""
Stream a file, in this case an mp4 video, supporting range-requests using starlette
@liuw
liuw / ctype_async_raise.py
Created April 17, 2012 16:02
Nasty hack to raise exception for other threads
#!/usr/bin/env python
# liuw
# Nasty hack to raise exception for other threads
import ctypes # Calm down, this has become standard library since 2.5
import threading
import time
NULL = 0
@yossorion
yossorion / what-i-wish-id-known-about-equity-before-joining-a-unicorn.md
Last active April 7, 2024 22:55
What I Wish I'd Known About Equity Before Joining A Unicorn

What I Wish I'd Known About Equity Before Joining A Unicorn

Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.

This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would

@CharlesNepote
CharlesNepote / csv2datasette
Last active March 17, 2024 17:02
csv2datasette
#!/usr/bin/env bash
# sudo ln -s "$(pwd)/csv2datasette" /usr/bin/csv2datasette
# csv2datasette is meant to explore CSV data. It is not meant to create a sustainable DB.
# csv2datasette is a bash script which open CSV files directly in Datasette. It offers
# a number of options for reading and exploring CSV files, such as --stats, inspired by WTFCsv.
#
# `--stats` option includes, for each column: the column name, the number of unique values,
# the number of filled rows, the number of missing values, the mininmum value, the maximum value,
# the average, the sum, the shortest string, the longest string, the number of numeric values,
@harperreed
harperreed / prompt.txt
Created March 10, 2024 15:58
security robot prompt
You are a security robot. Your job is to observe and report any activity. Specifically, notice the people and what they are doing.
Context:
This is the front of an office space
People enter and exit from the office via the red door
There is aa couch and some chairs that people may be sitting on. There is also a snack area, and an area with equipment. right of the image.
Return JSON.
{
@samuelcolvin
samuelcolvin / aicli.py
Last active March 2, 2024 16:04
OpenAI powered AI CLI in just a few lines of code - moved to https://github.com/samuelcolvin/aicli
#!/usr/bin/env python3
import os
from datetime import datetime, timezone
from pathlib import Path
from prompt_toolkit import PromptSession
from prompt_toolkit.history import FileHistory
import openai
from rich.console import Console
from rich.markdown import Markdown
@sakopov
sakopov / OIDC_for_Github.md
Last active January 5, 2024 22:46
OIDC for Github and AWS

Some rough cloudformation to add OIDC support for Github in AWS.

  1. Create new identity provider for Github. (1b511abead59c6ce207077c0bf0e0043b1382612 is the known thumbprint for Github).

Note, you can discover current thumbprint using openssl.

 $ openssl s_client -servername token.actions.githubusercontent.com -showcerts -connect token.actions.githubusercontent.com:443 <    /dev/null 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sed "0,/-END CERTIFICATE-/d" > certificate.crt
 $ openssl x509 -in certificate.crt -fingerprint -noout | cut -f2 -d'=' | tr -d ':' | tr '[:upper:]' '[:lower:]'
 1b511abead59c6ce207077c0bf0e0043b1382612
@kristoferjoseph
kristoferjoseph / single-file-web-component.html
Last active November 22, 2023 01:17
Single file Web Component
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Single File Web Component</title>
</head>
<body>
<template id=single-file>
<style>
h1 {
@rsbohn
rsbohn / digger.py
Last active September 14, 2023 21:25
"get embeddings from an LLM database"
# LICENSE https://www.apache.org/licenses/LICENSE-2.0.txt
# Copyright (C) Randall Bohn 2023
# requires: llm>=0.9, sqlite_utils, numpy, umap-learn==0.5.3
from typing import Dict
import llm
import numpy as np
from sqlite_utils import Database
from umap import UMAP