Skip to content

Instantly share code, notes, and snippets.

View davidfraser's full-sized avatar

David Fraser davidfraser

View GitHub Profile
@davidfraser
davidfraser / setup-wsl-clock-sync.cmd
Last active October 30, 2023 07:23
Set up WSL2 clock sync
@echo off
rem this is a programmatic reminder of how to set up wsl clock sync
rem to prevent clock drift after sleep etc
rem see https://stackoverflow.com/a/65086857/120398 and https://github.com/microsoft/WSL/issues/5324
set WSL_UTF8=1
setlocal EnableDelayedExpansion
for /F "tokens=* delims=" %%D in ('wsl --list --quiet') DO (
set hwclock_count=0
for /f "tokens=* delims=" %%C in ('wsl -d %%D bash -c "grep -c hwclock /usr/local/sbin/hwclock-sync 2>/dev/null"') DO set hwclock_count=%%C
@davidfraser
davidfraser / Google Drive Sync Wine Scripting.md
Last active July 9, 2023 01:00
Google Drive Sync Wine Scripting

Google Drive Sync Wine Scripting

This is a set of scripts that help running Google Drive Backup and Sync under Wine, with multiple Google accounts.

Each account is given its own Wine prefix (a separate wine configuration).

To install, run install-gdrive-sync google_account

List the accounts set up in ~/.config/gdrive-accounts

@davidfraser
davidfraser / MaliciousServer3.py
Last active April 5, 2020 00:02
Speed tests for CVE-2020-8492
from http.server import BaseHTTPRequestHandler, HTTPServer
def make_basic_auth(n_commas):
commas = "," * n_commas
return f"basic {commas}A"
comma_tests = [100, 250, 500, 750, 1000, 1250, 1500, 65509]
i = 0
class Handler(BaseHTTPRequestHandler):
@davidfraser
davidfraser / README.md
Created February 17, 2020 15:51
Speed tests for CVE-2020-8492

= CVE-2020-8492 Speed Tests

CVE-2020-8492 describes a DOS opportunity for malicious servers responding to requests from the Python built-in urllib library.

A malicious server can send up to 65,509 additional commas in the WWW-Authenticate header, which triggers an O(2**n) evaluation of a regular expression.

This folder contains a sample malicious server (in Python 3), and sample vulnerable clients (in Python 2 and 3)

@davidfraser
davidfraser / win_encoding_check
Last active January 24, 2020 13:18
Testing Python 2/3 environment variable handling on Windows, including calling subprocesses
This is some notes and sample code on interacting with Windows environment variable encodings etc. See README.md for more info.
@davidfraser
davidfraser / python_weakset_2.7_add_TypeError_fix.patch
Created December 12, 2019 20:54
Patches CPython's _weakrefset.py to prevent a spurious TypeError when adding an item to a WeakSet
This patches WeakSet.add to prevent it having a spurious error if a weak ref goes away between calling this function and adding it
This is done analogously to the patch in https://github.com/python/cpython/commit/f8de3fea1280d55377d40c6e04b64114f9da2fa6:
"#10360: catch TypeError in WeakSet.__contains__, just like WeakKeyDictionary does."
See https://bugs.python.org/issue10360 for infomration on that
@@ -83,7 +83,11 @@
def add(self, item):
if self._pending_removals:
self._commit_removals()
- self.data.add(ref(item, self._remove))
@davidfraser
davidfraser / Daily-Standup-JIRA
Last active September 19, 2018 10:43
Some TamperMonkey scripts and bash scripting to make our daily standup report from JIRA
Daily Standup Report for JIRA
=============================
This project contains two tampermonkey scripts (for installation in Chrome),
and a bash script that makes it easier for us to quickly make the report we use at our daily standup meeting
@davidfraser
davidfraser / list-vbox-snapshots.sh
Last active May 15, 2018 15:19
List VirtualBox snapshots and disk usage in a tree
#!/bin/bash
vmname="$1"
[ "$vmname" == "" ] && { echo syntax $0 vmname >&2 ; exit 1 ; }
vmdir="$HOME/virtualbox/machines/$vmname"
sndir="$vmdir/Snapshots/"
vboxtmp="`tempfile -p vbox-$vmname --suffix='-list.txt'`"
vboxsed="`tempfile -p vbox-$vmname --suffix='-list.sed'`"
vboxmanage snapshot "$vmname" list > "$vboxtmp"
for uuid in `grep "UUID:" "$vboxtmp" | sed 's%^.*(UUID: \([0-9a-f-]*\)).*$%\1%'`
do
@davidfraser
davidfraser / make_yaml_decoder_module.py
Last active August 1, 2017 20:29
Script for making cut-down version of pyyaml that is a single-file yaml loader
#!/usr/bin/env python
"""Command-line utility to combine the necessary modules to make a single-file yaml_decoder.py"""
import shutil
import os
from os.path import abspath, dirname, exists, join
include_modules = 'loader reader parser scanner composer constructor resolver nodes events tokens error'.split()
# this should be placed in the pyyaml source tree
@davidfraser
davidfraser / venv_link.py
Last active June 2, 2017 20:30
Script to link Python system package into virtual environment from Nick Coghlan at https://bitbucket.org/ncoghlan/misc/raw/44341af0b2e4ac7f9580d5f907d8f49c7013b3b9/venv_link.py Modified to use system python to find the module, and pip to decide the link location