Skip to content

Instantly share code, notes, and snippets.

View simonhayward's full-sized avatar

Simon Hayward simonhayward

View GitHub Profile
@simonhayward
simonhayward / migrations_check.py
Created July 12, 2016 14:59
Check migrations ran
import logging
from django.db import DEFAULT_DB_ALIAS, connections
from django.db.migrations.loader import MigrationLoader
def migrations_have_applied():
"""
Check if there are any migrations that haven't been applied yet
"""
@simonhayward
simonhayward / keybase.md
Created August 30, 2016 13:13
keybase.md

Keybase proof

I hereby claim:

  • I am simonhayward on github.
  • I am simonhayward (https://keybase.io/simonhayward) on keybase.
  • I have a public key whose fingerprint is C78E AB4C 3CCB 8657 CC05 011F 8AC0 2148 9CC8 9FA0

To claim this, I am signing this object:

@simonhayward
simonhayward / reservoir-sampling.py
Created August 17, 2020 09:55
reservoir sampling
"""
https://florian.github.io/reservoir-sampling/
- Store the first k elements as the reservoir elements
- For the i-th element, add it to the reservoir with a probability of k/i.
This is done by replacing a randomly selected element in the reservoir
"""
import random
import sys
@simonhayward
simonhayward / main.go
Created August 21, 2020 06:43
simple static server
package main
import (
"log"
"net/http"
)
func logRequest(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s %s\n", r.RemoteAddr, r.Method, r.URL)