Skip to content

Instantly share code, notes, and snippets.

View davidwtbuxton's full-sized avatar

David Buxton davidwtbuxton

View GitHub Profile
@davidwtbuxton
davidwtbuxton / app.yaml
Last active August 31, 2023 11:17
Serve a Google-looking 404 page for all requests
# For App Engine.
runtime: python311
# Setup for Ubuntu 20.04
# ======================
# Install Nomad, Consul, Docker
# -----------------------------
# GPG keys for Nomad and Docker.
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
@davidwtbuxton
davidwtbuxton / app.yaml
Created September 8, 2021 10:43
Python App Engine test for the Firebase Admin SDK list users API
runtime: python38
@davidwtbuxton
davidwtbuxton / app.yaml
Created March 23, 2021 18:33
Example of App Engine static website with Python redirect handler
runtime: python37
handlers:
# Redirect / and /my-example-project to /my-example-project/. Requires Python.
- url: /(my-example-project)?$
script: auto
secure: always
# The static assets are collected in a "dist" folder.
@davidwtbuxton
davidwtbuxton / main.py
Last active August 5, 2020 13:40
Getting an auth token with custom scopes for the default service account on Google App Engine's Python 3 runtime
# Copyright David Buxton 2020
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@davidwtbuxton
davidwtbuxton / fields.py
Created December 15, 2019 22:11
Other approaches to obfuscating a value
# https://github.com/potatolondon/django-gcloud-connectors/blob/b5279492b5b4b615640efa7cc5783a2cee0c1cbe/gcloudc/forms/fields.py#L145
import base64
import itertools
_VC_KEY = "1K94KG8L" # Fixed key, don't change this!!
def model_path(obj):
return obj._meta.db_table
@davidwtbuxton
davidwtbuxton / example.py
Created December 20, 2018 11:39
Sending data to PubSub on App Engine standard 2.7
import base64
import json
# Install google-api-python-client for Py27
import googleapiclient.discovery
def publish(data):
# The PubSub topic is created beforehand.
topic = 'projects/my-app-engine-project/topics/my-topic'
@davidwtbuxton
davidwtbuxton / untitled.sh
Created July 12, 2018 00:26
In Python, which is fastest to build? A literal list, tuple or set?
$ python3.6 -m timeit '[20, 50, 75, 100]'
10000000 loops, best of 3: 0.0618 usec per loop
$ python3.6 -m timeit '(20, 50, 75, 100)'
100000000 loops, best of 3: 0.0132 usec per loop
$ python3.6 -m timeit '{20, 50, 75, 100}'
10000000 loops, best of 3: 0.127 usec per loop
$ python2.7 -m timeit '[20, 50, 75, 100]'
10000000 loops, best of 3: 0.126 usec per loop
$ python2.7 -m timeit '(20, 50, 75, 100)'
100000000 loops, best of 3: 0.0134 usec per loop
@davidwtbuxton
davidwtbuxton / untitled.sh
Created June 18, 2018 18:02
Accessing Daily Mail comments
$ curl -i http://www.dailymail.co.uk/reader-comments/p/asset/readcomments/5774717?max=1&order=desc
HTTP/1.1 403 Forbidden
Server: AkamaiGHost
Mime-Version: 1.0
Content-Type: text/html
Content-Length: 341
Expires: Mon, 18 Jun 2018 18:00:23 GMT
Date: Mon, 18 Jun 2018 18:00:23 GMT
Connection: keep-alive
Vary: User-Agent