Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile
<!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 / rasterize.js
Last active December 5, 2016 21:40 — forked from FiloSottile/rasterize.js
PhantomJS rasterize.js with "Retina" output
var system = require('system');
var page = require('webpage').create(),
address, output, size;
if (system.args.length < 2 || system.args.length > 3) {
console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
console.log(system.args);
address = system.args[1];
@simonw
simonw / profile-this.py
Last active August 29, 2015 14:27 — forked from andrewgodwin/profile-this.py
Handy profiler pattern
import cProfile, pstats, StringIO
pr = cProfile.Profile()
pr.enable()
# ... do something ...
pr.disable()
s = StringIO.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
@simonw
simonw / howto.txt
Created February 11, 2010 23:49 — forked from joonathan/howto.txt
Save the supervisord.initscript script as /etc/init.d/supervisord
Run /usr/sbin/update-rc.d -f supervisord defaults
import MySQLdb;
from datetime import datetime
import re
import mailbox
import sys
name = "enation"
threading=False
if len(sys.argv) > 1:
@simonw
simonw / shorten-bookmarklet.js
Created April 12, 2009 12:32 — forked from singpolyma/shorten-bookmarklet.js
singpolyma's bit.ly version updated to detect rev=canonical on A elements as well
/* Expanded form of a bookmarklet for extracting rev=canonical OR tinyurling a page */
(function(){
var url=document.location;
var links=document.getElementsByTagName('link');
var found=0;
for(var i = 0, l; l = links[i]; i++) {
if (l.getAttribute('rev') == 'canonical' || (/alternate short/).exec(l.getAttribute('rel'))) {
found=l.getAttribute('href');
break;
}