Skip to content

Instantly share code, notes, and snippets.

View gasman's full-sized avatar

Matt Westcott gasman

View GitHub Profile
from collections import defaultdict
from collections.abc import Mapping
import html
import re
import warnings
from django.utils.html import conditional_escape, format_html
from django.utils.safestring import mark_safe
@gasman
gasman / results.txt
Created June 3, 2020 08:24
Rich text benchmarking - management command
On a real-world site with 3058 HTML fragments
with richtext-benchmark/original:
1. 13.098440
2. 14.320241
3. 13.525923
with richtext-benchmark/loic:
@gasman
gasman / ticroll.py
Created August 23, 2021 11:44
Python script for building the TIC-ROLL TIC-80 cartridge https://tic80.com/play?cart=1754
#!/usr/bin/env python3
import wave
from io import BytesIO
from PIL import Image
wave_buffer = BytesIO()
data_len = 0
with wave.open('nevergonna-1920.wav', 'rb') as wav:
@gasman
gasman / encode.py
Created October 25, 2020 12:23
Encoding a file as a Youtube video - https://www.youtube.com/watch?v=hyqLv2_zBdA
# Encode inputfile.tar.gz as a series of video frames
# Frames are written to frames/frameNNNN.png
from PIL import Image
with open('inputfile.tar.gz', 'rb') as f:
data = f.read()
WIDTH = 120
HEIGHT = 90
CHUNK_SIZE = int((WIDTH * HEIGHT) / 8)
@gasman
gasman / pnginator.rb
Created April 30, 2012 18:08
pnginator: pack Javascript into a self-extracting PNG
#!/usr/bin/env ruby -w
# pnginator.rb: pack a .js file into a PNG image with an HTML payload;
# when saved with an .html extension and opened in a browser, the HTML extracts and executes
# the javascript.
# Usage: ruby pnginator.rb input.js output.png.html
# By Gasman <http://matt.west.co.tt/>
# from an original idea by Daeken: http://daeken.com/superpacking-js-demos