Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam Pritchard adam-p

View GitHub Profile
@adam-p
adam-p / Local PR test and merge.md
Last active Jul 8, 2022
Testing a pull request, then merging locally; and avoiding TOCTOU
View Local PR test and merge.md

It's not immediately obvious how to pull down the code for a PR and test it locally. But it's pretty easy. (This assumes you have a remote for the main repo named upstream.)

Getting the PR code

  1. Make note of the PR number. For example, Rod's latest is PR #37: Psiphon-Labs/psiphon-tunnel-core#37

  2. Fetch the PR's pseudo-branch (or bookmark or rev pointer whatever the word is), and give it a local branch name. Here we'll name it pr37:

$ git fetch upstream pull/37/head:pr37
@adam-p
adam-p / app.yaml
Last active Feb 25, 2022 — forked from darktable/app.yaml
GAE: App.yaml designed for serving a static site on Google App Engine (Python). Copy your static html and files into a folder called "static" next to app.yaml. Contains a bunch of mimetype declarations from html5boilerplate's .htaccess. May not be neces
View app.yaml
application: you-app-name-here
version: 1
runtime: python
api_version: 1
default_expiration: "30d"
handlers:
- url: /(.*\.(appcache|manifest))
mime_type: text/cache-manifest
@adam-p
adam-p / harvestbot.py
Created Dec 15, 2011
A tool to automatically fill in Harvest timesheets. For when you're just expected to put 8s in a single task across all five days anyway. Note that it doesn't really do the job, since Harvest doesn't let you submit your entries for approval via the API.
View harvestbot.py
#!python
# Note that this whole effort is fundamentally flawed. The Harvest API does not
# provide the ability to submit the timesheet for approval. So, even though this
# code can fill in your timesheet, you still have to go to the web page to submit
# it. Which makes this a waste of time.
# See the feature request thread here:
# http://forum.getharvest.com/forums/api-and-developer-chat/topics/is-there-a-timesheet-api
# HARVEST_URL, PROJECT_NAME, and TASK_NAME need to be set to the desired values.
@adam-p
adam-p / cb.py
Created Nov 30, 2012
Python function to copy text to clipboard (so far only supports Windows).
View cb.py
import sys
import subprocess
def copy(s):
if sys.platform == 'win32' or sys.platform == 'cygwin':
subprocess.Popen(['clip'], stdin=subprocess.PIPE).communicate(s)
else:
raise Exception('Platform not supported')
'''
@adam-p
adam-p / gist:2514182
Created Apr 27, 2012
Displays the contents of the Windows clipboard, including all available formats. Created to answer a friend's question about how he could paste both rich and plain text, depending on the target application.
View gist:2514182
import win32clipboard as cb
builtin_type = {
2: "CF_BITMAP",
8: "CF_DIB",
17: "CF_DIBV5",
5: "CF_DIF",
130: "CF_DSPBITMAP",
142: "CF_DSPENHMETAFILE",
@adam-p
adam-p / README.md
Created Oct 1, 2014
Patching Python code at runtime
View README.md

A rather dirty way to patch module code at runtime.

View Memory Leak Test Chrome Extension
Test extension to demonstrate possible memory leak in Chrome extension API.
Install it, open a bunch of tabs, open Chrome's task manager, let it run, watch memory usage increase.
View prefixed-office-properties.md

MS Office prefixed style properties

mso-ansi-font-size

Note: Office only

mso-ansi-font-size: large | larger | <length> | medium | <percentage> | small | smaller | x-large | x-small | xx-large | xx-small
@adam-p
adam-p / github_issues_exporter.py
Last active Jun 15, 2017
Export open Github issues for offline use
View github_issues_exporter.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
pip install --upgrade PyGithub
TODO:
- Configurable output directory
- Output more issue info
- Better rendering
View keybase.md

Keybase proof

I hereby claim:

  • I am adam-p on github.
  • I am adampritchard (https://keybase.io/adampritchard) on keybase.
  • I have a public key whose fingerprint is 9D4F A4F9 CD4A 4174 4178 F271 9B6E 13E8 B083 9B79

To claim this, I am signing this object: