Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile
@simonw
simonw / sql_replace_in_django_orm.py
Last active April 20, 2024 18:34
How to use the SQL replace function in a Django ORM query
from django.db.models import F, Func, Value
from myapp.models import MyModel
# Annotation
MyModel.objects.filter(description__icontains='\r\n').annotate(
fixed_description=Func(
F('description'),
Value('\r\n'), Value('\n'),
function='replace',
)

What I want from a run-Python-in-WASM solution

I want to be able to use WebAssembly as a sandbox to safely run Python code from untrusted sources, within my existing Python applications.

I'd like to be able to:

  • Pass in an untrusted string of Python code and have that evaluated
  • Maybe also pass in initial variables to be used in the code - though hard-coding them would work OK too
  • Have the code run in a sandboxed environment, with a timeout and memory limit
  • The sandbox disallows network access and disk access - it can only access the variables passed in
@simonw
simonw / loading_data.js
Created January 28, 2015 02:57
Using gist.github.com to persist data from JavaScript running on any webpage
jQuery.get('https://api.github.com/gists/3a065d804c44b0149eac', function(data) {
console.log(data.files['file1.txt'].content)
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Single File Web Component</title>
<style>
body {
background-color: #eee;
font-family: Helvetica, sans-serif;
}
@simonw
simonw / how-to.md
Last active March 26, 2024 23:21
How to create a tarball of a git repository using "git archive"
@simonw
simonw / README.md
Created May 3, 2022 18:11
Simple declarative schema migration for SQLite
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[338],{578:(e,t,r)=>{e.exports=r.p+"7cf7ced34f0a1ece31b4.wasm"},338:(e,t,r)=>{var n;r.r(t),r.d(t,{default:()=>a});const a=(n="file:///private/tmp/node_modules/@jitl/quickjs-wasmfile-release-sync/dist/emscripten-module.browser.mjs",function(e={}){var t,a,o=e;function i(e){e={log:e||function(){}};for(const t of i.za)t(e);return o.quickJSEmscriptenExtensions=e}o.ready=new Promise(((e,r)=>{t=e,a=r})),i.za=[],o.quickjsEmscriptenInit=i,i.za.push((e=>{e.getWasmMemory=function(){return Q}}));var _,u=Object.assign({},o),l="./this.program",s="object"==typeof window,f="function"==typeof importScripts,S="";(s||f)&&(f?S=self.location.href:"undefined"!=typeof document&&document.currentScript&&(S=document.currentScript.src),n&&(S=n),S=0!==S.indexOf("blob:")?S.substr(0,S.replace(/[?#].*/,"").lastIndexOf("/")+1):"",f&&(_=e=>{var t=new XMLHttpRequest;return t.open("GET",e,!1),t.responseType="arraybuffer",t.send(null),new Uint8Array(t.response)}));var c,T=o.print||con

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