Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile
# Apache conf (/etc/apache2/apache2.conf)
#
# Based on http://github.com/jacobian/django-deployment-workshop/
# blob/master/apache/apache2.conf by Jacob Kaplan-Moss
# Basic server setup
#
ServerRoot "/etc/apache2"
PidFile ${APACHE_PID_FILE}
User ${APACHE_RUN_USER}
@simonw
simonw / varnish-jsonp.vcl
Last active May 13, 2021 18:13
Get Varnish to handle JSON-P requests for you
backend default {
.host = "127.0.0.1";
.port = "8000";
}
# We go BACK to varnish to get it to generate an ESI template that
# generates a JSON-P response.
backend jsonp_template_backend {
.host = "127.0.0.1";
.port = "8070";
@simonw
simonw / gist:778541
Created January 13, 2011 20:34
Hacker news comment that's failing to post
We put a lot of thought in to loading times of the badge. There are some
performance notes here:
http://lanyrd.com/services/badges/docs/#performance
We're serving the initial 2215 byte script from Amazon's CloudFront CDN, so it
should load lightning fast. You can place the script link at the bottom of the
body to make absolutely sure there's no chance of it blocking the load of the
rest of your page.
javascript:void(document.getElementById('content').style.backgroundImage='url(http://cdn.lanyrd.net/img/bg/omg.0c3bb23c.gif)');
@simonw
simonw / localtime_with_timezone_to_utc_datestring.py
Created March 6, 2011 22:23
Convert a local datetime object to a UTC string represestation, taking daylight savings time in to account
"""
Convert a local datetime object to a UTC string represestation, taking
daylight savings time in to account. Here's an example - the clocks change
at 2am on March 13th 2011.
>>> to_utc_datestring(datetime.datetime(2011, 3, 11, 17, 30))
'20110311T233000Z'
>>> to_utc_datestring(datetime.datetime(2011, 3, 15, 17, 30))
'20110315T223000Z'
@simonw
simonw / gist:969059
Created May 12, 2011 17:50
Things that were wrong with my experience buying flights on aa.com edit
* The "start over" button was just a few pixels away from the "continue"
button
* The phone number fields included a "country" pulldown with numeric country
codes, good thing I knew mine off the top of my head, but not exactly
friendly
* The phone number "area" field was limited to 3 characters... but area codes
in the UK are 4 (5 if you include the leading 0)
* There was no visible indication that I had gone over the 3 character limit,
so the first time I submitted the form I got to the confirmation and saw
that one of the numbers in my phone's area code had been silently lost...
@simonw
simonw / log.lua
Created June 22, 2011 09:28
Query logging for mysql-proxy
--[[
Copyright (C) 2007 MySQL AB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@simonw
simonw / show_mysql_tables_and_charsets.sql
Created July 20, 2011 13:20
Show MySQL tables and their charsets
SELECT
T.table_name, CCSA.character_set_name
FROM
information_schema.`TABLES` T,
information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
WHERE
CCSA.collation_name = T.table_collation
AND T.table_schema = "YOUR_DB_NAME";
@simonw
simonw / gist:1662528
Created January 23, 2012 11:09
static.lanyrd.net
$ host static.lanyrd.net
static.lanyrd.net is an alias for static.lanyrd.net.s3.amazonaws.com.
static.lanyrd.net.s3.amazonaws.com is an alias for s3-directional-w.amazonaws.com.
s3-directional-w.amazonaws.com is an alias for s3-directional-w.geo.amazonaws.com.
s3-directional-w.geo.amazonaws.com is an alias for s3-1-w.amazonaws.com.
s3-1-w.amazonaws.com has address 72.21.203.149
@simonw
simonw / google-map-marker-with-shadow.js
Created May 15, 2012 14:39
google-map-marker-with-shadow.js
/* Here's how to add a coloured marker to a Google Map with a shadow in the
right place.
The pin itself is dynamically generated using the Google Charts API,
documented here:
https://developers.google.com/chart/image/docs/gallery/dynamic_icons
Note however that this API was marked as deprecated on April 20th 2012
although it's not clear when or if it will be turned off.
*/