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
kgriffs / unused.py
Created Jan 20, 2020 — forked from jmvrbanac/unused.py
Get Unused Port
View unused.py
def get_unused_port():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(('localhost', 0))
_, port = sock.getsockname()
sock.close()
return port
@kgriffs
kgriffs / _ssl_util.py
Last active Dec 30, 2019
Validate a server's certificate in Python 3 using only the standard library + certifi
View _ssl_util.py
import datetime
from enum import Enum
import socket
import ssl
import certifi
class CertificateStatus(Enum):
UNKNOWN = -1
@kgriffs
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
kgriffs / gcp_ips.sh
Last active Oct 15, 2019 — forked from vulkoingim/gcp_ips.sh
Get GCP Public IP Ranges
View gcp_ips.sh
#!/usr/bin/env bash
# This script lists all ip ranges currently used by
# the google cloud platform, according to ns-lookup / dig
# TXT _cloud-netblocks.googleusercontent.com
#
# https://cloud.google.com/compute/docs/faq#find_ip_range
errcho() {
>&2 echo "$@"
@kgriffs
kgriffs / falcon-3.0-roadmap.md
Last active Jan 20, 2020
Falcon 3.0 Roadmap
View falcon-3.0-roadmap.md

Falcon 3.0 Roadmap

3.0.0a1

  • 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
kgriffs / falcon_parse_multipart_example.py
Created Jul 24, 2019
Falcon: Multipart form parsing example
View falcon_parse_multipart_example.py
import cgi
# NOTE: This does not handle file uploads
def parse_form(req):
# NOTE: See also the docs for cgi.FieldStorage
form = cgi.FieldStorage(fp=req.stream, environ=req.env,
keep_blank_values=1)
if not form.list:
return {}
@kgriffs
kgriffs / upgrade-kernel.yml
Created Jul 23, 2019
Ansible - Upgrade CentOS 7 Kernel
View upgrade-kernel.yml
- name: Add ELRepo
yum:
name: https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
state: latest
- name: Install latest mainline kernel
yum:
name: kernel-ml
state: latest
enablerepo: elrepo-kernel
- name: Remake grub config to pick up new kernel
@kgriffs
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
local_action:
module: wait_for
host={{ inventory_hostname }}
port=22
@kgriffs
kgriffs / example.py
Last active Jul 19, 2019
Convert a non-blocking synchronous function to an async coroutine function
View example.py
import functools
def non_blocking_sync_to_async(func):
"""Convert a non-blocking synchronous function to an async coroutine.
Warning:
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
instead.
@kgriffs
kgriffs / str_compare_timesafe.py
Created Jul 4, 2019
Compare Entire Strings in a Time-Stable Way to Mitigate Timing Attacks
View str_compare_timesafe.py
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.