Skip to content

Instantly share code, notes, and snippets.

Kurt Griffiths kgriffs

Block or report user

Report or block kgriffs

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
kgriffs /
Created Jan 20, 2020 — forked from jmvrbanac/
Get Unused Port
def get_unused_port():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 0))
_, port = sock.getsockname()
return port
kgriffs /
Last active Dec 30, 2019
Validate a server's certificate in Python 3 using only the standard library + certifi
import datetime
from enum import Enum
import socket
import ssl
import certifi
class CertificateStatus(Enum):
kgriffs / scroll.js
Last active Nov 5, 2019
Scroll to bottom of page using vanilla JS to trigger lazy loading
View scroll.js
const scrollingElement = document.scrollingElement
const viewport_height = scrollingElement.clientHeight
for (let pos = 0; pos < scrollingElement.scrollHeight; pos += viewport_height) {
scrollBy(0, viewport_height)
kgriffs /
Last active Oct 15, 2019 — forked from vulkoingim/
Get GCP Public IP Ranges
#!/usr/bin/env bash
# This script lists all ip ranges currently used by
# the google cloud platform, according to ns-lookup / dig
errcho() {
>&2 echo "$@"
kgriffs /
Last active Jan 20, 2020
Falcon 3.0 Roadmap

Falcon 3.0 Roadmap


  • Review/Merge the ASGI implementation - PR #1573
  • Review/Merge native form parsing (WSGI only) - PR #1549
  • Review/Merge PR backlog
  • Fix doc formatting issue (see also comment on PR #1566)
kgriffs /
Created Jul 24, 2019
Falcon: Multipart form parsing example
import cgi
# NOTE: This does not handle file uploads
def parse_form(req):
# NOTE: See also the docs for cgi.FieldStorage
form = cgi.FieldStorage(, environ=req.env,
if not form.list:
return {}
kgriffs / upgrade-kernel.yml
Created Jul 23, 2019
Ansible - Upgrade CentOS 7 Kernel
View upgrade-kernel.yml
- name: Add ELRepo
state: latest
- name: Install latest mainline kernel
name: kernel-ml
state: latest
enablerepo: elrepo-kernel
- name: Remake grub config to pick up new kernel
kgriffs / restart.yml
Created Jul 23, 2019
Ansible - Restart Server and Wait
View restart.yml
- name: Restart server to ensure configuration changes take hold
shell: 'sleep 2 && shutdown -r now "Reboot triggered by Ansible" && sleep 5'
async: 1
poll: 0
become: true
- name: Wait for the server to restart
module: wait_for
host={{ inventory_hostname }}
kgriffs /
Last active Jul 19, 2019
Convert a non-blocking synchronous function to an async coroutine function
import functools
def non_blocking_sync_to_async(func):
"""Convert a non-blocking synchronous function to an async coroutine.
This should only be used to wrap non-blocking synchronous functions.
If the function may block for an extended period of time (e.g., it
performs I/O), it should be scheduled to run in an Executor
kgriffs /
Created Jul 4, 2019
Compare Entire Strings in a Time-Stable Way to Mitigate Timing Attacks
def str_compare_timesafe(a, b):
all_chars_match = 0
for c1, c2 in zip(a, b):
all_chars_match |= ord(c1) ^ ord(c2)
return all_chars_match == 0
You can’t perform that action at this time.