Skip to content

Instantly share code, notes, and snippets.

View adam-p's full-sized avatar

Adam Pritchard adam-p

View GitHub Profile
@adam-p
adam-p / Firefox-notification-on-all-tabs.js
Last active December 22, 2015 09:18
Code to show the native Firefox per-tab notification on all tabs, and have the notification be cleared from all tabs when the user takes action on one of them. (If you have the Firefox "Browser Console" enabled, you can paste this code directly into it. (Tested in Aurora 25.))
// This function is from https://github.com/adam-p/markdown-here/blob/3fca89d704d431dc55e78c68b1afae762794c7e7/src/firefox/chrome/content/ff-overlay.js#L382
/*
* doFunction will be passed a [browser](https://developer.mozilla.org/en-US/docs/XUL/browser)
* (which is approximately analogous to a tab)
* and a [tabbrowser](https://developer.mozilla.org/en-US/docs/XUL/tabbrowser)
* (which is approximately analogous to the window containing the tab)
* for each open tab. browser.contentDocument can be used to access the page's
* document object.
*/
function forAllTabsDo(doFunction) {
@adam-p
adam-p / cb.py
Created November 30, 2012 01:37
Python function to copy text to clipboard (so far only supports Windows).
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 April 27, 2012 23:10
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.
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 / harvestbot.py
Created December 15, 2011 06:22
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.
#!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.