Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile

2023-08-22T20:18:12 conversation: 01h8fec5xgr78z9pyfmdgnwy33

Model: mlc-chat-Llama-2-13b-chat-hf-q4f16_1

Prompt:

Five cute names for a pet weasel

Response:

@simonw
simonw / ubuntu-python-upgrade.md
Created March 28, 2020 19:45
How to run Python 3.7 on Ubuntu 16.04
@simonw
simonw / METADATA
Last active February 28, 2024 00:36
Flattened directory of the files from the whl for https://pypi.org/project/testcontainers-postgres
Metadata-Version: 2.1
Name: testcontainers-postgres
Version: 0.0.1rc1
Summary: PostgreSQL component of testcontainers-python.
Home-page: https://github.com/testcontainers/testcontainers-python
Requires-Python: >=3.7
Description-Content-Type: text/x-rst
Requires-Dist: testcontainers-core
Requires-Dist: sqlalchemy
Requires-Dist: psycopg2-binary
@simonw
simonw / wget.md
Created December 9, 2016 06:38
Recursive wget ignoring robots
$ wget -e robots=off -r -np 'http://example.com/folder/'
  • -e robots=off causes it to ignore robots.txt for that domain
  • -r makes it recursive
  • -np = no parents, so it doesn't follow links up to the parent folder
import sqlite3
# Connect to the test.db database
conn = sqlite3.connect(":memory:")
cursor = conn.cursor()
# Create the news table
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS news (

I made this Toga app as a Bash one-liner:

python -c '
import toga
import urllib.request
import json

def fetch_json(url):
    with urllib.request.urlopen(url) as response:
 if response.getcode() == 200:
@simonw
simonw / gist:3947083
Created October 24, 2012 16:19
Setting up port forwarding from inside an SSH session
localhost:~$ ssh example.com
ubuntu@example.com:~$
... ooh, I could really do with a port forwarding to something on here ...
Type ENTER TILDE CAPITAL-C
ssh>
Secret SSH shell!
ssh> -L8080:localhost:8080
.grow-wrap {
/* easy way to plop the elements on top of each other and have them both sized based on the tallest one's height */
display: grid;
}
.grow-wrap::after {
/* Note the weird space! Needed to preventy jumpy behavior */
content: attr(data-replicated-value) " ";
/* This is how textarea text behaves */
white-space: pre-wrap;
@simonw
simonw / recover_source_code.md
Last active January 16, 2024 08:13
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
@simonw
simonw / auto-fill-slug-from-title.js
Created May 8, 2021 15:04
Pre-fill the slug form field based on the title, but stop doing that if the slug is manually edited
function slugify(s) {
return s
.toLowerCase()
.replace(/[^-\w\s]/g, "") // remove non-alphanumerics
.trim()
.replace(/[-\s]+/g, "-") // spaces to hyphens
.replace(/-+$/g, ""); // trim trailing hyphens
}
function slugAutoFill() {